1 |
efrain |
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\tagcollname
|
|
|
19 |
*
|
|
|
20 |
* @package core_tag
|
|
|
21 |
* @copyright 2016 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 context_system;
|
|
|
28 |
use lang_string;
|
|
|
29 |
use html_writer;
|
|
|
30 |
use core_tag_collection;
|
|
|
31 |
use moodle_url;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Class to preapare a tag name for display.
|
|
|
35 |
*
|
|
|
36 |
* @package core_tag
|
|
|
37 |
* @copyright 2016 Marina Glancy
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*/
|
|
|
40 |
class tagcollname extends \core\output\inplace_editable {
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Constructor.
|
|
|
44 |
*
|
|
|
45 |
* @param \stdClass $tagcoll
|
|
|
46 |
*/
|
|
|
47 |
public function __construct($tagcoll) {
|
|
|
48 |
$editable = has_capability('moodle/tag:manage', context_system::instance());
|
|
|
49 |
$edithint = new lang_string('editcollname', 'core_tag');
|
|
|
50 |
$value = $tagcoll->name;
|
|
|
51 |
$name = \core_tag_collection::display_name($tagcoll);
|
|
|
52 |
$editlabel = new lang_string('newcollnamefor', 'core_tag', $name);
|
|
|
53 |
$manageurl = new moodle_url('/tag/manage.php', array('tc' => $tagcoll->id));
|
|
|
54 |
$displayvalue = html_writer::link($manageurl, $name);
|
|
|
55 |
parent::__construct('core_tag', 'tagcollname', $tagcoll->id, $editable, $displayvalue, $value, $edithint, $editlabel);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Updates the value in database and returns itself, called from inplace_editable callback
|
|
|
60 |
*
|
|
|
61 |
* @param int $itemid
|
|
|
62 |
* @param mixed $newvalue
|
|
|
63 |
* @return \self
|
|
|
64 |
*/
|
|
|
65 |
public static function update($itemid, $newvalue) {
|
|
|
66 |
global $DB;
|
|
|
67 |
require_capability('moodle/tag:manage', context_system::instance());
|
|
|
68 |
$tagcoll = $DB->get_record('tag_coll', array('id' => $itemid), '*', MUST_EXIST);
|
|
|
69 |
\core_tag_collection::update($tagcoll, array('name' => $newvalue));
|
|
|
70 |
return new self($tagcoll);
|
|
|
71 |
}
|
|
|
72 |
}
|