PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/workshop/form/numerrors/edit_form.php

https://bitbucket.org/moodle/moodle
PHP | 111 lines | 61 code | 15 blank | 35 comment | 6 complexity | a7295878e1db1aade6c5e6b29d4a93e5 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 an mform to edit "Number of errors" grading strategy forms.
  18. *
  19. * @package workshopform_numerrors
  20. * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once(__DIR__ . '/../../lib.php'); // module library
  25. require_once(__DIR__ . '/../edit_form.php'); // parent class definition
  26. /**
  27. * Class for editing "Number of errors" grading strategy forms.
  28. *
  29. * @uses moodleform
  30. */
  31. class workshop_edit_numerrors_strategy_form extends workshop_edit_strategy_form {
  32. /**
  33. * Define the elements to be displayed at the form
  34. *
  35. * Called by the parent::definition()
  36. *
  37. * @return void
  38. */
  39. protected function definition_inner(&$mform) {
  40. $plugindefaults = get_config('workshopform_numerrors');
  41. $nodimensions = $this->_customdata['nodimensions']; // number of currently filled dimensions
  42. $norepeats = $this->_customdata['norepeats']; // number of dimensions to display
  43. $descriptionopts = $this->_customdata['descriptionopts']; // wysiwyg fields options
  44. $current = $this->_customdata['current']; // current data to be set
  45. $mform->addElement('hidden', 'norepeats', $norepeats);
  46. $mform->setType('norepeats', PARAM_INT);
  47. // value not to be overridden by submitted value
  48. $mform->setConstants(array('norepeats' => $norepeats));
  49. for ($i = 0; $i < $norepeats; $i++) {
  50. $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_numerrors', $i+1));
  51. $mform->addElement('hidden', 'dimensionid__idx_'.$i); // the id in workshop_forms
  52. $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
  53. $mform->addElement('editor', 'description__idx_'.$i.'_editor',
  54. get_string('dimensiondescription', 'workshopform_numerrors'), '', $descriptionopts);
  55. $mform->addElement('text', 'grade0__idx_'.$i, get_string('grade0', 'workshopform_numerrors'), array('size'=>'15'));
  56. $mform->setDefault('grade0__idx_'.$i, $plugindefaults->grade0);
  57. $mform->setType('grade0__idx_'.$i, PARAM_TEXT);
  58. $mform->addElement('text', 'grade1__idx_'.$i, get_string('grade1', 'workshopform_numerrors'), array('size'=>'15'));
  59. $mform->setDefault('grade1__idx_'.$i, $plugindefaults->grade1);
  60. $mform->setType('grade1__idx_'.$i, PARAM_TEXT);
  61. $mform->addElement('select', 'weight__idx_'.$i,
  62. get_string('dimensionweight', 'workshopform_numerrors'), workshop::available_dimension_weights_list());
  63. $mform->setDefault('weight__idx_'.$i, 1);
  64. }
  65. $mform->addElement('header', 'mappingheader', get_string('grademapping', 'workshopform_numerrors'));
  66. $mform->addElement('static', 'mappinginfo', get_string('maperror', 'workshopform_numerrors'),
  67. get_string('mapgrade', 'workshopform_numerrors'));
  68. // get the total weight of all items == maximum weighted number of errors
  69. $totalweight = 0;
  70. for ($i = 0; $i < $norepeats; $i++) {
  71. if (!empty($current->{'weight__idx_'.$i})) {
  72. $totalweight += $current->{'weight__idx_'.$i};
  73. }
  74. }
  75. $totalweight = max($totalweight, $nodimensions);
  76. $percents = array();
  77. $percents[''] = '';
  78. for ($i = 100; $i >= 0; $i--) {
  79. $percents[$i] = get_string('percents', 'moodle', $i);
  80. }
  81. $mform->addElement('static', 'mappingzero', 0, get_string('percents', 'moodle', 100));
  82. for ($i = 1; $i <= $totalweight; $i++) {
  83. $selects = array();
  84. $selects[] = $mform->createElement('select', 'map__idx_'.$i, $i, $percents);
  85. $selects[] = $mform->createElement('static', 'mapdefault__idx_'.$i, '',
  86. get_string('percents', 'moodle', floor(100 - $i * 100 / $totalweight)));
  87. $mform->addGroup($selects, 'grademapping'.$i, $i, array(' '), false);
  88. $mform->setDefault('map__idx_'.$i, '');
  89. }
  90. $mform->registerNoSubmitButton('noadddims');
  91. $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopform_numerrors',
  92. workshop_numerrors_strategy::ADDDIMS));
  93. $mform->closeHeaderBefore('noadddims');
  94. $this->set_data($current);
  95. }
  96. }