1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file defines an mform to assess a submission by accumulative grading strategy
20 *
21 * @package    workshopform_accumulative
22 * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28require_once(__DIR__.'/../assessment_form.php');    // parent class definition
29
30/**
31 * Class representing a form for assessing submissions by accumulative grading strategy
32 *
33 * @uses moodleform
34 */
35class workshop_accumulative_assessment_form extends workshop_assessment_form {
36
37    /**
38     * Define the elements to be displayed at the form
39     *
40     * Called by the parent::definition()
41     *
42     * @return void
43     */
44    protected function definition_inner(&$mform) {
45        $fields     = $this->_customdata['fields'];
46        $current    = $this->_customdata['current'];
47        $nodims     = $this->_customdata['nodims'];     // number of assessment dimensions
48
49        $mform->addElement('hidden', 'nodims', $nodims);
50        $mform->setType('nodims', PARAM_INT);
51
52        // minimal grade value to select - used by the 'compare' rule below
53        // (just an implementation detail to make the rule work, this element is
54        // not processed by the server)
55        $mform->addElement('hidden', 'minusone', -1);
56        $mform->setType('minusone', PARAM_INT);
57
58        for ($i = 0; $i < $nodims; $i++) {
59            // dimension header
60            $dimtitle = get_string('dimensionnumber', 'workshopform_accumulative', $i+1);
61            $mform->addElement('header', 'dimensionhdr__idx_'.$i, $dimtitle);
62
63            // dimension id
64            $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
65            $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
66
67            // grade id
68            $mform->addElement('hidden', 'gradeid__idx_'.$i);   // value set by set_data() later
69            $mform->setType('gradeid__idx_'.$i, PARAM_INT);
70
71            // dimension description
72            $desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description accumulative">'."\n";
73            $desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
74            $desc .= "\n</div>";
75            $mform->addElement('html', $desc);
76
77            // grade for this aspect
78            $label = get_string('dimensiongradefor', 'workshopform_accumulative', $dimtitle);
79            if ($fields->{'grade__idx_' . $i}) {
80                $options = make_grades_menu($fields->{'grade__idx_' . $i});
81                $options = array('-1' => get_string('choosedots')) + $options;
82                $mform->addElement('select', 'grade__idx_' . $i, $label, $options);
83                $mform->addRule(array('grade__idx_' . $i, 'minusone'),
84                    get_string('mustchoosegrade', 'workshopform_accumulative'), 'compare', 'gt');
85            }
86            // comment
87            $label = get_string('dimensioncommentfor', 'workshopform_accumulative', $dimtitle);
88            //$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
89            $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
90        }
91        $this->set_data($current);
92    }
93}
94