Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 402 and 403]

   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_admin\reportbuilder\datasource;
  20  
  21  use core_admin\reportbuilder\local\entities\task_log;
  22  use core_reportbuilder\datasource;
  23  use core_reportbuilder\local\entities\user;
  24  use core_reportbuilder\local\filters\select;
  25  
  26  /**
  27   * Task logs datasource
  28   *
  29   * @package     core_admin
  30   * @copyright   2022 Paul Holden <paulh@moodle.com>
  31   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class task_logs extends datasource {
  34  
  35      /**
  36       * Return user friendly name of the report source
  37       *
  38       * @return string
  39       */
  40      public static function get_name(): string {
  41          return get_string('tasklogs', 'core_admin');
  42      }
  43  
  44      /**
  45       * Initialise report
  46       */
  47      protected function initialise(): void {
  48          $tasklogentity = new task_log();
  49  
  50          $tasklogalias = $tasklogentity->get_table_alias('task_log');
  51          $this->set_main_table('task_log', $tasklogalias);
  52  
  53          $this->add_entity($tasklogentity);
  54  
  55          // Join the user entity to represent the associated user.
  56          $userentity = new user();
  57          $useralias = $userentity->get_table_alias('user');
  58          $this->add_entity($userentity->add_join("
  59              LEFT JOIN {user} {$useralias}
  60                     ON {$useralias}.id = {$tasklogalias}.userid")
  61          );
  62  
  63          // Add report elements from each of the entities we added to the report.
  64          $this->add_all_from_entities();
  65      }
  66  
  67      /**
  68       * Return the columns that will be added to the report upon creation
  69       *
  70       * @return string[]
  71       */
  72      public function get_default_columns(): array {
  73          return [
  74              'task_log:name',
  75              'task_log:starttime',
  76              'task_log:duration',
  77              'task_log:result',
  78          ];
  79      }
  80  
  81      /**
  82       * Return the filters that will be added to the report upon creation
  83       *
  84       * @return string[]
  85       */
  86      public function get_default_filters(): array {
  87          return [
  88              'task_log:timestart',
  89              'task_log:result',
  90          ];
  91      }
  92  
  93      /**
  94       * Return the conditions that will be added to the report upon creation
  95       *
  96       * @return string[]
  97       */
  98      public function get_default_conditions(): array {
  99          return [
 100              'task_log:type',
 101              'task_log:timestart',
 102              'task_log:result',
 103          ];
 104      }
 105  
 106      /**
 107       * Return the condition values that will be set for the report upon creation
 108       *
 109       * @return array
 110       */
 111      public function get_default_condition_values(): array {
 112          return [
 113              'task_log:type_operator' => select::EQUAL_TO,
 114              'task_log:type_value' => \core\task\database_logger::TYPE_SCHEDULED,
 115          ];
 116      }
 117  }