[ 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 * Contains class core_tag\output\taglist 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 templatable; 28 use renderer_base; 29 use stdClass; 30 use core_tag_tag; 31 use context; 32 33 /** 34 * Class to preapare a list of tags for display, usually the list of tags some entry is tagged with. 35 * 36 * @package core_tag 37 * @copyright 2015 Marina Glancy 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class taglist implements templatable { 41 42 /** @var array */ 43 protected $tags; 44 45 /** @var string */ 46 protected $label; 47 48 /** @var string */ 49 protected $classes; 50 51 /** @var int */ 52 protected $limit; 53 54 /** 55 * Constructor 56 * 57 * @param array $tags list of instances of \core_tag_tag or \stdClass 58 * @param string $label label to display in front, by default 'Tags' (get_string('tags')), set to null 59 * to use default, set to '' (empty string) to omit the label completely 60 * @param string $classes additional classes for the enclosing div element 61 * @param int $limit limit the number of tags to display, if size of $tags is more than this limit the "more" link 62 * will be appended to the end, JS will toggle the rest of the tags 63 * @param context $pagecontext specify if needed to overwrite the current page context for the view tag link 64 */ 65 public function __construct($tags, $label = null, $classes = '', $limit = 10, $pagecontext = null) { 66 global $PAGE; 67 $canmanagetags = has_capability('moodle/tag:manage', \context_system::instance()); 68 69 $this->label = ($label === null) ? get_string('tags') : $label; 70 $this->classes = $classes; 71 $fromctx = $pagecontext ? $pagecontext->id : 72 (($PAGE->context->contextlevel == CONTEXT_SYSTEM) ? 0 : $PAGE->context->id); 73 74 $this->tags = array(); 75 foreach ($tags as $idx => $tag) { 76 $this->tags[$idx] = new stdClass(); 77 78 $this->tags[$idx]->name = core_tag_tag::make_display_name($tag, false); 79 80 if ($canmanagetags && !empty($tag->flag)) { 81 $this->tags[$idx]->flag = 1; 82 } 83 84 $viewurl = core_tag_tag::make_url($tag->tagcollid, $tag->rawname, 0, $fromctx); 85 $this->tags[$idx]->viewurl = $viewurl->out(false); 86 87 if (isset($tag->isstandard)) { 88 $this->tags[$idx]->isstandard = $tag->isstandard ? 1 : 0; 89 } 90 91 if ($limit && count($this->tags) > $limit) { 92 $this->tags[$idx]->overlimit = 1; 93 } 94 } 95 $this->limit = $limit; 96 } 97 98 /** 99 * Export this data so it can be used as the context for a mustache template. 100 * 101 * @param renderer_base $output 102 * @return stdClass 103 */ 104 public function export_for_template(renderer_base $output) { 105 $cnt = count($this->tags); 106 return (object)array( 107 'tags' => array_values($this->tags), 108 'label' => $this->label, 109 'tagscount' => $cnt, 110 'overflow' => ($this->limit && $cnt > $this->limit) ? 1 : 0, 111 'classes' => $this->classes, 112 ); 113 } 114 }
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 |