2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 defined('MOODLE_INTERNAL') OR die('not allowed');
18 require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
19 require_once($CFG->libdir.'/formslib.php');
21 class feedback_item_label extends feedback_item_base {
22 protected $type = "label";
23 private $presentationoptions = null;
29 public function __construct() {
30 $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
35 public function build_editform($item, $feedback, $cm) {
37 require_once('label_form.php');
39 //get the lastposition number of the feedback_items
40 $position = $item->position;
41 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
42 if ($position == -1) {
43 $i_formselect_last = $lastposition + 1;
44 $i_formselect_value = $lastposition + 1;
45 $item->position = $lastposition + 1;
47 $i_formselect_last = $lastposition;
48 $i_formselect_value = $item->position;
50 //the elements for position dropdownlist
51 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
53 //all items for dependitem
54 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
55 $commonparams = array('cmid'=>$cm->id,
56 'id'=>isset($item->id) ? $item->id : null,
58 'items'=>$feedbackitems,
59 'feedback'=>$feedback->id);
61 $this->context = context_module::instance($cm->id);
63 //preparing the editor for new file-api
64 $item->presentationformat = FORMAT_HTML;
65 $item->presentationtrust = 1;
67 // Append editor context to presentation options, giving preference to existing context.
68 $this->presentationoptions = array_merge(array('context' => $this->context),
69 $this->presentationoptions);
71 $item = file_prepare_standard_editor($item,
72 'presentation', //name of the form element
73 $this->presentationoptions,
76 'item', //the filearea
80 $customdata = array('item' => $item,
81 'common' => $commonparams,
82 'positionlist' => $positionlist,
83 'position' => $position,
84 'presentationoptions' => $this->presentationoptions);
86 $this->item_form = new feedback_label_form('edit_item.php', $customdata);
89 public function save_item() {
92 if (!$item = $this->item_form->get_data()) {
96 if (isset($item->clone_item) AND $item->clone_item) {
97 $item->id = ''; //to clone this item
101 $item->presentation = '';
103 $item->hasvalue = $this->get_hasvalue();
105 $item->id = $DB->insert_record('feedback_item', $item);
107 $DB->update_record('feedback_item', $item);
110 $item = file_postupdate_standard_editor($item,
112 $this->presentationoptions,
118 $DB->update_record('feedback_item', $item);
120 return $DB->get_record('feedback_item', array('id'=>$item->id));
124 * prepares the item for output or export to file
125 * @param stdClass $item
128 private function print_item($item) {
131 require_once($CFG->libdir . '/filelib.php');
133 //is the item a template?
134 if (!$item->feedback AND $item->template) {
135 $template = $DB->get_record('feedback_template', array('id'=>$item->template));
136 if ($template->ispublic) {
137 $context = context_system::instance();
139 $context = context_course::instance($template->course);
141 $filearea = 'template';
143 $cm = get_coursemodule_from_instance('feedback', $item->feedback);
144 $context = context_module::instance($cm->id);
148 $item->presentationformat = FORMAT_HTML;
149 $item->presentationtrust = 1;
151 $output = file_rewrite_pluginfile_urls($item->presentation,
158 $formatoptions = array('overflowdiv'=>true, 'trusted'=>$CFG->enabletrusttext);
159 echo format_text($output, FORMAT_HTML, $formatoptions);
163 * @param stdClass $item
164 * @param bool|true $withpostfix
167 public function get_display_name($item, $withpostfix = true) {
172 * Adds an input element to the complete form
174 * @param stdClass $item
175 * @param mod_feedback_complete_form $form
177 public function complete_form_element($item, $form) {
179 if (!$item->feedback AND $item->template) {
180 // This is a template.
181 $template = $DB->get_record('feedback_template', array('id' => $item->template));
182 if ($template->ispublic) {
183 $context = context_system::instance();
185 $context = context_course::instance($template->course);
187 $filearea = 'template';
189 // This is a question in the current feedback.
190 $context = $form->get_cm()->context;
193 $output = file_rewrite_pluginfile_urls($item->presentation, 'pluginfile.php',
194 $context->id, 'mod_feedback', $filearea, $item->id);
195 $formatoptions = array('overflowdiv' => true, 'noclean' => true);
196 $output = format_text($output, FORMAT_HTML, $formatoptions);
198 $inputname = $item->typ . '_' . $item->id;
200 $name = $this->get_display_name($item);
201 $form->add_form_element($item, ['static', $inputname, $name, $output], false, false);
204 public function compare_value($item, $dbvalue, $dependvalue) {
208 public function postupdate($item) {
211 $context = context_module::instance($item->cmid);
212 $item = file_postupdate_standard_editor($item,
214 $this->presentationoptions,
220 $DB->update_record('feedback_item', $item);
224 public function get_hasvalue() {
228 public function can_switch_require() {
232 public function excelprint_item(&$worksheet,
240 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
242 public function get_printval($item, $value) {