Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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  declare(strict_types=1);
  18  
  19  namespace core_reportbuilder;
  20  
  21  use core_reportbuilder\local\report\action;
  22  use lang_string;
  23  use core_reportbuilder\local\filters\text;
  24  use core_reportbuilder\local\report\column;
  25  use core_reportbuilder\local\report\filter;
  26  use moodle_url;
  27  use pix_icon;
  28  
  29  /**
  30   * Testable system report fixture
  31   *
  32   * @package     core_reportbuilder
  33   * @copyright   2020 Paul Holden <paulh@moodle.com>
  34   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class system_report_available extends system_report {
  37  
  38      /**
  39       * Initialise the report
  40       */
  41      protected function initialise(): void {
  42          $this->set_main_table('user', 'u');
  43          $this->annotate_entity('user', new lang_string('user'));
  44  
  45          $this->add_column((new column(
  46              'username',
  47              new lang_string('username'),
  48              'user'
  49          ))
  50              ->add_joins($this->get_joins())
  51              ->add_field('u.firstname')
  52          );
  53  
  54          $withfilters = $this->get_parameter('withfilters', false, PARAM_BOOL);
  55          if ($withfilters) {
  56              $this->add_filter((new filter(
  57                  text::class,
  58                  'username',
  59                  new lang_string('username'),
  60                  'user',
  61                  'u.username'
  62              ))
  63                  ->add_joins($this->get_joins())
  64              );
  65          }
  66  
  67          $withactions = $this->get_parameter('withactions', false, PARAM_BOOL);
  68          if ($withactions) {
  69              $this->add_action(new action(
  70                  new moodle_url('/user/profile.php', ['id' => ':id']),
  71                  new pix_icon('e/search', get_string('view')),
  72                  [],
  73                  true,
  74              ));
  75          }
  76      }
  77  
  78      /**
  79       * Ensure we can view the report
  80       *
  81       * @return bool
  82       */
  83      protected function can_view(): bool {
  84          return true;
  85      }
  86  
  87      /**
  88       * Explicitly set availability of report
  89       *
  90       * @return bool
  91       */
  92      public static function is_available(): bool {
  93          return true;
  94      }
  95  }