[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/log/classes/helper/ -> reader.php (source)

   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   * Reader helper trait.
  19   *
  20   * @package    tool_log
  21   * @copyright  2014 onwards Ankit Agarwal
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_log\helper;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Reader helper trait.
  31   * \tool_log\helper\store must be included before using this trait.
  32   *
  33   * @package    tool_log
  34   * @copyright  2014 onwards Ankit Agarwal
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   *
  37   * @property string $component Frankenstyle plugin name initialised in store trait.
  38   * @property string $store short plugin name initialised in store trait.
  39   */
  40  trait reader {
  41      /**
  42       * Default get name api.
  43       *
  44       * @return string name of the store.
  45       */
  46      public function get_name() {
  47          if (get_string_manager()->string_exists('pluginname', $this->component)) {
  48              return get_string('pluginname', $this->component);
  49          }
  50          return $this->store;
  51      }
  52  
  53      /**
  54       * Default get description method.
  55       *
  56       * @return string description of the store.
  57       */
  58      public function get_description() {
  59          if (get_string_manager()->string_exists('pluginname_desc', $this->component)) {
  60              return get_string('pluginname_desc', $this->component);
  61          }
  62          return $this->store;
  63      }
  64  
  65      /**
  66       * Adds ID column to $sort to make sure events from one request
  67       * within 1 second are returned in the same order.
  68       *
  69       * @param string $sort
  70       * @return string sort string
  71       */
  72      protected static function tweak_sort_by_id($sort) {
  73          if (empty($sort)) {
  74              // Mysql does this - unlikely to be used in real life because $sort is always expected.
  75              $sort = "id ASC";
  76          } else if (stripos($sort, 'timecreated') === false) {
  77              $sort .= ", id ASC";
  78          } else if (stripos($sort, 'timecreated DESC') !== false) {
  79              $sort .= ", id DESC";
  80          } else {
  81              $sort .= ", id ASC";
  82          }
  83  
  84          return $sort;
  85      }
  86  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1