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  namespace tool_brickfield\local\tool;
  18  
  19  use tool_brickfield\sitedata;
  20  
  21  /**
  22   * Class activityresults.
  23   *
  24   * @package tool_brickfield
  25   * @copyright  2020 onward: Brickfield Education Labs, www.brickfield.ie
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class activityresults extends tool {
  29  
  30      /**
  31       * Provide a name for this tool, suitable for display on pages.
  32       * @return mixed|string
  33       * @throws \coding_exception
  34       */
  35      public static function toolname(): string {
  36          return get_string('activityresults:toolname', 'tool_brickfield');
  37      }
  38  
  39      /**
  40       * Provide a short name for this tool, suitable for menus and selectors.
  41       * @return mixed|string
  42       * @throws \coding_exception
  43       */
  44      public static function toolshortname(): string {
  45          return get_string('activityresults:toolshortname', 'tool_brickfield');
  46      }
  47  
  48      /**
  49       * Provide a lowercase name identifying this plugin. Should really be the same as the directory name.
  50       * @return string
  51       */
  52      public function pluginname(): string {
  53          return 'activityresults';
  54      }
  55  
  56      /**
  57       * Return the data for renderer / template display.
  58       * @return \stdClass
  59       * @throws \coding_exception
  60       * @throws \dml_exception
  61       */
  62      protected function fetch_data(): \stdClass {
  63          $filter = $this->get_filter();
  64          if (!$filter->validate_filters()) {
  65              return (object)[
  66                  'valid' => false,
  67                  'error' => $filter->get_errormessage(),
  68              ];
  69          }
  70  
  71          $data = (object)[
  72              'valid' => true,
  73              'error' => '',
  74              'data' => (new sitedata())->get_component_data($filter),
  75          ];
  76  
  77          if ($filter->categoryid != 0) {
  78              $data->countdata = count($filter->courseids);
  79          } else {
  80              $data->countdata = sitedata::get_total_courses_checked();
  81          }
  82  
  83          return $data;
  84      }
  85  }