Search moodle.org's
Developer Documentation

See Release Notes

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

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 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  /**
  18   * Representation of a suggested bulk action.
  19   *
  20   * @package   core_analytics
  21   * @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_analytics;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Representation of a suggested bulk action.
  31   *
  32   * @package   core_analytics
  33   * @copyright 2019 David Monllao {@link http://www.davidmonllao.com}
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class bulk_action extends action {
  37  
  38      /**
  39       * Prediction action constructor.
  40       *
  41       * @param string $actionname They should match a-zA-Z_0-9-, as we apply a PARAM_ALPHANUMEXT filter
  42       * @param \moodle_url $actionurl The final URL where the user should be forwarded.
  43       * @param \pix_icon $icon Link icon
  44       * @param string $text Link text
  45       * @param bool $primary Primary button or secondary.
  46       * @param array $attributes Link attributes
  47       * @param string|false $type
  48       * @return void
  49       */
  50      public function __construct($actionname, \moodle_url $actionurl, \pix_icon $icon,
  51                                  $text, $primary = false, $attributes = array(), $type = false) {
  52          global $OUTPUT;
  53  
  54          $this->actionname = $actionname;
  55          $this->text = $text;
  56          $this->set_type($type);
  57  
  58          // We want to track how effective are our suggested actions, we pass users through a script that will log these actions.
  59          $params = array('action' => $this->actionname, 'forwardurl' => $actionurl->out(false));
  60          $this->url = new \moodle_url('/report/insights/action.php', $params);
  61  
  62          $label = $OUTPUT->render($icon) . $this->text;
  63          $this->actionlink = new \single_button($this->url, $label,
  64              'get',
  65              $primary ? \single_button::BUTTON_PRIMARY : \single_button::BUTTON_SECONDARY,
  66              $attributes);
  67      }
  68  }