Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/portfolio/forms.php
Go to the documentation of this file.
00001 <?php
00029 defined('MOODLE_INTERNAL') || die();
00030 
00031 // make sure we include moodleform first!
00032 require_once ($CFG->libdir.'/formslib.php');
00033 
00044 final class portfolio_export_form extends moodleform {
00045 
00046     public function definition() {
00047 
00048         $mform =& $this->_form;
00049         $mform->addElement('hidden', 'stage', PORTFOLIO_STAGE_CONFIG);
00050         $mform->addElement('hidden', 'id', $this->_customdata['id']);
00051         $mform->addElement('hidden', 'instance', $this->_customdata['instance']->get('id'));
00052         $mform->setType('instance', PARAM_INT);
00053         $mform->setType('stage', PARAM_INT);
00054         $mform->setType('id', PARAM_INT);
00055 
00056         if (array_key_exists('formats', $this->_customdata) && is_array($this->_customdata['formats'])) {
00057             if (count($this->_customdata['formats']) > 1) {
00058                 $options = array();
00059                 foreach ($this->_customdata['formats'] as $key) {
00060                     $options[$key] = get_string('format_' . $key, 'portfolio');
00061                 }
00062                 $mform->addElement('select', 'format', get_string('availableformats', 'portfolio'), $options);
00063             } else {
00064                 $f = array_shift($this->_customdata['formats']);
00065                 $mform->addElement('hidden', 'format', $f);
00066                 $mform->setType('format', PARAM_RAW);
00067             }
00068         }
00069 
00070         // only display the option to wait or not if it's applicable
00071         if (array_key_exists('expectedtime', $this->_customdata)
00072             && $this->_customdata['expectedtime'] != PORTFOLIO_TIME_LOW
00073             && $this->_customdata['expectedtime'] != PORTFOLIO_TIME_FORCEQUEUE) {
00074             $radioarray = array();
00075             $radioarray[] = &MoodleQuickForm::createElement('radio', 'wait', '', get_string('wait', 'portfolio'), 1);
00076             $radioarray[] = &MoodleQuickForm::createElement('radio', 'wait', '', get_string('dontwait', 'portfolio'),  0);
00077             $mform->addGroup($radioarray, 'radioar', get_string('wanttowait_' . $this->_customdata['expectedtime'], 'portfolio') , array(' '), false);
00078             $mform->setDefault('wait', 0);
00079         } else {
00080             if ($this->_customdata['expectedtime'] == PORTFOLIO_TIME_LOW) {
00081                 $mform->addElement('hidden', 'wait', 1);
00082             } else {
00083                 $mform->addElement('hidden', 'wait', 0);
00084             }
00085             $mform->setType('wait', PARAM_INT);
00086         }
00087 
00088         if (array_key_exists('plugin', $this->_customdata) && is_object($this->_customdata['plugin'])) {
00089             $this->_customdata['plugin']->export_config_form($mform, $this->_customdata['userid']);
00090         }
00091 
00092         if (array_key_exists('caller', $this->_customdata) && is_object($this->_customdata['caller'])) {
00093             $this->_customdata['caller']->export_config_form($mform, $this->_customdata['instance'], $this->_customdata['userid']);
00094         }
00095 
00096         $this->add_action_buttons(true, get_string('next'));
00097     }
00098 
00099     public function validation($data) {
00100 
00101         $errors = array();
00102 
00103         if (array_key_exists('plugin', $this->_customdata) && is_object($this->_customdata['plugin'])) {
00104             $pluginerrors = $this->_customdata['plugin']->export_config_validation($data);
00105             if (is_array($pluginerrors)) {
00106                 $errors = $pluginerrors;
00107             }
00108         }
00109         if (array_key_exists('caller', $this->_customdata) && is_object($this->_customdata['caller'])) {
00110             $callererrors = $this->_customdata['caller']->export_config_validation($data);
00111             if (is_array($callererrors)) {
00112                 $errors = array_merge($errors, $callererrors);
00113             }
00114         }
00115         return $errors;
00116     }
00117 }
00118 
00126 final class portfolio_admin_form extends moodleform {
00127 
00128     protected $instance;
00129     protected $plugin;
00130     protected $portfolio;
00131     protected $action;
00132     protected $visible;
00133 
00134     public function definition() {
00135         global $CFG;
00136         $this->plugin = $this->_customdata['plugin'];
00137         $this->instance = (isset($this->_customdata['instance'])
00138                 && is_subclass_of($this->_customdata['instance'], 'portfolio_plugin_base'))
00139             ? $this->_customdata['instance'] : null;
00140         $this->portfolio = $this->_customdata['portfolio'];
00141         $this->action = $this->_customdata['action'];
00142         $this->visible = $this->_customdata['visible'];
00143 
00144         $mform =& $this->_form;
00145         $strrequired = get_string('required');
00146 
00147         $mform->addElement('hidden', 'pf', $this->portfolio);
00148         $mform->setType('pf', PARAM_ALPHA);
00149         $mform->addElement('hidden', 'action', $this->action);
00150         $mform->setType('action', PARAM_ALPHA);
00151         $mform->addElement('hidden', 'visible', $this->visible);
00152         $mform->setType('visible', PARAM_INT);
00153         $mform->addElement('hidden', 'plugin', $this->plugin);
00154         $mform->setType('plugin', PARAM_PLUGIN);
00155 
00156         if (!$this->instance) {
00157             $insane = portfolio_instance_sanity_check($this->instance);
00158         } else {
00159             $insane = portfolio_plugin_sanity_check($this->plugin);
00160         }
00161 
00162         if (isset($insane) && is_array($insane)) {
00163             $insane = array_shift($insane);
00164         }
00165         if (isset($insane) && is_string($insane)) { // something went wrong, warn...
00166             $mform->addElement('warning', 'insane', null, get_string($insane, 'portfolio_' . $this->plugin));
00167         }
00168 
00169         $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
00170         $mform->addRule('name', $strrequired, 'required', null, 'client');
00171 
00172         // let the plugin add the fields they want (either statically or not)
00173         if (portfolio_static_function($this->plugin, 'has_admin_config')) {
00174             if (!$this->instance) {
00175                 require_once($CFG->libdir . '/portfolio/plugin.php');
00176                 require_once($CFG->dirroot . '/portfolio/' . $this->plugin .  '/lib.php');
00177                 call_user_func(array('portfolio_plugin_' . $this->plugin, 'admin_config_form'), $mform);
00178             } else {
00179                 $this->instance->admin_config_form($mform);
00180             }
00181         }
00182 
00183         // and set the data if we have some.
00184         if ($this->instance) {
00185             $data = array('name' => $this->instance->get('name'));
00186             foreach ($this->instance->get_allowed_config() as $config) {
00187                 $data[$config] = $this->instance->get_config($config);
00188             }
00189             $this->set_data($data);
00190         } else {
00191             $this->set_data(array('name' => portfolio_static_function($this->plugin, 'get_name')));
00192         }
00193 
00194         $this->add_action_buttons(true, get_string('save', 'portfolio'));
00195     }
00196 
00197     public function validation($data) {
00198         global $DB;
00199 
00200         $errors = array();
00201         if ($DB->count_records('portfolio_instance', array('name' => $data['name'], 'plugin' => $data['plugin'])) > 1) {
00202             $errors = array('name' => get_string('err_uniquename', 'portfolio'));
00203         }
00204 
00205         $pluginerrors = array();
00206         if ($this->instance) {
00207             $pluginerrors = $this->instance->admin_config_validation($data);
00208         }
00209         else {
00210             $pluginerrors = portfolio_static_function($this->plugin, 'admin_config_validation', $data);
00211         }
00212         if (is_array($pluginerrors)) {
00213             $errors = array_merge($errors, $pluginerrors);
00214         }
00215         return $errors;
00216     }
00217 }
00218 
00227 final class portfolio_user_form extends moodleform {
00228 
00229     protected $instance;
00230     protected $userid;
00231 
00232     public function definition() {
00233         $this->instance = $this->_customdata['instance'];
00234         $this->userid = $this->_customdata['userid'];
00235 
00236         $this->_form->addElement('hidden', 'config', $this->instance->get('id'));
00237         $this->_form->setType('config', PARAM_INT);
00238 
00239         $this->instance->user_config_form($this->_form, $this->userid);
00240 
00241         $data = array();
00242         foreach ($this->instance->get_allowed_user_config() as $config) {
00243             $data[$config] = $this->instance->get_user_config($config, $this->userid);
00244         }
00245         $this->set_data($data);
00246         $this->add_action_buttons(true, get_string('save', 'portfolio'));
00247     }
00248 
00249     public function validation($data) {
00250 
00251         $errors = $this->instance->user_config_validation($data);
00252 
00253     }
00254 }
00255 
00256 
00263 class portfolio_instance_select extends moodleform {
00264 
00265     private $caller;
00266 
00267     function definition() {
00268         $this->caller = $this->_customdata['caller'];
00269         $options = $this->_customdata['options'];
00270         $mform =& $this->_form;
00271         $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options);
00272         $mform->addElement('hidden', 'id', $this->_customdata['id']);
00273         $this->add_action_buttons(true, get_string('next'));
00274     }
00275 }
 All Data Structures Namespaces Files Functions Variables Enumerations