[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 stored_file data. 19 * 20 * @package core_competency 21 * @copyright 2015 Frédéric Massart - FMCorz.net 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core_competency\external; 25 26 use coding_exception; 27 use core_text; 28 use moodle_url; 29 use renderer_base; 30 use stdClass; 31 use stored_file; 32 33 /** 34 * Class for exporting stored_file data. 35 * 36 * @package core_competency 37 * @copyright 2015 Frédéric Massart - FMCorz.net 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class stored_file_exporter extends exporter { 41 42 /** @var stored_file */ 43 protected $file; 44 45 public function __construct(stored_file $file, $related = array()) { 46 $this->file = $file; 47 48 $data = new stdClass(); 49 $data->contextid = $file->get_contextid(); 50 $data->component = $file->get_component(); 51 $data->filearea = $file->get_filearea(); 52 $data->itemid = $file->get_itemid(); 53 $data->filepath = $file->get_filepath(); 54 $data->filename = $file->get_filename(); 55 $data->isdir = $file->is_directory(); 56 $data->timemodified = $file->get_timemodified(); 57 $data->timecreated = $file->get_timecreated(); 58 $data->filesize = $file->get_filesize(); 59 $data->author = $file->get_author(); 60 $data->license = $file->get_license(); 61 62 if ($related['context']->id != $data->contextid) { 63 throw new coding_exception('Unexpected context ID received.'); 64 } 65 66 parent::__construct($data, $related); 67 } 68 69 protected static function define_related() { 70 return array('context' => 'context'); 71 } 72 73 protected static function define_properties() { 74 return array( 75 'contextid' => array( 76 'type' => PARAM_INT 77 ), 78 'component' => array( 79 'type' => PARAM_COMPONENT 80 ), 81 'filearea' => array( 82 'type' => PARAM_AREA 83 ), 84 'itemid' => array( 85 'type' => PARAM_INT 86 ), 87 'filepath' => array( 88 'type' => PARAM_PATH 89 ), 90 'filename' => array( 91 'type' => PARAM_FILE 92 ), 93 'isdir' => array( 94 'type' => PARAM_BOOL 95 ), 96 'timemodified' => array( 97 'type' => PARAM_INT 98 ), 99 'timecreated' => array( 100 'type' => PARAM_INT 101 ), 102 'filesize' => array( 103 'type' => PARAM_INT 104 ), 105 'author' => array( 106 'type' => PARAM_TEXT 107 ), 108 'license' => array( 109 'type' => PARAM_TEXT 110 ) 111 ); 112 } 113 114 protected static function define_other_properties() { 115 return array( 116 'filenameshort' => array( 117 'type' => PARAM_RAW, 118 ), 119 'filesizeformatted' => array( 120 'type' => PARAM_RAW 121 ), 122 'icon' => array( 123 'type' => PARAM_RAW, 124 ), 125 'iconurl' => array( 126 'type' => PARAM_URL, 127 ), 128 'timecreatedformatted' => array( 129 'type' => PARAM_RAW 130 ), 131 'timemodifiedformatted' => array( 132 'type' => PARAM_RAW 133 ), 134 'url' => array( 135 'type' => PARAM_URL 136 ), 137 ); 138 } 139 140 protected function get_other_values(renderer_base $output) { 141 $filename = $this->file->get_filename(); 142 $filenameshort = $filename; 143 if (core_text::strlen($filename) > 25) { 144 $filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..'); 145 $filenameshort .= substr($filename, -4); 146 } 147 148 $icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file); 149 $iconurl = $output->pix_url($icon, 'core'); 150 151 $url = moodle_url::make_pluginfile_url( 152 $this->file->get_contextid(), 153 $this->file->get_component(), 154 $this->file->get_filearea(), 155 $this->file->get_itemid(), 156 $this->file->get_filepath(), 157 $this->file->get_filename(), 158 true 159 ); 160 161 return array( 162 'filenameshort' => $filenameshort, 163 'filesizeformatted' => display_size((int) $this->file->get_filesize()), 164 'icon' => $icon, 165 'iconurl' => $iconurl->out(false), 166 'url' => $url->out(false), 167 'timecreatedformatted' => userdate($this->file->get_timecreated()), 168 'timemodifiedformatted' => userdate($this->file->get_timemodified()), 169 ); 170 } 171 172 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |