Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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) {
  46          $defaultid = core_tag_collection::get_default();
  47          $editable = $tagcoll->id != $defaultid &&
  48                  has_capability('moodle/tag:manage', context_system::instance());
  49          $edithint = new lang_string('editsearchable', 'core_tag');
  50          $value = $tagcoll->searchable ? 1 : 0;
  51  
  52          parent::__construct('core_tag', 'tagcollsearchable', $tagcoll->id, $editable, $value, $value, $edithint);
  53          $this->set_type_toggle();
  54      }
  55  
  56      /**
  57       * Export this data so it can be used as the context for a mustache template.
  58       *
  59       * @param \renderer_base $output
  60       * @return \stdClass
  61       */
  62      public function export_for_template(\renderer_base $output) {
  63          if ($this->value) {
  64              $this->displayvalue = $output->pix_icon('i/checked', get_string('yes'));
  65          } else {
  66              $this->displayvalue = $output->pix_icon('i/unchecked', get_string('no'));
  67          }
  68  
  69          return parent::export_for_template($output);
  70      }
  71  
  72      /**
  73       * Updates the value in database and returns itself, called from inplace_editable callback
  74       *
  75       * @param int $itemid
  76       * @param mixed $newvalue
  77       * @return \self
  78       */
  79      public static function update($itemid, $newvalue) {
  80          global $DB;
  81          require_capability('moodle/tag:manage', context_system::instance());
  82          $tagcoll = $DB->get_record('tag_coll', array('id' => $itemid), '*', MUST_EXIST);
  83          core_tag_collection::update($tagcoll, array('searchable' => $newvalue));
  84          return new self($tagcoll);
  85      }
  86  }