Skip to content

Resolved Code Checker Errors #3

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

Open
wants to merge 6 commits into
base: MOODLE_401_STABLE
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
17 changes: 8 additions & 9 deletions checklisteditor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -53,7 +52,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');
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -326,7 +325,7 @@ protected function get_next_id($ids) {
$maxid = (int)$matches[1];
}
}
return 'NEWID'.($maxid+1);
return 'NEWID' . ($maxid + 1);
}


Expand Down Expand Up @@ -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);
}
}
1 change: 0 additions & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
1 change: 0 additions & 1 deletion edit.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
5 changes: 2 additions & 3 deletions edit_form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -50,7 +49,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);

Expand All @@ -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'));
Expand Down
1 change: 0 additions & 1 deletion lang/en/gradingform_checklist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
19 changes: 9 additions & 10 deletions lib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -47,7 +46,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 */
Expand Down Expand Up @@ -426,7 +425,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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -630,7 +629,7 @@ public static function get_default_options() {
'showitempointstudent' => 1,
'enableitemremarks' => 1,
'enablegroupremarks' => 1,
'showremarksstudent' => 1
'showremarksstudent' => 1,
);
return $options;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 0 additions & 1 deletion preview.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
38 changes: 22 additions & 16 deletions renderer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -120,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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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';
Expand Down Expand Up @@ -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';
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/generator/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];

Expand Down
8 changes: 4 additions & 4 deletions tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
];

Expand Down Expand Up @@ -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,
],
];

Expand Down
1 change: 0 additions & 1 deletion version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down