Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/ui/base_moodleform.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once($CFG->libdir . '/formslib.php');
00031 
00042 abstract class base_moodleform extends moodleform {
00047     protected $uistage = null;
00052     protected $coursediv = false;
00057     protected $sectiondiv = false;
00062     protected $activitydiv = false;
00074     function __construct(base_ui_stage $uistage, $action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) {
00075         $this->uistage = $uistage;
00076         parent::__construct($action, $customdata, $method, $target, $attributes, $editable);
00077     }
00081     function definition() {
00082         $ui = $this->uistage->get_ui();
00083         $mform = $this->_form;
00084         $stage = $mform->addElement('hidden', 'stage', $this->uistage->get_stage());
00085         $stage = $mform->addElement('hidden', $ui->get_name(), $ui->get_uniqueid());
00086         $params = $this->uistage->get_params();
00087         if (is_array($params) && count($params) > 0) {
00088             foreach ($params as $name=>$value) {
00089                 $stage = $mform->addElement('hidden', $name, $value);
00090             }
00091         }
00092     }
00098     function definition_after_data() {
00099         global $PAGE;
00100         $buttonarray=array();
00101         $buttonarray[] = $this->_form->createElement('submit', 'submitbutton', get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'), array('class'=>'proceedbutton'));
00102         if (!$this->uistage->is_first_stage()) {
00103             $buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage','backup'));
00104         }
00105         $buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class'=>'confirmcancel'));
00106         $this->_form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
00107         $this->_form->closeHeaderBefore('buttonar');
00108 
00109         $config = new stdClass;
00110         $config->title = get_string('confirmcancel', 'backup');
00111         $config->question = get_string('confirmcancelquestion', 'backup');
00112         $config->yesLabel = get_string('confirmcancelyes', 'backup');
00113         $config->noLabel = get_string('confirmcancelno', 'backup');
00114         $PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_cancel_buttons', array($config));
00115     }
00119     function close_task_divs() {
00120         if ($this->activitydiv) {
00121             $this->_form->addElement('html', html_writer::end_tag('div'));
00122             $this->activitydiv = false;
00123         }
00124         if ($this->sectiondiv) {
00125             $this->_form->addElement('html', html_writer::end_tag('div'));
00126             $this->sectiondiv = false;
00127         }
00128         if ($this->coursediv) {
00129             $this->_form->addElement('html', html_writer::end_tag('div'));
00130             $this->coursediv = false;
00131         }
00132     }
00138     function add_setting(backup_setting $setting, base_task $task=null) {
00139         global $OUTPUT;
00140 
00141         // If the setting cant be changed or isn't visible then add it as a fixed setting.
00142         if (!$setting->get_ui()->is_changeable() || $setting->get_visibility() != backup_setting::VISIBLE) {
00143             return $this->add_fixed_setting($setting, $task);
00144         }
00145 
00146         // First add the formatting for this setting
00147         $this->add_html_formatting($setting);
00148 
00149         // The call the add method with the get_element_properties array
00150         call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
00151         $this->_form->setDefault($setting->get_ui_name(), $setting->get_value());
00152         if ($setting->has_help()) {
00153             list($identifier, $component) = $setting->get_help();
00154             $this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
00155         }
00156         $this->_form->addElement('html', html_writer::end_tag('div'));
00157         return true;
00158     }
00164     function add_heading($name , $text) {
00165         $this->_form->addElement('header', $name, $text);
00166     }
00172     protected function add_html_formatting(backup_setting $setting) {
00173         $mform = $this->_form;
00174         $isincludesetting = (strpos($setting->get_name(), '_include')!==false);
00175         if ($isincludesetting && $setting->get_level() != backup_setting::ROOT_LEVEL)  {
00176             switch ($setting->get_level()) {
00177                 case backup_setting::COURSE_LEVEL:
00178                     if ($this->activitydiv) {
00179                         $this->_form->addElement('html', html_writer::end_tag('div'));
00180                         $this->activitydiv = false;
00181                     }
00182                     if ($this->sectiondiv) {
00183                         $this->_form->addElement('html', html_writer::end_tag('div'));
00184                         $this->sectiondiv = false;
00185                     }
00186                     if ($this->coursediv) {
00187                         $this->_form->addElement('html', html_writer::end_tag('div'));
00188                     }
00189                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings course_level')));
00190                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting course_level')));
00191                     $this->coursediv = true;
00192                     break;
00193                 case backup_setting::SECTION_LEVEL:
00194                     if ($this->activitydiv) {
00195                         $this->_form->addElement('html', html_writer::end_tag('div'));
00196                         $this->activitydiv = false;
00197                     }
00198                     if ($this->sectiondiv) {
00199                         $this->_form->addElement('html', html_writer::end_tag('div'));
00200                     }
00201                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings section_level')));
00202                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting section_level')));
00203                     $this->sectiondiv = true;
00204                     break;
00205                 case backup_setting::ACTIVITY_LEVEL:
00206                     if ($this->activitydiv) {
00207                         $this->_form->addElement('html', html_writer::end_tag('div'));
00208                     }
00209                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'grouped_settings activity_level')));
00210                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'include_setting activity_level')));
00211                     $this->activitydiv = true;
00212                     break;
00213                 default:
00214                     $mform->addElement('html', html_writer::start_tag('div', array('class'=>'normal_setting')));
00215                     break;
00216             }
00217         } else if ($setting->get_level() == backup_setting::ROOT_LEVEL) {
00218             $mform->addElement('html', html_writer::start_tag('div', array('class'=>'root_setting')));
00219         } else {
00220             $mform->addElement('html', html_writer::start_tag('div', array('class'=>'normal_setting')));
00221         }
00222     }
00227     function add_fixed_setting(backup_setting $setting, base_task $task) {
00228         global $OUTPUT;
00229         $settingui = $setting->get_ui();
00230         if ($setting->get_visibility() == backup_setting::VISIBLE) {
00231             $this->add_html_formatting($setting);
00232             switch ($setting->get_status()) {
00233                 case backup_setting::LOCKED_BY_PERMISSION:
00234                     $icon = ' '.$OUTPUT->pix_icon('i/permissionlock', get_string('lockedbypermission', 'backup'), 'moodle', array('class'=>'smallicon lockedicon permissionlock'));
00235                     break;
00236                 case backup_setting::LOCKED_BY_CONFIG:
00237                     $icon = ' '.$OUTPUT->pix_icon('i/configlock', get_string('lockedbyconfig', 'backup'), 'moodle', array('class'=>'smallicon lockedicon configlock'));
00238                     break;
00239                 case backup_setting::LOCKED_BY_HIERARCHY:
00240                     $icon = ' '.$OUTPUT->pix_icon('i/hierarchylock', get_string('lockedbyhierarchy', 'backup'), 'moodle', array('class'=>'smallicon lockedicon configlock'));
00241                     break;
00242                 default:
00243                     $icon = '';
00244                     break;
00245             }
00246             $label = $settingui->get_label($task);
00247             $labelicon = $settingui->get_icon();
00248             if (!empty($labelicon)) {
00249                 $label .= '&nbsp;'.$OUTPUT->render($labelicon);
00250             }
00251             $this->_form->addElement('static', 'static_'.$settingui->get_name(), $label, $settingui->get_static_value().$icon);
00252             $this->_form->addElement('html', html_writer::end_tag('div'));
00253         }
00254         $this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
00255     }
00261     function add_dependencies(backup_setting $setting) {
00262         $mform = $this->_form;
00263         // Apply all dependencies for backup
00264         foreach ($setting->get_my_dependency_properties() as $key=>$dependency) {
00265             call_user_func_array(array($this->_form, 'disabledIf'), $dependency);
00266         }
00267     }
00272     public function is_cancelled() {
00273         return (optional_param('cancel', false, PARAM_BOOL) || parent::is_cancelled());
00274     }
00275 
00281     public function remove_element($elementname) {
00282         if ($this->_form->elementExists($elementname)) {
00283             return $this->_form->removeElement($elementname);
00284         } else {
00285             return false;
00286         }
00287     }
00288 
00295     public function get_element($elementname) {
00296         if ($this->_form->elementExists($elementname)) {
00297             return $this->_form->getElement($elementname);
00298         } else {
00299             return false;
00300         }
00301     }
00302 
00306     public function display() {
00307         $this->require_definition_after_data();
00308         parent::display();
00309     }
00310 
00314     public function require_definition_after_data() {
00315         if (!$this->_definition_finalized) {
00316             $this->_definition_finalized = true;
00317             $this->definition_after_data();
00318         }
00319     }
00320 }
 All Data Structures Namespaces Files Functions Variables Enumerations