Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/user/profile/field/datetime/define.class.php
Go to the documentation of this file.
00001 <?php
00002 
00011 class profile_define_datetime extends profile_define_base {
00012 
00018     function define_form_specific($form) {
00019         // Create variables to store start and end
00020         $currentyear = date('Y');
00021         $startyear = $currentyear - 100;
00022         $endyear = $currentyear + 20;
00023 
00024         // Create array for the years
00025         $arryears = array();
00026         for ($i = $startyear; $i <= $endyear; $i++) {
00027             $arryears[$i] = $i;
00028         }
00029 
00030         // Add elements
00031         $form->addElement('select', 'param1', get_string('startyear', 'profilefield_datetime'), $arryears);
00032         $form->setType('param1', PARAM_INT);
00033         $form->setDefault('param1', $currentyear);
00034 
00035         $form->addElement('select', 'param2', get_string('endyear', 'profilefield_datetime'), $arryears);
00036         $form->setType('param2', PARAM_INT);
00037         $form->setDefault('param2', $currentyear + 20);
00038 
00039         $form->addElement('checkbox', 'param3', get_string('wanttime', 'profilefield_datetime'));
00040         $form->setType('param3', PARAM_INT);
00041 
00042         $form->addElement('hidden', 'defaultdata', '0');
00043         $form->setType('defaultdata', PARAM_INT);
00044     }
00045 
00052     function define_validate_specific($data) {
00053         $errors = array();
00054 
00055         // Make sure the start year is not greater than the end year
00056         if ($data->param1 > $data->param2) {
00057             $errors['param1'] = get_string('startyearafterend', 'profilefield_datetime');
00058         }
00059 
00060         return $errors;
00061     }
00062 
00070     function define_save_preprocess($data) {
00071         if (empty($data->param3)) {
00072             $data->param3 = NULL;
00073         }
00074 
00075         // No valid value in the default data column needed
00076         $data->defaultdata = '0';
00077 
00078         return $data;
00079     }
00080 }
 All Data Structures Namespaces Files Functions Variables Enumerations