Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
18
 * This file defines a base class for all assessment forms
19
 *
20
 * @package    mod_workshop
21
 * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->libdir . '/formslib.php'); // parent class definition
28
 
29
/**
30
 * Base class for all assessment forms
31
 *
32
 * This defines the common fields that all assessment forms need.
33
 * Strategies should define their own class that inherits from this one, and
34
 * implements the definition_inner() method.
35
 *
36
 * @uses moodleform
37
 */
38
class workshop_assessment_form extends moodleform {
39
 
40
    /** @var string Mode to open the form in: preview/assessment. */
41
    public $mode;
42
 
43
    /** @var workshop_strategy workshop strategy */
44
    public $strategy;
45
 
46
    /** @var workshop workshop. */
47
    public $workshop;
48
 
49
    /** @var array options. */
50
    public $options;
51
 
52
    /**
53
     * Add the fields that are common for all grading strategies.
54
     *
55
     * If the strategy does not support all these fields, then you can override
56
     * this method and remove the ones you don't want with
57
     * $mform->removeElement().
58
     * Strategy subclassess should define their own fields in definition_inner()
59
     *
60
     * @return void
61
     */
62
    public function definition() {
63
        global $CFG;
64
 
65
        $mform          = $this->_form;
66
        $this->mode     = $this->_customdata['mode'];       // influences the save buttons
67
        $this->strategy = $this->_customdata['strategy'];   // instance of the strategy api class
68
        $this->workshop = $this->_customdata['workshop'];   // instance of the workshop api class
69
        $this->options  = $this->_customdata['options'];    // array with addiotional options
70
 
71
        // Disable shortforms
72
        $mform->setDisableShortforms();
73
 
74
        // add the strategy-specific fields
75
        $this->definition_inner($mform);
76
 
77
        // add the data common for all subplugins
78
        $mform->addElement('hidden', 'strategy', $this->workshop->strategy);
79
        $mform->setType('strategy', PARAM_PLUGIN);
80
 
81
        if ($this->workshop->overallfeedbackmode and $this->is_editable()) {
82
            $mform->addElement('header', 'overallfeedbacksection', get_string('overallfeedback', 'mod_workshop'));
83
            $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_workshop'), null,
84
                $this->workshop->overall_feedback_content_options());
85
            if ($this->workshop->overallfeedbackmode == 2) {
86
                $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client');
87
            }
88
            if ($this->workshop->overallfeedbackfiles) {
89
                $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager',
90
                    get_string('feedbackauthorattachment', 'mod_workshop'), null,
91
                    $this->workshop->overall_feedback_attachment_options());
92
            }
93
        }
94
 
95
        if (!empty($this->options['editableweight']) and $this->is_editable()) {
96
            $mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'workshop'));
97
            $mform->addElement('select', 'weight',
98
                    get_string('assessmentweight', 'workshop'), workshop::available_assessment_weights_list());
99
            $mform->setDefault('weight', 1);
100
        }
101
 
102
        $buttonarray = array();
103
        if ($this->mode == 'preview') {
104
            $buttonarray[] = $mform->createElement('cancel', 'backtoeditform', get_string('backtoeditform', 'workshop'));
105
        }
106
        if ($this->mode == 'assessment') {
107
            if (!empty($this->options['pending'])) {
108
                $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('saveandshownext', 'workshop'));
109
            }
110
            $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
111
            $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
112
            $buttonarray[] = $mform->createElement('cancel');
113
        }
114
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
115
        $mform->closeHeaderBefore('buttonar');
116
    }
117
 
118
    /**
119
     * Add any strategy specific form fields.
120
     *
121
     * @param stdClass $mform the form being built.
122
     */
123
    protected function definition_inner(&$mform) {
124
        // By default, do nothing.
125
    }
126
 
127
    /**
128
     * Is the form frozen (read-only)?
129
     *
130
     * @return boolean
131
     */
132
    public function is_editable() {
133
        return !$this->_form->isFrozen();
134
    }
135
 
136
    /**
137
     * Return the form custom data.
138
     *
139
     * @return array an array containing the custom data
140
     * @since  Moodle 3.4
141
     */
142
    public function get_customdata() {
143
        return $this->_customdata;
144
    }
145
}