Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW17177714, added in check for incorrect delimiters #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lang/en/block_badgeawarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
$string['selectcountry'] = 'Select Default Country';
$string['csv'] = 'The badge CSV file';
$string['csvdelimiter'] = 'CSV delimiter';
$string['csvdelimitererror'] = 'Incorrect field delimiter detected.';
$string['csvfileerror'] = 'There was an error in your CSV upload file';
$string['csvformaterror'] = '<br>The CSV manager failed to find all required fields, The BadgeAwarder requires
the fields firstname, lastname, badge, email on the first row.<br>If you receive this message either one of these fields were missing or you have not chosen the correct field delimiter.';
the fields firstname, lastname, badge, email on the first row.<br>If you receive this message one of these fields were missing.';
$string['csvline'] = 'CSV line';
$string['defaultuploadtype'] = 'Default upload type';
$string['defaultdelimiter'] = 'Default delimiter';
Expand Down
14 changes: 14 additions & 0 deletions processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,20 @@ public function reset() {
protected function validate() {
global $COURSE;
foreach ($this->filecolumns as $requiredcolumn) {

foreach ($this->columns as $test) {
// Checks that the columns do not still contain delimiters.
// If they still contain delimiters this means the wrong delimiter was used.
$delimiters = array(',', ';', ':', '\t');
foreach ($delimiters as $delimiter) {
if (strpos($test, $delimiter)){
$returnlink = new moodle_url('/course/view.php', array('id' => $COURSE->id));
throw new moodle_exception('csvloaderror', 'error',
$returnlink, get_string('csvdelimitererror', 'block_badgeawarder'), '');
}
}
}

if (!in_array($requiredcolumn, $this->columns)) {
$returnlink = new moodle_url('/course/view.php', array('id' => $COURSE->id));
throw new moodle_exception('csvloaderror', 'error',
Expand Down