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;
24 private $commonparams;
29 public function init() {
31 $this->presentationoptions = array('maxfiles' => EDITOR_UNLIMITED_FILES,
36 public function build_editform($item, $feedback, $cm) {
38 require_once('label_form.php');
40 //get the lastposition number of the feedback_items
41 $position = $item->position;
42 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
43 if ($position == -1) {
44 $i_formselect_last = $lastposition + 1;
45 $i_formselect_value = $lastposition + 1;
46 $item->position = $lastposition + 1;
48 $i_formselect_last = $lastposition;
49 $i_formselect_value = $item->position;
51 //the elements for position dropdownlist
52 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
54 //all items for dependitem
55 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
56 $commonparams = array('cmid'=>$cm->id,
57 'id'=>isset($item->id) ? $item->id : null,
59 'items'=>$feedbackitems,
60 'feedback'=>$feedback->id);
62 $this->context = context_module::instance($cm->id);
64 //preparing the editor for new file-api
65 $item->presentationformat = FORMAT_HTML;
66 $item->presentationtrust = 1;
68 // Append editor context to presentation options, giving preference to existing context.
69 $this->presentationoptions = array_merge(array('context' => $this->context),
70 $this->presentationoptions);
72 $item = file_prepare_standard_editor($item,
73 'presentation', //name of the form element
74 $this->presentationoptions,
77 'item', //the filearea
81 $customdata = array('item' => $item,
82 'common' => $commonparams,
83 'positionlist' => $positionlist,
84 'position' => $position,
85 'presentationoptions' => $this->presentationoptions);
87 $this->item_form = new feedback_label_form('edit_item.php', $customdata);
90 //this function only can used after the call of build_editform()
91 public function show_editform() {
92 $this->item_form->display();
95 public function is_cancelled() {
96 return $this->item_form->is_cancelled();
99 public function get_data() {
100 if ($this->item = $this->item_form->get_data()) {
106 public function save_item() {
109 if (!$item = $this->item_form->get_data()) {
113 if (isset($item->clone_item) AND $item->clone_item) {
114 $item->id = ''; //to clone this item
118 $item->presentation = '';
120 $item->hasvalue = $this->get_hasvalue();
122 $item->id = $DB->insert_record('feedback_item', $item);
124 $DB->update_record('feedback_item', $item);
127 $item = file_postupdate_standard_editor($item,
129 $this->presentationoptions,
135 $DB->update_record('feedback_item', $item);
137 return $DB->get_record('feedback_item', array('id'=>$item->id));
140 public function print_item($item) {
143 require_once($CFG->libdir . '/filelib.php');
145 //is the item a template?
146 if (!$item->feedback AND $item->template) {
147 $template = $DB->get_record('feedback_template', array('id'=>$item->template));
148 if ($template->ispublic) {
149 $context = context_system::instance();
151 $context = context_course::instance($template->course);
153 $filearea = 'template';
155 $cm = get_coursemodule_from_instance('feedback', $item->feedback);
156 $context = context_module::instance($cm->id);
160 $item->presentationformat = FORMAT_HTML;
161 $item->presentationtrust = 1;
163 $output = file_rewrite_pluginfile_urls($item->presentation,
170 $formatoptions = array('overflowdiv'=>true, 'trusted'=>$CFG->enabletrusttext);
171 echo format_text($output, FORMAT_HTML, $formatoptions);
175 * print the item at the edit-page of feedback
178 * @param object $item
181 public function print_item_preview($item) {
184 if ($item->dependitem) {
185 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
186 echo ' <span class="feedback_depend">';
187 echo '('.format_string($dependitem->label).'->'.$item->dependvalue.')';
191 $this->print_item($item);
195 * print the item at the complete-page of feedback
198 * @param object $item
199 * @param string $value
200 * @param bool $highlightrequire
203 public function print_item_complete($item, $value = '', $highlightrequire = false) {
204 $this->print_item($item);
208 * print the item at the complete-page of feedback
211 * @param object $item
212 * @param string $value
215 public function print_item_show_value($item, $value = '') {
216 $this->print_item($item);
219 public function create_value($data) {
223 public function compare_value($item, $dbvalue, $dependvalue) {
227 //used by create_item and update_item functions,
228 //when provided $data submitted from feedback_show_edit
229 public function get_presentation($data) {
232 public function postupdate($item) {
235 $context = context_module::instance($item->cmid);
236 $item = file_postupdate_standard_editor($item,
238 $this->presentationoptions,
244 $DB->update_record('feedback_item', $item);
248 public function get_hasvalue() {
252 public function can_switch_require() {
256 public function check_value($value, $item) {
259 public function excelprint_item(&$worksheet,
267 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
269 public function get_printval($item, $value) {
271 public function get_analysed($item, $groupid = false, $courseid = false) {
273 public function value_type() {
276 public function clean_input_value($value) {