From 9cfee7c584ba8034ccd533a57ca122eced0ec226 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Thu, 28 Dec 2023 14:01:58 -0500 Subject: [PATCH 1/6] Fixed array syntax issues. --- checklisteditor.php | 4 ++-- lib.php | 4 ++-- renderer.php | 2 +- tests/generator/checklist.php | 2 +- tests/generator/lib.php | 4 ++-- tests/generator_test.php | 8 ++++---- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/checklisteditor.php b/checklisteditor.php index 997d518..287618d 100644 --- a/checklisteditor.php +++ b/checklisteditor.php @@ -101,12 +101,12 @@ public function toHtml() { $mode = gradingform_checklist_controller::DISPLAY_EDIT_FULL; $module = array('name'=>'gradingform_checklisteditor', 'fullpath'=>'/grade/grading/form/checklist/js/checklisteditor.js', 'strings' => array(array('confirmdeletegroup', 'gradingform_checklist'), array('confirmdeleteitem', 'gradingform_checklist'), - array('groupempty', 'gradingform_checklist'), array('itemempty', 'gradingform_checklist'), ['maxlengthalert', 'gradingform_checklist'] + array('groupempty', 'gradingform_checklist'), array('itemempty', 'gradingform_checklist'), ['maxlengthalert', 'gradingform_checklist'], )); $PAGE->requires->js_init_call('M.gradingform_checklisteditor.init', array( array('name' => $this->getName(), 'grouptemplate' => $renderer->group_template($mode, $data['options'], $this->getName()), - 'itemtemplate' => $renderer->item_template($mode, $data['options'], $this->getName()) + 'itemtemplate' => $renderer->item_template($mode, $data['options'], $this->getName()), )), true, $module); } else { diff --git a/lib.php b/lib.php index 99c7054..ff7c358 100644 --- a/lib.php +++ b/lib.php @@ -464,7 +464,7 @@ public function get_formatted_description() { 'noclean' => false, 'trusted' => false, 'filter' => true, - 'context' => $context + 'context' => $context, ); return format_text($description, $this->definition->descriptionformat, $formatoptions); } @@ -630,7 +630,7 @@ public static function get_default_options() { 'showitempointstudent' => 1, 'enableitemremarks' => 1, 'enablegroupremarks' => 1, - 'showremarksstudent' => 1 + 'showremarksstudent' => 1, ); return $options; } diff --git a/renderer.php b/renderer.php index 3f71704..07e65d3 100644 --- a/renderer.php +++ b/renderer.php @@ -546,7 +546,7 @@ public function display_regrade_confirmation($elementname, $changelevel, $value) $html .= get_string('regrademessage1', 'gradingform_checklist'); $selectoptions = array( 0 => get_string('regradeoption0', 'gradingform_checklist'), - 1 => get_string('regradeoption1', 'gradingform_checklist') + 1 => get_string('regradeoption1', 'gradingform_checklist'), ); $html .= html_writer::select($selectoptions, $elementname.'[regrade]', $value, false); } else { diff --git a/tests/generator/checklist.php b/tests/generator/checklist.php index 9ad5e9b..35dcb5d 100644 --- a/tests/generator/checklist.php +++ b/tests/generator/checklist.php @@ -76,7 +76,7 @@ public function get_definition(): stdClass { 'description_editor' => [ 'text' => $this->description, 'format' => FORMAT_HTML, - 'itemid' => 1 + 'itemid' => 1, ], 'checklist' => [ 'groups' => $this->get_all_criterion_values(), diff --git a/tests/generator/lib.php b/tests/generator/lib.php index c3300f5..b22cee5 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -198,10 +198,10 @@ public function get_submitted_form_data(gradingform_checklist_controller $contro public function get_test_checklist(context $context, string $component, string $area): gradingform_checklist_controller { $criteria = [ 'Group 1' => [ - 'Has title' => 1 + 'Has title' => 1, ], 'Group 2' => [ - 'Has references' => 1 + 'Has references' => 1, ], ]; diff --git a/tests/generator_test.php b/tests/generator_test.php index 87ce683..6b588db 100644 --- a/tests/generator_test.php +++ b/tests/generator_test.php @@ -61,10 +61,10 @@ public function test_checklist_creation(): void { $description = 'My first checklist'; $criteria = [ 'Group 1' => [ - 'Has title' => 1 + 'Has title' => 1, ], 'Group 2' => [ - 'Has references' => 1 + 'Has references' => 1, ], ]; @@ -138,10 +138,10 @@ public function test_get_item_and_criterion_for_values(): void { $description = 'My first checklist'; $criteria = [ 'Group 1' => [ - 'Has title' => 1 + 'Has title' => 1, ], 'Group 2' => [ - 'Has references' => 1 + 'Has references' => 1, ], ]; From 1e7a54276ccef721727b4c1d90b73644b4df17a6 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Thu, 28 Dec 2023 14:32:16 -0500 Subject: [PATCH 2/6] Fixed syntax in code formatting --- checklisteditor.php | 12 ++++++------ edit_form.php | 4 ++-- lib.php | 12 ++++++------ renderer.php | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/checklisteditor.php b/checklisteditor.php index 287618d..236c001 100644 --- a/checklisteditor.php +++ b/checklisteditor.php @@ -53,7 +53,7 @@ function __construct($elementName=null, $elementLabel=null, $attributes=null) { * @param array $helpbuttonargs array of arguments to make a help button * @param string $function function name to call to get html */ - public function setHelpButton($helpbuttonargs, $function='helpbutton'){ + public function setHelpButton($helpbuttonargs, $function='helpbutton') { debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead'); } @@ -99,7 +99,7 @@ public function toHtml() { $data = $this->prepare_data(null, $this->wasvalidated); if (!$this->_flagFrozen) { $mode = gradingform_checklist_controller::DISPLAY_EDIT_FULL; - $module = array('name'=>'gradingform_checklisteditor', 'fullpath'=>'/grade/grading/form/checklist/js/checklisteditor.js', + $module = array('name' => 'gradingform_checklisteditor', 'fullpath' => '/grade/grading/form/checklist/js/checklisteditor.js', 'strings' => array(array('confirmdeletegroup', 'gradingform_checklist'), array('confirmdeleteitem', 'gradingform_checklist'), array('groupempty', 'gradingform_checklist'), array('itemempty', 'gradingform_checklist'), ['maxlengthalert', 'gradingform_checklist'], )); @@ -190,7 +190,7 @@ protected function prepare_data($value = null, $withvalidation = false) { $group['items']['NEWID'.($i++)]['score'] = 1; // add more items so there are at least 3 in the new group. Score is 1 by default - for ($i= $i; $i < 3; $i++) { + for ($i = $i; $i < 3; $i++) { $group['items']['NEWID'.$i]['score'] = 1; } // set other necessary fields (definition) for the items in the new group @@ -239,7 +239,7 @@ protected function prepare_data($value = null, $withvalidation = false) { } } - //sortorder for items + // sortorder for items $itemsortorder = 1; foreach (array_keys($items) as $itemid) { $items[$itemid]['sortorder'] = $itemsortorder++; @@ -326,7 +326,7 @@ protected function get_next_id($ids) { $maxid = (int)$matches[1]; } } - return 'NEWID'.($maxid+1); + return 'NEWID' . ($maxid + 1); } @@ -370,7 +370,7 @@ public function validate($value) { * @return array */ public function exportValue(&$submitValues, $assoc = false) { - $value = $this->prepare_data($this->_findValue($submitValues)); + $value = $this->prepare_data($this->_findValue($submitValues)); return $this->_prepareValue($value, $assoc); } } diff --git a/edit_form.php b/edit_form.php index 93b1cf3..4a1ebe9 100644 --- a/edit_form.php +++ b/edit_form.php @@ -50,7 +50,7 @@ public function definition() { $form->setType('returnurl', PARAM_LOCALURL); // name - $form->addElement('text', 'name', get_string('name', 'gradingform_checklist'), array('size'=>52)); + $form->addElement('text', 'name', get_string( 'name' , 'gradingform_checklist'), array('size' => 52)); $form->addRule('name', get_string('required'), 'required'); $form->setType('name', PARAM_TEXT); @@ -68,7 +68,7 @@ public function definition() { // checklist editor $element = $form->addElement('checklisteditor', 'checklist', get_string('checklist', 'gradingform_checklist')); $form->setType('checklist', PARAM_RAW); - //$element->freeze(); // TODO freeze checklist editor if needed + // $element->freeze(); // TODO freeze checklist editor if needed $buttonarray = array(); $buttonarray[] = &$form->createElement('submit', 'savechecklist', get_string('savechecklist', 'gradingform_checklist')); diff --git a/lib.php b/lib.php index ff7c358..d4df1c8 100644 --- a/lib.php +++ b/lib.php @@ -47,7 +47,7 @@ class gradingform_checklist_controller extends gradingform_controller { /** checklist display mode: Preview the checklist design (for person with manage permission) */ const DISPLAY_PREVIEW = 3; /** checklist display mode: Preview the checklist (for people being graded) */ - const DISPLAY_PREVIEW_GRADED= 8; + const DISPLAY_PREVIEW_GRADED = 8; /** checklist display mode: For evaluation, enabled (teacher grades a student) */ const DISPLAY_EVAL = 4; /** checklist display mode: For evaluation, with hidden fields */ @@ -426,7 +426,7 @@ public function get_definition_copy(gradingform_controller $target) { $new->checklist = array('groups' => array(), 'options' => $old->checklist['options']); $newgroupid = 1; $newitemid = 1; - foreach ($old->checklist['groups'] as $oldgroup) { + foreach ($old->checklist['groups'] as $oldgroup) { unset($oldgroup['id']); if (isset($oldgroup['items'])) { foreach ($oldgroup['items'] as $olditemid => $olditem) { @@ -769,7 +769,7 @@ public function update($data) { foreach ($data['groups'] as $groupid => $group) { foreach($group['items'] as $itemid => $record) { - //handle deletions later + // handle deletions later if (empty($record['remark']) && empty($record['id'])) { continue; } @@ -845,7 +845,7 @@ public function get_grade() { } } - $gradeoffset = ($curscore-$scores['minscore'])/($scores['maxscore']-$scores['minscore'])*($maxgrade-$mingrade); + $gradeoffset = ($curscore - $scores['minscore']) / ($scores['maxscore'] - $scores['minscore']) * ($maxgrade - $mingrade); if ($this->get_controller()->get_allow_grade_decimals()) { return $gradeoffset + $mingrade; } @@ -861,7 +861,7 @@ public function get_grade() { */ public function render_grading_element($page, $gradingformelement) { if (!$gradingformelement->_flagFrozen) { - $module = array('name'=>'gradingform_checklist', 'fullpath'=>'/grade/grading/form/checklist/js/checklist.js'); + $module = array('name' => 'gradingform_checklist', 'fullpath' => '/grade/grading/form/checklist/js/checklist.js'); $page->requires->js_init_call('M.gradingform_checklist.init', array(array('name' => $gradingformelement->getName())), true, $module); $mode = gradingform_checklist_controller::DISPLAY_EVAL; } else { @@ -895,7 +895,7 @@ public function render_grading_element($page, $gradingformelement) { $newchecked = null; if (isset($value['groups'][$groupid]['items'][$itemid]['remark'])) $newremark = $value['groups'][$groupid]['items'][$itemid]['remark']; if (isset($value['groups'][$groupid]['items'][$itemid]['id'])) $newchecked = !empty($value['groups'][$groupid]['items'][$itemid]['id']); - if ($newchecked != !empty($item['checked']) || $newremark != $item['remark']) { + if ($newchecked != !empty($item['checked']) || $newremark != $item['remark']) { $haschanges = true; } } diff --git a/renderer.php b/renderer.php index 07e65d3..c1a66e0 100644 --- a/renderer.php +++ b/renderer.php @@ -424,7 +424,7 @@ public function display_checklist($groups, $options, $mode, $elementname = null, $scoredpoints = 0; $cnt = 0; foreach ($groups as $id => $group) { - $group['class'] = $this->get_css_class_suffix($cnt++, sizeof($groups) -1); + $group['class'] = $this->get_css_class_suffix($cnt++, sizeof($groups) - 1); $group['id'] = $id; $itemsstr = ''; $itemcnt = 0; @@ -435,7 +435,7 @@ public function display_checklist($groups, $options, $mode, $elementname = null, } foreach ($group['items'] as $itemid => $item) { $item['id'] = $itemid; - $item['class'] = $this->get_css_class_suffix($itemcnt++, sizeof($group['items']) -1); + $item['class'] = $this->get_css_class_suffix($itemcnt++, sizeof($group['items']) - 1); $item['checked'] = !empty($groupvalue['items'][$itemid]['checked']); if ($item['checked'] && ($mode == gradingform_checklist_controller::DISPLAY_EVAL_FROZEN || $mode == gradingform_checklist_controller::DISPLAY_REVIEW || $mode == gradingform_checklist_controller::DISPLAY_VIEW)) { $item['class'] .= ' checked'; @@ -487,7 +487,7 @@ protected function get_css_class_suffix($idx, $maxidx) { if ($idx == $maxidx) { $class .= ' last'; } - if ($idx%2) { + if ($idx % 2) { $class .= ' odd'; } else { $class .= ' even'; @@ -542,7 +542,7 @@ public function display_instance(gradingform_checklist_instance $instance, $idx, public function display_regrade_confirmation($elementname, $changelevel, $value) { $html = html_writer::start_tag('div', array('class' => 'gradingform_checklist-regrade')); - if ($changelevel<=2) { + if ($changelevel <= 2) { $html .= get_string('regrademessage1', 'gradingform_checklist'); $selectoptions = array( 0 => get_string('regradeoption0', 'gradingform_checklist'), From b92b609967e677e92d5b73b7f715a0a7c3499af6 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Thu, 28 Dec 2023 14:59:58 -0500 Subject: [PATCH 3/6] Removed extra newline after the opening PHP tag. --- checklisteditor.php | 1 - db/upgrade.php | 1 - edit.php | 1 - edit_form.php | 1 - lang/en/gradingform_checklist.php | 1 - lib.php | 1 - preview.php | 1 - renderer.php | 1 - version.php | 1 - 9 files changed, 9 deletions(-) diff --git a/checklisteditor.php b/checklisteditor.php index 236c001..5d6ed30 100644 --- a/checklisteditor.php +++ b/checklisteditor.php @@ -1,5 +1,4 @@ Date: Thu, 28 Dec 2023 15:06:27 -0500 Subject: [PATCH 4/6] Updated htmlentities flags to ENT_QUOTES --- renderer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/renderer.php b/renderer.php index 4326f32..c556cf8 100644 --- a/renderer.php +++ b/renderer.php @@ -119,7 +119,7 @@ public function group_template($mode, $options, $elementname = '{NAME}', $group if ($mode == gradingform_checklist_controller::DISPLAY_EVAL) { $labelforremark = html_writer::tag('label', get_string('groupremark', 'gradingform_checklist', $group['description']), array('class' => 'hiddenelement', 'for' => '{NAME}-groups-{GROUP-id}-items-0-remark')); - $input = $labelforremark . html_writer::tag('textarea', htmlspecialchars($currentremark), + $input = $labelforremark . html_writer::tag('textarea', htmlspecialchars($currentremark, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), array('id' => '{NAME}-groups-{GROUP-id}-items-0-remark', 'name' => '{NAME}[groups][{GROUP-id}][items][0][remark]', 'cols' => '10', 'rows' => '5')); $grouptemplate .= html_writer::tag('div', $input, array('class' => 'remark')); } else if ($mode == gradingform_checklist_controller::DISPLAY_EVAL_FROZEN) { @@ -281,7 +281,7 @@ public function item_template($mode, $options, $elementname = '{NAME}', $groupid if ($mode == gradingform_checklist_controller::DISPLAY_EVAL) { $labelforremark = html_writer::tag('label', get_string('itemremark', 'gradingform_checklist', $item['definition']), array('class' => 'hiddenelement', 'for' => '{NAME}-groups-{GROUP-id}-items-{ITEM-id}-remark-input')); - $input = $labelforremark . html_writer::tag('textarea', htmlspecialchars($currentremark), array('id' => '{NAME}-groups-{GROUP-id}-items-{ITEM-id}-remark-input', + $input = $labelforremark . html_writer::tag('textarea', htmlspecialchars($currentremark, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401), array('id' => '{NAME}-groups-{GROUP-id}-items-{ITEM-id}-remark-input', 'name' => '{NAME}[groups][{GROUP-id}][items][{ITEM-id}][remark]', 'cols' => '20', 'rows' => '3')); $itemtemplate .= html_writer::tag('div', $input, array('class' => 'remark')); } else if ($mode == gradingform_checklist_controller::DISPLAY_EVAL_FROZEN) { From 52e158700c7887cf452afbf6028e7dcbf607b1fe Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Thu, 28 Dec 2023 15:10:54 -0500 Subject: [PATCH 5/6] Replaced sizeof() with count(). --- lib.php | 2 +- renderer.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib.php b/lib.php index 0851813..3252f7d 100644 --- a/lib.php +++ b/lib.php @@ -832,7 +832,7 @@ public function get_grade() { } sort($graderange); $mingrade = $graderange[0]; - $maxgrade = $graderange[sizeof($graderange) - 1]; + $maxgrade = $graderange[count($graderange) - 1]; $curscore = 0; foreach ($grade['groups'] as $groupid => $group) { diff --git a/renderer.php b/renderer.php index c556cf8..6fab667 100644 --- a/renderer.php +++ b/renderer.php @@ -423,7 +423,7 @@ public function display_checklist($groups, $options, $mode, $elementname = null, $scoredpoints = 0; $cnt = 0; foreach ($groups as $id => $group) { - $group['class'] = $this->get_css_class_suffix($cnt++, sizeof($groups) - 1); + $group['class'] = $this->get_css_class_suffix($cnt++, count($groups) - 1); $group['id'] = $id; $itemsstr = ''; $itemcnt = 0; @@ -434,7 +434,7 @@ public function display_checklist($groups, $options, $mode, $elementname = null, } foreach ($group['items'] as $itemid => $item) { $item['id'] = $itemid; - $item['class'] = $this->get_css_class_suffix($itemcnt++, sizeof($group['items']) - 1); + $item['class'] = $this->get_css_class_suffix($itemcnt++, count($group['items']) - 1); $item['checked'] = !empty($groupvalue['items'][$itemid]['checked']); if ($item['checked'] && ($mode == gradingform_checklist_controller::DISPLAY_EVAL_FROZEN || $mode == gradingform_checklist_controller::DISPLAY_REVIEW || $mode == gradingform_checklist_controller::DISPLAY_VIEW)) { $item['class'] .= ' checked'; @@ -504,7 +504,7 @@ protected function get_css_class_suffix($idx, $maxidx) { */ public function display_instances($instances, $defaultcontent, $cangrade) { $return = ''; - if (sizeof($instances)) { + if (count($instances)) { $return .= html_writer::start_tag('div', array('class' => 'advancedgrade')); $idx = 0; foreach ($instances as $instance) { From 16bc6f972f6dd8e56a88e52b7fcfa556077ecf58 Mon Sep 17 00:00:00 2001 From: JuanPablo-Openlms Date: Thu, 28 Dec 2023 15:13:59 -0500 Subject: [PATCH 6/6] Removed extra space in the switch break statement. --- renderer.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/renderer.php b/renderer.php index 6fab667..f1c0d2a 100644 --- a/renderer.php +++ b/renderer.php @@ -324,20 +324,27 @@ protected function checklist_template($mode, $options, $elementname, $groupsstr, $classsuffix = ''; // CSS suffix for class of the main div. Depends on the mode switch ($mode) { case gradingform_checklist_controller::DISPLAY_EDIT_FULL: - $classsuffix = ' editor editable'; break; + $classsuffix = ' editor editable'; + break; case gradingform_checklist_controller::DISPLAY_EDIT_FROZEN: - $classsuffix = ' editor frozen'; break; + $classsuffix = ' editor frozen'; + break; case gradingform_checklist_controller::DISPLAY_PREVIEW: case gradingform_checklist_controller::DISPLAY_PREVIEW_GRADED: - $classsuffix = ' editor preview'; break; + $classsuffix = ' editor preview'; + break; case gradingform_checklist_controller::DISPLAY_EVAL: - $classsuffix = ' evaluate editable'; break; + $classsuffix = ' evaluate editable'; + break; case gradingform_checklist_controller::DISPLAY_EVAL_FROZEN: - $classsuffix = ' evaluate frozen'; break; + $classsuffix = ' evaluate frozen'; + break; case gradingform_checklist_controller::DISPLAY_REVIEW: - $classsuffix = ' review'; break; + $classsuffix = ' review'; + break; case gradingform_checklist_controller::DISPLAY_VIEW: - $classsuffix = ' view'; break; + $classsuffix = ' view'; + break; } $checklisttemplate = html_writer::start_tag('div', array('id' => 'checklist-{NAME}', 'class' => 'clearfix gradingform_checklist'.$classsuffix));