Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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\tagareashowstandard
  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_tag;
  30  use core_tag_area;
  31  
  32  /**
  33   * Class to display tag area show standard control
  34   *
  35   * @package   core_tag
  36   * @copyright 2016 Marina Glancy
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class tagareashowstandard extends \core\output\inplace_editable {
  40  
  41      /**
  42       * Constructor.
  43       *
  44       * @param \stdClass $tagarea
  45       */
  46      public function __construct($tagarea) {
  47          $editable = has_capability('moodle/tag:manage', context_system::instance());
  48          $edithint = new lang_string('editisstandard', 'core_tag');
  49          $value = $tagarea->showstandard;
  50          $areaname = core_tag_area::display_name($tagarea->component, $tagarea->itemtype);
  51          $editlabel = new lang_string('changeshowstandard', 'core_tag', $areaname);
  52  
  53          parent::__construct('core_tag', 'tagareashowstandard', $tagarea->id, $editable,
  54                  null, $value, $edithint, $editlabel);
  55  
  56          $standardchoices = array(
  57              core_tag_tag::BOTH_STANDARD_AND_NOT => get_string('standardsuggest', 'tag'),
  58              core_tag_tag::STANDARD_ONLY => get_string('standardforce', 'tag'),
  59              core_tag_tag::HIDE_STANDARD => get_string('standardhide', 'tag')
  60          );
  61          $this->set_type_select($standardchoices);
  62      }
  63  
  64      /**
  65       * Updates the value in database and returns itself, called from inplace_editable callback
  66       *
  67       * @param int $itemid
  68       * @param mixed $newvalue
  69       * @return \self
  70       */
  71      public static function update($itemid, $newvalue) {
  72          global $DB;
  73          require_capability('moodle/tag:manage', context_system::instance());
  74          $tagarea = $DB->get_record('tag_area', array('id' => $itemid), '*', MUST_EXIST);
  75          $newvalue = clean_param($newvalue, PARAM_INT);
  76          $data = array('showstandard' => $newvalue);
  77          core_tag_area::update($tagarea, $data);
  78          $tagarea->showstandard = $newvalue;
  79          $tmpl = new self($tagarea);
  80          return $tmpl;
  81      }
  82  }