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 format_theunittest\courseformat;
  18  
  19  use core_courseformat\stateupdates;
  20  use core_courseformat\stateactions as core_actions;
  21  use stdClass;
  22  
  23  /**
  24   * Fixture for fake course stateactions testing.
  25   *
  26   * @package    core_course
  27   * @copyright  2021 Sara Arjona (sara@moodle.com)
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class stateactions extends core_actions {
  31  
  32      /**
  33       * Alternative cm_state state action for testing.
  34       *
  35       * @param stateupdates $updates the affected course elements track
  36       * @param stdClass $course the course object
  37       * @param int[] $ids the list of affected course module ids
  38       * @param int $targetsectionid optional target section id
  39       * @param int $targetcmid optional target cm id
  40       */
  41      public function cm_state(
  42          stateupdates $updates,
  43          stdClass $course,
  44          array $ids,
  45          ?int $targetsectionid = null,
  46          ?int $targetcmid = null
  47      ): void {
  48          $updates->add_cm_create(array_pop($ids));
  49      }
  50  
  51      /**
  52       * Course format custom state action.
  53       *
  54       * @param stateupdates $updates the affected course elements track
  55       * @param stdClass $course the course object
  56       * @param int[] $ids the list of affected course module ids
  57       * @param int $targetsectionid optional target section id
  58       * @param int $targetcmid optional target cm id
  59       */
  60      public function format_do_something(
  61          stateupdates $updates,
  62          stdClass $course,
  63          array $ids,
  64          ?int $targetsectionid = null,
  65          ?int $targetcmid = null
  66      ): void {
  67  
  68          $updates->add_cm_remove(array_pop($ids));
  69      }
  70  
  71      /**
  72       * Course format target section testing action.
  73       *
  74       * @param stateupdates $updates the affected course elements track
  75       * @param stdClass $course the course object
  76       * @param int[] $ids the list of affected course module ids
  77       * @param int $targetsectionid optional target section id
  78       * @param int $targetcmid optional target cm id
  79       */
  80      public function targetsection_test(
  81          stateupdates $updates,
  82          stdClass $course,
  83          array $ids,
  84          ?int $targetsectionid = null,
  85          ?int $targetcmid = null
  86      ): void {
  87  
  88          $updates->add_section_put($targetsectionid);
  89      }
  90  
  91      /**
  92       * Course format target cm testing action.
  93       *
  94       * @param stateupdates $updates the affected course elements track
  95       * @param stdClass $course the course object
  96       * @param int[] $ids the list of affected course module ids
  97       * @param int $targetsectionid optional target section id
  98       * @param int $targetcmid optional target cm id
  99       */
 100      public function targetcm_test(
 101          stateupdates $updates,
 102          stdClass $course,
 103          array $ids,
 104          ?int $targetsectionid = null,
 105          ?int $targetcmid = null
 106      ): void {
 107  
 108          $updates->add_cm_put($targetcmid);
 109      }
 110  
 111  }