[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/data/ -> mod_form.php (source)

   1  <?php
   2  if (!defined('MOODLE_INTERNAL')) {
   3      die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
   4  }
   5  
   6  require_once ($CFG->dirroot.'/course/moodleform_mod.php');
   7  
   8  class mod_data_mod_form extends moodleform_mod {
   9  
  10      function definition() {
  11          global $CFG, $DB;
  12  
  13          $mform =& $this->_form;
  14  
  15          //-------------------------------------------------------------------------------
  16          $mform->addElement('header', 'general', get_string('general', 'form'));
  17  
  18          $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
  19          if (!empty($CFG->formatstringstriptags)) {
  20              $mform->setType('name', PARAM_TEXT);
  21          } else {
  22              $mform->setType('name', PARAM_CLEANHTML);
  23          }
  24          $mform->addRule('name', null, 'required', null, 'client');
  25          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  26  
  27          $this->standard_intro_elements(get_string('intro', 'data'));
  28  
  29          // ----------------------------------------------------------------------
  30          $mform->addElement('header', 'entrieshdr', get_string('entries', 'data'));
  31  
  32          $mform->addElement('selectyesno', 'approval', get_string('requireapproval', 'data'));
  33          $mform->addHelpButton('approval', 'requireapproval', 'data');
  34  
  35          $mform->addElement('selectyesno', 'manageapproved', get_string('manageapproved', 'data'));
  36          $mform->addHelpButton('manageapproved', 'manageapproved', 'data');
  37          $mform->setDefault('manageapproved', 1);
  38          $mform->disabledIf('manageapproved', 'approval', 'eq', 0);
  39  
  40          $mform->addElement('selectyesno', 'comments', get_string('allowcomments', 'data'));
  41  
  42          $countoptions = array(0=>get_string('none'))+
  43                          (array_combine(range(1, DATA_MAX_ENTRIES), // Keys.
  44                                          range(1, DATA_MAX_ENTRIES))); // Values.
  45          $mform->addElement('select', 'requiredentries', get_string('requiredentries', 'data'), $countoptions);
  46          $mform->addHelpButton('requiredentries', 'requiredentries', 'data');
  47  
  48          $mform->addElement('select', 'requiredentriestoview', get_string('requiredentriestoview', 'data'), $countoptions);
  49          $mform->addHelpButton('requiredentriestoview', 'requiredentriestoview', 'data');
  50  
  51          $mform->addElement('select', 'maxentries', get_string('maxentries', 'data'), $countoptions);
  52          $mform->addHelpButton('maxentries', 'maxentries', 'data');
  53  
  54          // ----------------------------------------------------------------------
  55          $mform->addElement('header', 'availibilityhdr', get_string('availability'));
  56  
  57          $mform->addElement('date_time_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'),
  58                             array('optional' => true));
  59  
  60          $mform->addElement('date_time_selector', 'timeavailableto', get_string('availabletodate', 'data'),
  61                             array('optional' => true));
  62  
  63          $mform->addElement('date_time_selector', 'timeviewfrom', get_string('viewfromdate', 'data'),
  64                             array('optional' => true));
  65  
  66          $mform->addElement('date_time_selector', 'timeviewto', get_string('viewtodate', 'data'),
  67                             array('optional' => true));
  68  
  69          // ----------------------------------------------------------------------
  70          if ($CFG->enablerssfeeds && $CFG->data_enablerssfeeds) {
  71              $mform->addElement('header', 'rsshdr', get_string('rss'));
  72              $mform->addElement('select', 'rssarticles', get_string('numberrssarticles', 'data') , $countoptions);
  73          }
  74  
  75          $this->standard_grading_coursemodule_elements();
  76  
  77          $this->standard_coursemodule_elements();
  78  
  79  //-------------------------------------------------------------------------------
  80          // buttons
  81          $this->add_action_buttons();
  82      }
  83  
  84      /**
  85       * Enforce validation rules here
  86       *
  87       * @param array $data array of ("fieldname"=>value) of submitted data
  88       * @param array $files array of uploaded files "element_name"=>tmp_file_path
  89       * @return array
  90       **/
  91      public function validation($data, $files) {
  92          $errors = parent::validation($data, $files);
  93  
  94          // Check open and close times are consistent.
  95          if ($data['timeavailablefrom'] && $data['timeavailableto'] &&
  96                  $data['timeavailableto'] < $data['timeavailablefrom']) {
  97              $errors['timeavailableto'] = get_string('availabletodatevalidation', 'data');
  98          }
  99          if ($data['timeviewfrom'] && $data['timeviewto'] &&
 100                  $data['timeviewto'] < $data['timeviewfrom']) {
 101              $errors['timeviewto'] = get_string('viewtodatevalidation', 'data');
 102          }
 103  
 104          return $errors;
 105      }
 106  
 107      function data_preprocessing(&$default_values){
 108          parent::data_preprocessing($default_values);
 109      }
 110  
 111  }
 112  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1