PageRenderTime 76ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/workshop/form/rubric/assessment_form.php

https://bitbucket.org/moodle/moodle
PHP | 170 lines | 89 code | 26 blank | 55 comment | 9 complexity | da452196e54273130b0089d711aac8be MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file defines mforms to assess a submission by rubric grading strategy
  18. *
  19. * Rubric can be displayed in two possible layouts - list or grid. This file defines
  20. * therefore defines two classes, respectively.
  21. *
  22. * @package workshopform_rubric
  23. * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25. */
  26. defined('MOODLE_INTERNAL') || die();
  27. require_once(__DIR__ . '/../assessment_form.php'); // parent class definition
  28. /**
  29. * Base class representing a form for assessing submissions by rubric grading strategy
  30. */
  31. abstract class workshop_rubric_assessment_form extends workshop_assessment_form {
  32. public function validation($data, $files) {
  33. $errors = parent::validation($data, $files);
  34. for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) {
  35. if (empty($data['chosenlevelid__idx_'.$i])) {
  36. $errors['chosenlevelid__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric'); // used in grid
  37. $errors['levelgrp__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric'); // used in list
  38. }
  39. }
  40. return $errors;
  41. }
  42. }
  43. /**
  44. * Class representing a form for assessing submissions by rubric grading strategy - list layout
  45. */
  46. class workshop_rubric_list_assessment_form extends workshop_rubric_assessment_form {
  47. /**
  48. * Define the elements to be displayed at the form
  49. *
  50. * Called by the parent::definition()
  51. *
  52. * @return void
  53. */
  54. protected function definition_inner(&$mform) {
  55. $workshop = $this->_customdata['workshop'];
  56. $fields = $this->_customdata['fields'];
  57. $current = $this->_customdata['current'];
  58. $nodims = $this->_customdata['nodims']; // number of assessment dimensions
  59. for ($i = 0; $i < $nodims; $i++) {
  60. // dimension header
  61. $dimtitle = get_string('dimensionnumber', 'workshopform_rubric', $i+1);
  62. $mform->addElement('header', 'dimensionhdr__idx_'.$i, $dimtitle);
  63. // dimension id
  64. $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
  65. $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
  66. // grade id
  67. $mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
  68. $mform->setType('gradeid__idx_'.$i, PARAM_INT);
  69. // dimension description
  70. $desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description rubric">'."\n";
  71. $desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
  72. $desc .= "\n</div>";
  73. $mform->addElement('html', $desc);
  74. $numoflevels = $fields->{'numoflevels__idx_'.$i};
  75. $levelgrp = array();
  76. for ($j = 0; $j < $numoflevels; $j++) {
  77. $levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
  78. $definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
  79. $definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
  80. $levelgrp[] = $mform->createElement('radio', 'chosenlevelid__idx_'.$i, '',
  81. format_text($definition, $definitionformat, null, $workshop->course->id), $levelid);
  82. }
  83. $mform->addGroup($levelgrp, 'levelgrp__idx_'.$i, '', "<br />\n", false);
  84. }
  85. $this->set_data($current);
  86. }
  87. }
  88. /**
  89. * Class representing a form for assessing submissions by rubric grading strategy - grid layout
  90. */
  91. class workshop_rubric_grid_assessment_form extends workshop_rubric_assessment_form {
  92. /**
  93. * Define the elements to be displayed at the form
  94. *
  95. * Called by the parent::definition()
  96. *
  97. * @return void
  98. */
  99. protected function definition_inner(&$mform) {
  100. $workshop = $this->_customdata['workshop'];
  101. $fields = $this->_customdata['fields'];
  102. $current = $this->_customdata['current'];
  103. $nodims = $this->_customdata['nodims']; // number of assessment dimensions
  104. // get the number of required grid columns
  105. $levelcounts = array();
  106. for ($i = 0; $i < $nodims; $i++) {
  107. if ($fields->{'numoflevels__idx_'.$i} > 0) {
  108. $levelcounts[] = $fields->{'numoflevels__idx_'.$i};
  109. }
  110. }
  111. $numofcolumns = array_reduce($levelcounts, 'workshop::lcm', 1);
  112. $mform->addElement('header', 'rubric-grid-wrapper', get_string('layoutgrid', 'workshopform_rubric'));
  113. $mform->addElement('html', '<table class="rubric-grid">' . "\n");
  114. $mform->addElement('html', '<th class="header">' . get_string('criteria', 'workshopform_rubric') . '</th>');
  115. $mform->addElement('html', '<th class="header" colspan="'.$numofcolumns.'">'.get_string('levels', 'workshopform_rubric').'</th>');
  116. for ($i = 0; $i < $nodims; $i++) {
  117. $mform->addElement('html', '<tr class="r'. $i % 2 .'"><td class="criterion">' . "\n");
  118. // dimension id
  119. $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
  120. $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
  121. // given grade id
  122. $mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
  123. $mform->setType('gradeid__idx_'.$i, PARAM_INT);
  124. // dimension description
  125. $desc = format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
  126. $desc .= "</td>\n";
  127. $mform->addElement('html', $desc);
  128. $numoflevels = $fields->{'numoflevels__idx_'.$i};
  129. for ($j = 0; $j < $numoflevels; $j++) {
  130. $colspan = $numofcolumns / $numoflevels;
  131. $mform->addElement('html', '<td class="level c' . $j % 2 . '" colspan="' . $colspan . '">' . "\n");
  132. $levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
  133. $definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
  134. $definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
  135. $mform->addElement('radio', 'chosenlevelid__idx_'.$i, '',
  136. format_text($definition, $definitionformat, null, $workshop->course->id), $levelid);
  137. $mform->addElement('html', '</td>' . "\n");
  138. }
  139. $mform->addElement('html', '</tr>' . "\n");
  140. }
  141. $mform->addElement('html', '</table>' . "\n");
  142. $this->set_data($current);
  143. }
  144. }