Skip to content

Commit

Permalink
MDL-81376 mod_quiz: Fix formatting issues, remove other_cols function
Browse files Browse the repository at this point in the history
  • Loading branch information
djarran committed May 30, 2024
1 parent 815eb42 commit 283fac2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
3 changes: 2 additions & 1 deletion mod/quiz/classes/form/import_override_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function definition(): void {
$mform->setType('mode', PARAM_ALPHANUMEXT);

// Filepicker.
$element = $mform->createElement('filepicker', 'overridefile', get_string('overridefile', 'quiz'), null, ['accepted_types' => '.csv']);
$element = $mform->createElement('filepicker', 'overridefile',
get_string('overridefile', 'quiz'), null, ['accepted_types' => '.csv']);
$mform->addElement($element);
$mform->addHelpButton('overridefile', 'overridefile', 'quiz', null, null, $mode);
$mform->addRule('overridefile', null, 'required');
Expand Down
77 changes: 41 additions & 36 deletions mod/quiz/classes/overrides_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,52 +392,57 @@ public function col_attempts(stdClass $row): string {
}

/**
* This function is called for each data row to allow processing of
* columns which do not have a col_* method.
* Generates content for the recordstatus column.
*
* These contain simple validation and formatting checks.
*
* @param string $colname The name of the column.
* @param stdClass $value The value of the column.
* @return string|null Processed value. Returns NULL if no change has been made.
* @param stdClass $row The row data.
* @return string The HTML content for the recordstatus column.
*/
public function other_cols($colname, $row) {
global $OUTPUT;

if ($colname == $this->mode . 'id' && $this->ispreview && !empty($row->errors[$this->mode . 'id'])) {
// Preserve whitespace in HTML element.
return $this->highlighted('     ');
}
public function col_recordstatus(stdClass $row): string {
return ucwords($row->recordstatus);
}

if ($colname == 'recordstatus') {
return ucwords($row->recordstatus);
}
/**
* Generates content for the errors column.
*
* @param stdClass $row The row data.
* @return string The HTML content for the errors column.
*/
public function col_errors(stdClass $row): string {
return implode('<br>', $row->errors);
}

if ($colname == 'errors') {
return implode('<br>', $row->errors);
}
/**
* Generates content for the csvrow column.
*
* @param stdClass $row The row data.
* @return string The HTML content for the csvrow column.
*/
public function col_csvrow(stdClass $row): string {
global $OUTPUT;

if ($colname == 'csvrow') {
$icon;
if (!empty($row->errors)) {
$icon = $OUTPUT->pix_icon('i/invalid', '');
} else {
$icon = $OUTPUT->pix_icon('i/valid', '');
}
return $row->csvrow + 1 . ' ' . $icon;
$icon = null;
if (!empty($row->errors)) {
$icon = $OUTPUT->pix_icon('i/invalid', '');
} else {
$icon = $OUTPUT->pix_icon('i/valid', '');
}
return $row->csvrow + 1 . ' ' . $icon;
}

if ($colname == 'generate') {
$generate = $row->generate;

if ($this->ispreview && !empty($row->errors['generate'])) {
return $this->highlighted($row->generate);
}
/**
* Generates content for the generate column.
*
* @param stdClass $row The row data.
* @return string The HTML content for the generate column.
*/
public function col_generate(stdClass $row): string {
$generate = $row->generate;

return !empty($generate) ? 'True' : 'False';
if ($this->ispreview && !empty($row->errors['generate'])) {
return $this->highlighted($row->generate);
}

return null;
return !empty($generate) ? 'True' : 'False';
}

/**
Expand Down
1 change: 0 additions & 1 deletion mod/quiz/classes/process_override_imports.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public function process(): bool {
$delete = false;
if ($isoptionsempty && !empty($modeid)) {
if (in_array($modeid, $existingoverrides)) {
// if ($DB->record_exists('quiz_overrides', [$typeid => $modeid])) {
$delete = true;
} else {
// We can skip this row.
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/lang/en/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
* If no {$a} override exists and you provide an override, a new override will be created.
* If no {$a} override exists and you don\'t provide an override, no override will be created.
* If a {$a} override exists with a timeopen override and you provide no value for timeopen but add a value for attempts, that override will be updated to now only contain an attempt override.
* If a {$a} override exists and you provide no value for a setting, it will be deleted.
* If a {$a} override exists and you provide no value for a setting, it will be deleted.
';
$string['overridegroup'] = 'Override group';
$string['overridegroupeventname'] = '{$a->quiz} - {$a->group}';
Expand Down

0 comments on commit 283fac2

Please sign in to comment.