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 user_evidence 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 defined('MOODLE_INTERNAL') || die(); 26 27 use moodle_url; 28 use renderer_base; 29 use core_competency\external\performance_helper; 30 use core_files\external\stored_file_exporter; 31 32 /** 33 * Class for exporting user_evidence data. 34 * 35 * @package core_competency 36 * @copyright 2015 Frédéric Massart - FMCorz.net 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class user_evidence_exporter extends \core\external\persistent_exporter { 40 41 protected static function define_class() { 42 return \core_competency\user_evidence::class; 43 } 44 45 protected static function define_other_properties() { 46 return array( 47 'canmanage' => array( 48 'type' => PARAM_BOOL 49 ), 50 'competencycount' => array( 51 'type' => PARAM_INT 52 ), 53 'competencies' => array( 54 'type' => competency_exporter::read_properties_definition(), 55 'multiple' => true 56 ), 57 'filecount' => array( 58 'type' => PARAM_INT 59 ), 60 'files' => array( 61 'type' => stored_file_exporter::read_properties_definition(), 62 'multiple' => true 63 ), 64 'hasurlorfiles' => array( 65 'type' => PARAM_BOOL 66 ), 67 'urlshort' => array( 68 'type' => PARAM_TEXT 69 ), 70 ); 71 } 72 73 protected static function define_related() { 74 return array( 75 'context' => 'context', 76 'competencies' => 'core_competency\\competency[]' 77 ); 78 } 79 80 protected function get_other_values(renderer_base $output) { 81 $helper = new performance_helper(); 82 83 $competencies = array(); 84 foreach ($this->related['competencies'] as $competency) { 85 $context = $helper->get_context_from_competency($competency); 86 $compexporter = new competency_exporter($competency, array('context' => $context)); 87 $competencies[] = $compexporter->export($output); 88 } 89 90 $urlshort = ''; 91 $url = $this->persistent->get('url'); 92 if (!empty($url)) { 93 $murl = new moodle_url($url); 94 $shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false)); 95 $urlshort = shorten_text($shorturl, 30, true); 96 } 97 98 $files = array(); 99 $storedfiles = $this->persistent->get_files(); 100 if (!empty($storedfiles)) { 101 foreach ($storedfiles as $storedfile) { 102 $fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context'])); 103 $files[] = $fileexporter->export($output); 104 } 105 } 106 107 $values = array( 108 'canmanage' => $this->persistent->can_manage(), 109 'competencycount' => count($competencies), 110 'competencies' => $competencies, 111 'filecount' => count($files), 112 'files' => $files, 113 'hasurlorfiles' => !empty($files) || !empty($url), 114 'urlshort' => $urlshort 115 ); 116 117 return $values; 118 } 119 120 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body