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.
   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 core_admin\table;
  18  
  19  use core_plugin_manager;
  20  use dml_exception;
  21  use html_writer;
  22  use moodle_url;
  23  use stdClass;
  24  
  25  /**
  26   * Activity Module admin settings.
  27   *
  28   * @package core_admin
  29   * @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
  30   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class activity_management_table extends plugin_management_table {
  33  
  34      public function setup() {
  35          $this->set_attribute('id', 'modules');
  36          $this->set_attribute('class', 'admintable generaltable');
  37          parent::setup();
  38      }
  39  
  40      protected function get_table_id(): string {
  41          return 'module-administration-table';
  42      }
  43  
  44      protected function get_plugintype(): string {
  45          return 'mod';
  46      }
  47  
  48      public function guess_base_url(): void {
  49          $this->define_baseurl(
  50              new moodle_url('/admin/modules.php')
  51          );
  52      }
  53  
  54      protected function get_action_url(array $params = []): moodle_url {
  55          return new moodle_url('/admin/modules.php', $params);
  56      }
  57  
  58      protected function get_column_list(): array {
  59          $columns = parent::get_column_list();
  60          return array_merge(
  61              array_slice($columns, 0, 1, true),
  62              ['activities' => get_string('activities')],
  63              array_slice($columns, 1, null, true),
  64          );
  65      }
  66  
  67      protected function col_name(stdClass $row): string {
  68          global $OUTPUT;
  69  
  70          $status = $row->plugininfo->get_status();
  71          if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
  72              return html_writer::span(
  73                  get_string('pluginmissingfromdisk', 'core', $row->plugininfo),
  74                  'notifyproblem'
  75              );
  76          }
  77  
  78          return html_writer::span(
  79              html_writer::img(
  80                  $OUTPUT->image_url('monologo', $row->plugininfo->name),
  81                  '',
  82                  [
  83                      'class' => 'icon',
  84                  ],
  85              ) . get_string('modulename', $row->plugininfo->name)
  86          );
  87      }
  88  
  89      /**
  90       * Show the number of activities present, with a link to courses containing activity if relevant.
  91       *
  92       * @param mixed $row
  93       * @return string
  94       */
  95      protected function col_activities(stdClass $row): string {
  96          global $DB, $OUTPUT;
  97          try {
  98              $count = $DB->count_records_select($row->plugininfo->name, "course <> 0");
  99          } catch (dml_exception $e) {
 100              $count = -1;
 101          }
 102  
 103          if ($count > 0) {
 104              return $OUTPUT->action_link(
 105                  new moodle_url('/course/search.php', [
 106                      'modulelist' => $row->plugininfo->name,
 107                  ]),
 108                  $count,
 109                  null,
 110                  ['title' => get_string('showmodulecourse')]
 111              );
 112          } else if ($count < 0) {
 113              return get_string('error');
 114          } else {
 115              return $count;
 116          }
 117      }
 118  }