Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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   * Define all the backup steps that will be used by the backup_block_task
  19   * @package    block_activity_results
  20   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @copyright  2015 Stephen Bourget
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Specialised restore task for the activity_results block
  29   * (using execute_after_tasks for recoding of target activity)
  30   *
  31   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class restore_activity_results_block_task extends restore_block_task {
  35  
  36      /**
  37       * Define (add) particular settings this activity can have
  38       */
  39      protected function define_my_settings() {
  40      }
  41  
  42      /**
  43       * Define (add) particular steps this activity can have
  44       */
  45      protected function define_my_steps() {
  46      }
  47  
  48      /**
  49       * Define the associated file areas
  50       */
  51      public function get_fileareas() {
  52          return array(); // No associated fileareas.
  53      }
  54  
  55      /**
  56       * Define special handling of configdata.
  57       */
  58      public function get_configdata_encoded_attributes() {
  59          return array(); // No special handling of configdata.
  60      }
  61  
  62      /**
  63       * This function, executed after all the tasks in the plan
  64       * have been executed, will perform the recode of the
  65       * target activity for the block. This must be done here
  66       * and not in normal execution steps because the activity
  67       * can be restored after the block.
  68       */
  69      public function after_restore() {
  70          global $DB;
  71  
  72          // Get the blockid.
  73          $blockid = $this->get_blockid();
  74  
  75          if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
  76              $config = $this->decode_configdata($configdata);
  77              if (!empty($config->activityparentid)) {
  78                  // Get the mapping and replace it in config.
  79                  if ($mapping = restore_dbops::get_backup_ids_record($this->get_restoreid(),
  80                      $config->activityparent, $config->activityparentid)) {
  81  
  82                      // Update the parent module id (the id from mdl_quiz etc...)
  83                      $config->activityparentid = $mapping->newitemid;
  84  
  85                      // Get the grade_items record to update the activitygradeitemid.
  86                      $info = $DB->get_record('grade_items',
  87                              array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
  88  
  89                      // Update the activitygradeitemid the id from the grade_items table.
  90                      $config->activitygradeitemid = $info->id;
  91  
  92                      // Encode and save the config.
  93                      $configdata = base64_encode(serialize($config));
  94                      $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
  95                  }
  96              }
  97          }
  98      }
  99  
 100      /**
 101       * Define the contents in the activity that must be
 102       * processed by the link decoder
 103       */
 104      static public function define_decode_contents() {
 105          return array();
 106      }
 107  
 108      /**
 109       * Define the decoding rules for links belonging
 110       * to the activity to be executed by the link decoder
 111       */
 112      static public function define_decode_rules() {
 113          return array();
 114      }
 115  }