Differences Between: [Versions 400 and 402] [Versions 400 and 403]
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 * Class for exporting a feedback item (question). 19 * 20 * @package mod_feedback 21 * @copyright 2017 Juan Leyva <juan@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace mod_feedback\external; 25 defined('MOODLE_INTERNAL') || die(); 26 27 use mod_feedback\feedback; 28 use core\external\exporter; 29 use renderer_base; 30 use core_files\external\stored_file_exporter; 31 32 /** 33 * Class for exporting a feedback item (question). 34 * 35 * @copyright 2017 Juan Leyva <juan@moodle.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class feedback_item_exporter extends exporter { 39 40 protected static function define_properties() { 41 return array( 42 'id' => array( 43 'type' => PARAM_INT, 44 'description' => 'The record id.', 45 ), 46 'feedback' => array( 47 'type' => PARAM_INT, 48 'description' => 'The feedback instance id this records belongs to.', 49 'default' => 0, 50 ), 51 'template' => array( 52 'type' => PARAM_INT, 53 'description' => 'If it belogns to a template, the template id.', 54 'default' => 0, 55 ), 56 'name' => array( 57 'type' => PARAM_RAW, 58 'description' => 'The item name.', 59 ), 60 'label' => array( 61 'type' => PARAM_NOTAGS, 62 'description' => 'The item label.', 63 ), 64 'presentation' => array( 65 'type' => PARAM_RAW, 66 'description' => 'The text describing the item or the available possible answers.', 67 ), 68 'typ' => array( 69 'type' => PARAM_ALPHA, 70 'description' => 'The type of the item.', 71 ), 72 'hasvalue' => array( 73 'type' => PARAM_INT, 74 'description' => 'Whether it has a value or not.', 75 'default' => 0, 76 ), 77 'position' => array( 78 'type' => PARAM_INT, 79 'description' => 'The position in the list of questions.', 80 'default' => 0, 81 ), 82 'required' => array( 83 'type' => PARAM_BOOL, 84 'description' => 'Whether is a item (question) required or not.', 85 'default' => 0, 86 ), 87 'dependitem' => array( 88 'type' => PARAM_INT, 89 'description' => 'The item id this item depend on.', 90 'default' => 0, 91 ), 92 'dependvalue' => array( 93 'type' => PARAM_RAW, 94 'description' => 'The depend value.', 95 ), 96 'options' => array( 97 'type' => PARAM_ALPHA, 98 'description' => 'Different additional settings for the item (question).', 99 ), 100 ); 101 } 102 103 protected static function define_related() { 104 return array( 105 'context' => 'context', 106 'itemnumber' => 'int?' 107 ); 108 } 109 110 protected static function define_other_properties() { 111 return array( 112 'itemfiles' => array( 113 'type' => stored_file_exporter::read_properties_definition(), 114 'multiple' => true 115 ), 116 'itemnumber' => array( 117 'type' => PARAM_INT, 118 'description' => 'The item position number', 119 'null' => NULL_ALLOWED 120 ), 121 'otherdata' => array( 122 'type' => PARAM_RAW, 123 'description' => 'Additional data that may be required by external functions', 124 'null' => NULL_ALLOWED 125 ), 126 ); 127 } 128 129 protected function get_other_values(renderer_base $output) { 130 $context = $this->related['context']; 131 132 $itemobj = feedback_get_item_class($this->data->typ); 133 $values = array( 134 'itemfiles' => array(), 135 'itemnumber' => $this->related['itemnumber'], 136 'otherdata' => $itemobj->get_data_for_external($this->data), 137 ); 138 139 $fs = get_file_storage(); 140 $files = array(); 141 $itemfiles = $fs->get_area_files($context->id, 'mod_feedback', 'item', $this->data->id, 'filename', false); 142 if (!empty($itemfiles)) { 143 foreach ($itemfiles as $storedfile) { 144 $fileexporter = new stored_file_exporter($storedfile, array('context' => $context)); 145 $files[] = $fileexporter->export($output); 146 } 147 $values['itemfiles'] = $files; 148 } 149 150 return $values; 151 } 152 153 /** 154 * Get the formatting parameters for the name. 155 * 156 * @return array 157 */ 158 protected function get_format_parameters_for_name() { 159 return [ 160 'component' => 'mod_feedback', 161 'filearea' => 'item', 162 'itemid' => $this->data->id 163 ]; 164 } 165 166 /** 167 * Get the formatting parameters for the presentation. 168 * 169 * @return array 170 */ 171 protected function get_format_parameters_for_presentation() { 172 return [ 173 'component' => 'mod_feedback', 174 'filearea' => 'item', 175 'itemid' => $this->data->id 176 ]; 177 } 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body