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_moodleform.class.php

    r136 r1331  
    11<?php
    2 
    32// This file is part of Moodle - http://moodle.org/
    43//
     
    2120 * interface can exist within.
    2221 *
    23  * @package   moodlecore
     22 * @package   core_backup
    2423 * @copyright 2010 Sam Hemelryk
    2524 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
     
    3130
    3231/**
    33  * Backup moodleform bridge
     32 * Base moodleform bridge
    3433 *
    3534 * Ahhh the mighty moodleform bridge! Strong enough to take the weight of 682 full
     
    3736 * EWWWWW!!!!!!!!!!!!!!!!!!!!!!!!
    3837 *
     38 * @package   core_backup
    3939 * @copyright 2010 Sam Hemelryk
    4040 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    4141 */
    4242abstract class base_moodleform extends moodleform {
     43
    4344    /**
    4445     * The stage this form belongs to
     
    4647     */
    4748    protected $uistage = null;
     49
    4850    /**
    4951     * True if we have a course div open, false otherwise
     
    5153     */
    5254    protected $coursediv = false;
     55
    5356    /**
    5457     * True if we have a section div open, false otherwise
     
    5659     */
    5760    protected $sectiondiv = false;
     61
    5862    /**
    5963     * True if we have an activity div open, false otherwise
     
    6165     */
    6266    protected $activitydiv = false;
     67
    6368    /**
    6469     * Creates the form
    6570     *
    66      * @param backup_ui_stage $uistage
     71     * @param base_ui_stage $uistage
    6772     * @param moodle_url|string $action
    6873     * @param mixed $customdata
     
    7277     * @param bool $editable
    7378     */
    74     function __construct(base_ui_stage $uistage, $action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) {
     79    public function __construct(base_ui_stage $uistage, $action = null, $customdata = null, $method = 'post',
     80                                $target = '', $attributes = null, $editable = true) {
    7581        $this->uistage = $uistage;
    7682        // Add a class to the attributes to prevent the default collapsible behaviour.
     
    8490        parent::__construct($action, $customdata, $method, $target, $attributes, $editable);
    8591    }
     92
    8693    /**
    8794     * The standard form definition... obviously not much here
    8895     */
    89     function definition() {
     96    public function definition() {
    9097        $ui = $this->uistage->get_ui();
    9198        $mform = $this->_form;
     
    97104        $params = $this->uistage->get_params();
    98105        if (is_array($params) && count($params) > 0) {
    99             foreach ($params as $name=>$value) {
     106            foreach ($params as $name => $value) {
    100107                // TODO: Horrible hack, but current backup ui structure does not allow
    101108                // to make this easy (only changing params to objects that would be
     
    119126     * @global moodle_page $PAGE
    120127     */
    121     function definition_after_data() {
    122         $buttonarray=array();
    123         $buttonarray[] = $this->_form->createElement('submit', 'submitbutton', get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'), array('class'=>'proceedbutton'));
     128    public function definition_after_data() {
     129        $buttonarray = array();
     130        $buttonarray[] = $this->_form->createElement(
     131            'submit',
     132            'submitbutton',
     133            get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'),
     134            array('class' => 'proceedbutton')
     135        );
    124136        if (!$this->uistage->is_first_stage()) {
    125             $buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage','backup'));
     137            $buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage', 'backup'));
    126138        } else if ($this->uistage instanceof backup_ui_stage) {
    127139            // Only display the button on the first stage of backup, they only place where it has an effect.
     
    129141                array('class' => 'oneclickbackup'));
    130142        }
    131         $buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class'=>'confirmcancel'));
     143        $buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class' => 'confirmcancel'));
    132144        $this->_form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
    133145        $this->_form->closeHeaderBefore('buttonar');
     
    139151     * Closes any open divs
    140152     */
    141     function close_task_divs() {
     153    public function close_task_divs() {
    142154        if ($this->activitydiv) {
    143155            $this->_form->addElement('html', html_writer::end_tag('div'));
     
    153165        }
    154166    }
     167
    155168    /**
    156169     * Adds the backup_setting as a element to the form
    157170     * @param backup_setting $setting
     171     * @param base_task $task
    158172     * @return bool
    159173     */
    160     function add_setting(backup_setting $setting, base_task $task=null) {
     174    public function add_setting(backup_setting $setting, base_task $task = null) {
    161175        return $this->add_settings(array(array($setting, $task)));
    162176    }
     177
    163178    /**
    164179     * Adds multiple backup_settings as elements to the form
     
    178193            }
    179194
    180             // First add the formatting for this setting
     195            // First add the formatting for this setting.
    181196            $this->add_html_formatting($setting);
    182197
    183             // Then call the add method with the get_element_properties array
     198            // Then call the add method with the get_element_properties array.
    184199            call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
    185200            $this->_form->setType($setting->get_ui_name(), $setting->get_param_validation());
     
    194209        return true;
    195210    }
     211
    196212    /**
    197213     * Adds a heading to the form
     
    199215     * @param string $text
    200216     */
    201     function add_heading($name , $text) {
     217    public function add_heading($name , $text) {
    202218        $this->_form->addElement('header', $name, $text);
    203219    }
     220
    204221    /**
    205222     * Adds HTML formatting for the given backup setting, needed to group/segment
     
    209226    protected function add_html_formatting(backup_setting $setting) {
    210227        $mform = $this->_form;
    211         $isincludesetting = (strpos($setting->get_name(), '_include')!==false);
    212         if ($isincludesetting && $setting->get_level() != backup_setting::ROOT_LEVEL)  {
     228        $isincludesetting = (strpos($setting->get_name(), '_include') !== false);
     229        if ($isincludesetting && $setting->get_level() != backup_setting::ROOT_LEVEL) {
    213230            switch ($setting->get_level()) {
    214231                case backup_setting::COURSE_LEVEL:
     
    224241                        $this->_form->addElement('html', html_writer::end_tag('div'));
    225242                    }
    226                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings course_level')));
    227                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting course_level')));
     243                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings course_level')));
     244                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting course_level')));
    228245                    $this->coursediv = true;
    229246                    break;
     
    236253                        $this->_form->addElement('html', html_writer::end_tag('div'));
    237254                    }
    238                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings section_level')));
    239                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting section_level')));
     255                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings section_level')));
     256                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting section_level')));
    240257                    $this->sectiondiv = true;
    241258                    break;
     
    244261                        $this->_form->addElement('html', html_writer::end_tag('div'));
    245262                    }
    246                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings activity_level')));
    247                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting activity_level')));
     263                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings activity_level')));
     264                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting activity_level')));
    248265                    $this->activitydiv = true;
    249266                    break;
    250267                default:
    251                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'normal_setting')));
     268                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'normal_setting')));
    252269                    break;
    253270            }
    254271        } else if ($setting->get_level() == backup_setting::ROOT_LEVEL) {
    255             $mform->addElement('html', html_writer::start_tag('div', array('class'=>'root_setting')));
     272            $mform->addElement('html', html_writer::start_tag('div', array('class' => 'root_setting')));
    256273        } else {
    257             $mform->addElement('html', html_writer::start_tag('div', array('class'=>'normal_setting')));
    258         }
    259     }
     274            $mform->addElement('html', html_writer::start_tag('div', array('class' => 'normal_setting')));
     275        }
     276    }
     277
    260278    /**
    261279     * Adds a fixed or static setting to the form
    262280     * @param backup_setting $setting
    263      */
    264     function add_fixed_setting(backup_setting $setting, base_task $task) {
     281     * @param base_task $task
     282     */
     283    public function add_fixed_setting(backup_setting $setting, base_task $task) {
    265284        global $OUTPUT;
    266285        $settingui = $setting->get_ui();
     
    269288            switch ($setting->get_status()) {
    270289                case backup_setting::LOCKED_BY_PERMISSION:
    271                     $icon = ' '.$OUTPUT->pix_icon('i/permissionlock', get_string('lockedbypermission', 'backup'), 'moodle', array('class'=>'smallicon lockedicon permissionlock'));
     290                    $icon = ' '.$OUTPUT->pix_icon('i/permissionlock', get_string('lockedbypermission', 'backup'), 'moodle',
     291                            array('class' => 'smallicon lockedicon permissionlock'));
    272292                    break;
    273293                case backup_setting::LOCKED_BY_CONFIG:
    274                     $icon = ' '.$OUTPUT->pix_icon('i/configlock', get_string('lockedbyconfig', 'backup'), 'moodle', array('class'=>'smallicon lockedicon configlock'));
     294                    $icon = ' '.$OUTPUT->pix_icon('i/configlock', get_string('lockedbyconfig', 'backup'), 'moodle',
     295                            array('class' => 'smallicon lockedicon configlock'));
    275296                    break;
    276297                case backup_setting::LOCKED_BY_HIERARCHY:
    277                     $icon = ' '.$OUTPUT->pix_icon('i/hierarchylock', get_string('lockedbyhierarchy', 'backup'), 'moodle', array('class'=>'smallicon lockedicon configlock'));
     298                    $icon = ' '.$OUTPUT->pix_icon('i/hierarchylock', get_string('lockedbyhierarchy', 'backup'), 'moodle',
     299                            array('class' => 'smallicon lockedicon configlock'));
    278300                    break;
    279301                default:
     
    292314        $this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
    293315    }
     316
    294317    /**
    295318     * Adds dependencies to the form recursively
     
    297320     * @param backup_setting $setting
    298321     */
    299     function add_dependencies(backup_setting $setting) {
     322    public function add_dependencies(backup_setting $setting) {
    300323        $mform = $this->_form;
    301         // Apply all dependencies for backup
    302         foreach ($setting->get_my_dependency_properties() as $key=>$dependency) {
     324        // Apply all dependencies for backup.
     325        foreach ($setting->get_my_dependency_properties() as $key => $dependency) {
    303326            call_user_func_array(array($this->_form, 'disabledIf'), $dependency);
    304327        }
    305328    }
     329
    306330    /**
    307331     * Returns true if the form was cancelled, false otherwise
     
    353377        $config->noLabel = get_string('confirmcancelno', 'backup');
    354378        $config->closeButtonTitle = get_string('close', 'editor');
    355         $PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.confirmcancel.watch_cancel_buttons', array($config));
     379        $PAGE->requires->yui_module(
     380            'moodle-backup-confirmcancel',
     381            'M.core_backup.confirmcancel.watch_cancel_buttons',
     382            array($config)
     383        );
    356384
    357385        // Get list of module types on course.
Note: See TracChangeset for help on using the changeset viewer.