Differences Between: [Versions 311 and 402] [Versions 311 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 * Contains class core_tag\output\tag 19 * 20 * @package core_tag 21 * @copyright 2015 Marina Glancy 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_tag\output; 26 27 use renderable; 28 use templatable; 29 use renderer_base; 30 use stdClass; 31 use moodle_url; 32 use core_tag_tag; 33 34 /** 35 * Class to help display tag 36 * 37 * @package core_tag 38 * @copyright 2015 Marina Glancy 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class tag implements renderable, templatable { 42 43 /** @var core_tag_tag|stdClass */ 44 protected $record; 45 46 /** 47 * Constructor 48 * 49 * @param core_tag_tag|stdClass $tag 50 */ 51 public function __construct($tag) { 52 if ($tag instanceof core_tag_tag) { 53 $this->record = $tag; 54 return; 55 } 56 $tag = (array)$tag + 57 array( 58 'name' => '', 59 'rawname' => '', 60 'description' => '', 61 'descriptionformat' => FORMAT_HTML, 62 'flag' => 0, 63 'isstandard' => 0, 64 'id' => 0, 65 'tagcollid' => 0, 66 ); 67 $this->record = (object)$tag; 68 } 69 70 /** 71 * Export this data so it can be used as the context for a mustache template. 72 * 73 * @param renderer_base $output 74 * @return stdClass 75 */ 76 public function export_for_template(renderer_base $output) { 77 global $CFG; 78 require_once($CFG->libdir . '/externallib.php'); 79 80 $r = new stdClass(); 81 $r->id = (int)$this->record->id; 82 $r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT); 83 $r->rawname = clean_param($this->record->rawname, PARAM_TAG); 84 $r->name = clean_param($this->record->name, PARAM_TAG); 85 $format = clean_param($this->record->descriptionformat, PARAM_INT); 86 list($r->description, $r->descriptionformat) = external_format_text($this->record->description, 87 $format, \context_system::instance()->id, 'core', 'tag', $r->id); 88 $r->flag = clean_param($this->record->flag, PARAM_INT); 89 if (isset($this->record->isstandard)) { 90 $r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0; 91 } 92 $r->official = $r->isstandard; // For backwards compatibility. 93 94 $url = core_tag_tag::make_url($r->tagcollid, $r->rawname); 95 $r->viewurl = $url->out(false); 96 97 return $r; 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body