Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\tagcollsearchable
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 core_tag_collection;
30
 
31
/**
32
 * Class to display tag collection searchable control
33
 *
34
 * @package   core_tag
35
 * @copyright 2016 Marina Glancy
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class tagcollsearchable extends \core\output\inplace_editable {
39
 
40
    /**
41
     * Constructor.
42
     *
43
     * @param \stdClass $tagcoll
44
     */
45
    public function __construct($tagcoll) {
1441 ariadna 46
        $editable = has_capability('moodle/tag:manage', context_system::instance());
1 efrain 47
        $edithint = new lang_string('editsearchable', 'core_tag');
48
        $value = $tagcoll->searchable ? 1 : 0;
49
 
50
        parent::__construct('core_tag', 'tagcollsearchable', $tagcoll->id, $editable, $value, $value, $edithint);
51
        $this->set_type_toggle();
52
    }
53
 
54
    /**
55
     * Export this data so it can be used as the context for a mustache template.
56
     *
57
     * @param \renderer_base $output
58
     * @return \stdClass
59
     */
60
    public function export_for_template(\renderer_base $output) {
61
        if ($this->value) {
62
            $this->displayvalue = $output->pix_icon('i/checked', get_string('yes'));
63
        } else {
64
            $this->displayvalue = $output->pix_icon('i/unchecked', get_string('no'));
65
        }
66
 
67
        return parent::export_for_template($output);
68
    }
69
 
70
    /**
71
     * Updates the value in database and returns itself, called from inplace_editable callback
72
     *
73
     * @param int $itemid
74
     * @param mixed $newvalue
75
     * @return \self
76
     */
77
    public static function update($itemid, $newvalue) {
78
        global $DB;
79
        require_capability('moodle/tag:manage', context_system::instance());
80
        $tagcoll = $DB->get_record('tag_coll', array('id' => $itemid), '*', MUST_EXIST);
81
        core_tag_collection::update($tagcoll, array('searchable' => $newvalue));
82
        return new self($tagcoll);
83
    }
84
}