Merge branch 'wip-MDL-52039-master' of https://github.com/marinaglancy/moodle
[moodle.git] / blocks / tags / block_tags.php
CommitLineData
4ca6cfbf 1<?php
7dd764b8
JG
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
f25a6839
SH
17/**
18 * Tags block.
19 *
20 * @package block_tags
21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
d797e50f 24
25class block_tags extends block_base {
7dd764b8 26 public function init() {
8d4904be 27 $this->title = get_string('pluginname', 'block_tags');
d797e50f 28 }
29
7dd764b8 30 public function instance_allow_multiple() {
d797e50f 31 return true;
32 }
33
7dd764b8 34 public function has_config() {
38fb8190 35 return true;
d797e50f 36 }
37
7dd764b8 38 public function applicable_formats() {
cdcaa9f2 39 return array('all' => true);
d797e50f 40 }
41
7dd764b8 42 public function instance_allow_config() {
d797e50f 43 return true;
44 }
45
7dd764b8 46 public function specialization() {
d797e50f 47
7dd764b8 48 // Load userdefined title and make sure it's never empty.
d797e50f 49 if (empty($this->config->title)) {
7dd764b8 50 $this->title = get_string('pluginname', 'block_tags');
d797e50f 51 } else {
52 $this->title = $this->config->title;
53 }
54 }
55
7dd764b8 56 public function get_content() {
d797e50f 57
7dd764b8 58 global $CFG, $COURSE, $USER, $SCRIPT, $OUTPUT;
d797e50f 59
60 if (empty($CFG->usetags)) {
7c2cc9c8 61 $this->content = new stdClass();
d797e50f 62 $this->content->text = '';
b58961ac 63 if ($this->page->user_is_editing()) {
64 $this->content->text = get_string('disabledtags', 'block_tags');
65 }
d797e50f 66 return $this->content;
67 }
68
b85b25eb
PS
69 if (!isset($this->config)) {
70 $this->config = new stdClass();
71 }
72
d797e50f 73 if (empty($this->config->numberoftags)) {
74 $this->config->numberoftags = 80;
75 }
76
77 if ($this->content !== NULL) {
78 return $this->content;
79 }
80
81 if (empty($this->instance)) {
82 $this->content = '';
83 return $this->content;
84 }
85
86 $this->content = new stdClass;
c891a73d 87 $this->content->text = '';
d797e50f 88 $this->content->footer = '';
89
7dd764b8 90 // Get a list of tags.
d797e50f 91
7b2b1a91 92 require_once($CFG->dirroot.'/tag/locallib.php');
d797e50f 93
0d1e5456 94 $this->content->text = tag_print_cloud(null, $this->config->numberoftags, true);
d797e50f 95
96 return $this->content;
97 }
d0dff189 98}