diff --git a/checklisteditor.php b/checklisteditor.php index 997d518..5d6ed30 100644 --- a/checklisteditor.php +++ b/checklisteditor.php @@ -1,5 +1,4 @@ setHelpButton() instead'); } @@ -99,14 +98,14 @@ 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'] + 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 { @@ -190,7 +189,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 +238,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 +325,7 @@ protected function get_next_id($ids) { $maxid = (int)$matches[1]; } } - return 'NEWID'.($maxid+1); + return 'NEWID' . ($maxid + 1); } @@ -370,7 +369,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/db/upgrade.php b/db/upgrade.php index 297a1d2..4db9610 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -1,5 +1,4 @@ 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 +67,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/lang/en/gradingform_checklist.php b/lang/en/gradingform_checklist.php index cf2c4b7..d46fdea 100644 --- a/lang/en/gradingform_checklist.php +++ b/lang/en/gradingform_checklist.php @@ -1,5 +1,4 @@ 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) { @@ -464,7 +463,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 +629,7 @@ public static function get_default_options() { 'showitempointstudent' => 1, 'enableitemremarks' => 1, 'enablegroupremarks' => 1, - 'showremarksstudent' => 1 + 'showremarksstudent' => 1, ); return $options; } @@ -769,7 +768,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; } @@ -833,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) { @@ -845,7 +844,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 +860,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 +894,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/preview.php b/preview.php index 6bd3d04..ef2c23d 100644 --- a/preview.php +++ b/preview.php @@ -1,5 +1,4 @@ '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) { @@ -282,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) { @@ -325,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)); @@ -424,7 +430,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; @@ -435,7 +441,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'; @@ -487,7 +493,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'; @@ -505,7 +511,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) { @@ -542,11 +548,11 @@ 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'), - 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, ], ]; diff --git a/version.php b/version.php index 2b8309c..39bdca8 100644 --- a/version.php +++ b/version.php @@ -1,5 +1,4 @@