Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/backup/util/ui/base_ui.class.php

    r136 r1331  
    11<?php
    2 
    32// This file is part of Moodle - http://moodle.org/
    43//
     
    1918 * This file contains the backup user interface class
    2019 *
    21  * @package   moodlecore
     20 * @package   core_backup
    2221 * @copyright 2010 Sam Hemelryk
    2322 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     
    3029 * Moodle.
    3130 *
     31 * @package   core_backup
    3232 * @copyright 2010 Sam Hemelryk
    3333 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     
    3636    /**
    3737     * The progress of this instance of the backup ui class
     38     * It is in the initial stage.
    3839     */
    3940    const PROGRESS_INTIAL = 0;
     41
     42    /**
     43     * The progress of this instance of the backup ui class
     44     * It is processed.
     45     */
    4046    const PROGRESS_PROCESSED = 1;
     47
     48    /**
     49     * The progress of this instance of the backup ui class
     50     * It is saved.
     51     */
    4152    const PROGRESS_SAVED = 2;
     53
     54    /**
     55     * The progress of this instance of the backup ui class
     56     * It has been executed.
     57     */
    4258    const PROGRESS_EXECUTED = 3;
     59
    4360    /**
    4461     * The controller
     
    4663     */
    4764    protected $controller;
     65
    4866    /**
    4967     * The current stage
     
    5169     */
    5270    protected $stage;
     71
    5372    /**
    5473     * The current progress of the UI
     
    5675     */
    5776    protected $progress;
     77
    5878    /**
    5979     * The number of changes made by dependency enforcement
     
    6585     * Yay for constructors
    6686     * @param backup_controller $controller
    67      */
    68     public function __construct($controller, array $params=null) {
     87     * @param array $params
     88     */
     89    public function __construct($controller, array $params = null) {
    6990        $this->controller = $controller;
    7091        $this->progress = self::PROGRESS_INTIAL;
    7192        $this->stage = $this->initialise_stage(null, $params);
    72         // Process UI event before to be safe
     93        // Process UI event before to be safe.
    7394        $this->controller->process_ui_event();
    7495    }
     96
    7597    /**
    7698     * Destorys the backup controller and the loaded stage.
     
    84106
    85107    }
     108
    86109    /**
    87110     * Intialises what ever stage is requested. If none are requested we check
     
    89112     *
    90113     * @param int|null $stage The desired stage to intialise or null for the default
     114     * @param array $params
    91115     * @return base_ui_stage
    92116     */
    93     abstract protected function initialise_stage($stage = null, array $params=null);
     117    abstract protected function initialise_stage($stage = null, array $params = null);
     118
    94119    /**
    95120     * This processes the current stage of the backup
     121     * @throws backup_ui_exception
    96122     * @return bool
    97123     */
     
    107133        }
    108134
    109         // Process the stage
     135        // Process the stage.
    110136        $processoutcome = $this->stage->process();
    111137
     
    114140        }
    115141
    116         // Process UI event after to check changes are valid
     142        // Process UI event after to check changes are valid.
    117143        $this->controller->process_ui_event();
    118144        return $processoutcome;
    119145    }
     146
    120147    /**
    121148     * Saves the backup controller.
     
    123150     * Once this has been called nothing else can be changed in the controller.
    124151     *
     152     * @throws base_ui_exception
    125153     * @return bool
    126154     */
     
    130158        }
    131159        $this->progress = self::PROGRESS_SAVED;
    132         // First enforce dependencies
     160        // First enforce dependencies.
    133161        $this->enforce_dependencies();
    134         // Process UI event after to check any changes are valid
     162        // Process UI event after to check any changes are valid.
    135163        $this->controller->process_ui_event();
    136         // Save the controller
     164        // Save the controller.
    137165        $this->controller->save_controller();
    138166        return true;
    139167    }
     168
    140169    /**
    141170     * Displays the UI for the backup!
    142171     *
     172     * @throws base_ui_exception
    143173     * @param core_backup_renderer $renderer
    144174     * @return string HTML code to echo
     
    150180        return $this->stage->display($renderer);
    151181    }
     182
    152183    /**
    153184     * Gets all backup tasks from the controller
     
    159190        return $tasks;
    160191    }
     192
    161193    /**
    162194     * Gets the stage we are on
     
    166198        return $this->stage->get_stage();
    167199    }
     200
    168201    /**
    169202     * Gets the name of the stage we are on
     
    173206        return $this->stage->get_name();
    174207    }
     208
    175209    /**
    176210     * Gets the backup id from the controller
     
    178212     */
    179213    abstract public function get_uniqueid();
     214
    180215    /**
    181216     * Executes the backup plan
     
    183218     */
    184219    abstract public function execute();
     220
    185221    /**
    186222     * Enforces dependencies on all settings. Call before save
     
    188224     */
    189225    protected function enforce_dependencies() {
    190         // Get the plan
     226        // Get the plan.
    191227        $plan = $this->controller->get_plan();
    192         // Get the tasks as a var so we can iterate by reference
     228        // Get the tasks as a var so we can iterate by reference.
    193229        $tasks = $plan->get_tasks();
    194230        $changes = 0;
    195231        foreach ($tasks as &$task) {
    196             // Store as a var so we can iterate by reference
     232            // Store as a var so we can iterate by reference.
    197233            $settings = $task->get_settings();
    198234            foreach ($settings as &$setting) {
    199                 // Get all dependencies for iteration by reference
     235                // Get all dependencies for iteration by reference.
    200236                $dependencies = $setting->get_dependencies();
    201237                foreach ($dependencies as &$dependency) {
    202                     // Enforce each dependency
     238                    // Enforce each dependency.
    203239                    if ($dependency->enforce()) {
    204240                        $changes++;
     
    207243            }
    208244        }
    209         // Store the number of settings that changed through enforcement
     245        // Store the number of settings that changed through enforcement.
    210246        $this->dependencychanges = $changes;
    211         return ($changes>0);
    212     }
     247        return ($changes > 0);
     248    }
     249
    213250    /**
    214251     * Returns true if enforce_dependencies changed any settings
     
    218255        return ($this->dependencychanges > 0);
    219256    }
     257
    220258    /**
    221259     * Loads the backup controller if we are tracking one
     260     * @throws coding_exception
     261     * @param string|bool $uniqueid
    222262     * @return backup_controller|false
    223263     */
    224     public static function load_controller($uniqueid=false) {
     264    public static function load_controller($uniqueid = false) {
    225265        throw new coding_exception('load_controller() method needs to be overridden in each subclass of base_ui');
    226266    }
     
    231271    public function cancel_process() {
    232272        global $PAGE;
    233         // Determine the appropriate URL to redirect the user to
     273        // Determine the appropriate URL to redirect the user to.
    234274        if ($PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->cm !== null) {
    235             $relevanturl = new moodle_url('/mod/'.$PAGE->cm->modname.'/view.php', array('id'=>$PAGE->cm->id));
     275            $relevanturl = new moodle_url('/mod/'.$PAGE->cm->modname.'/view.php', array('id' => $PAGE->cm->id));
    236276        } else {
    237             $relevanturl = new moodle_url('/course/view.php', array('id'=>$PAGE->course->id));
     277            $relevanturl = new moodle_url('/course/view.php', array('id' => $PAGE->course->id));
    238278        }
    239279        redirect($relevanturl);
     
    259299        return $this->controller->get_type();
    260300    }
     301
     302    /**
     303     * Returns the controller object.
     304     * @return backup_controller|restore_controller
     305     */
    261306    public function get_controller() {
    262307        return $this->controller;
     
    272317     * Gets the requested setting
    273318     * @param string $name
     319     * @param bool $default
    274320     * @return mixed
    275321     */
     
    286332     *
    287333     * @param string $name
     334     * @param bool $default
    288335     * @return mixed
    289336     */
     
    297344    }
    298345
     346    /**
     347     * Returns the name of this stage.
     348     * @return mixed
     349     */
    299350    abstract public function get_name();
    300351
     352    /**
     353     * Returns the first stage ID.
     354     * @return mixed
     355     */
    301356    abstract public function get_first_stage_id();
    302357}
     
    304359/**
    305360 * Backup user interface exception. Modelled off the backup_exception class
     361 *
     362 * @package   core_backup
     363 * @copyright 2010 Sam Hemelryk
     364 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    306365 */
    307366class base_ui_exception extends backup_exception {}
Note: See TracChangeset for help on using the changeset viewer.