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  /**
  18   * No accesses since the start of the course.
  19   *
  20   * @package   core_course
  21   * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_course\analytics\target;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * No accesses since the start of the course.
  31   *
  32   * @package   core_course
  33   * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com}
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class no_access_since_course_start extends no_recent_accesses {
  37  
  38      /**
  39       * Only past stuff whose start matches the course start.
  40       *
  41       * @param  \core_analytics\local\time_splitting\base $timesplitting
  42       * @return bool
  43       */
  44      public function can_use_timesplitting(\core_analytics\local\time_splitting\base $timesplitting): bool {
  45          return ($timesplitting instanceof \core_analytics\local\time_splitting\after_start);
  46      }
  47  
  48      /**
  49       * Returns the name.
  50       *
  51       * If there is a corresponding '_help' string this will be shown as well.
  52       *
  53       * @return \lang_string
  54       */
  55      public static function get_name() : \lang_string {
  56          return new \lang_string('target:noaccesssincecoursestart', 'course');
  57      }
  58  
  59      /**
  60       * Returns the body message for the insight.
  61       *
  62       * @param  \context     $context
  63       * @param  string       $contextname
  64       * @param  \stdClass    $user
  65       * @param  \moodle_url  $insighturl
  66       * @return array                        The plain text message and the HTML message
  67       */
  68      public function get_insight_body(\context $context, string $contextname, \stdClass $user, \moodle_url $insighturl): array {
  69          global $OUTPUT;
  70  
  71          $a = (object)['coursename' => $contextname, 'userfirstname' => $user->firstname];
  72          $fullmessage = get_string('noaccesssincestartinfomessage', 'course', $a) . PHP_EOL . PHP_EOL . $insighturl->out(false);
  73          $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message',
  74              ['url' => $insighturl->out(false), 'insightinfomessage' => get_string('noaccesssincestartinfomessage', 'course', $a)]
  75          );
  76  
  77          return [$fullmessage, $fullmessagehtml];
  78      }
  79  
  80  }