Example #1
0
 /**
  * Constructor method.
  *
  * Pulls out the options for the menu from the database and sets the the corresponding key for the data if it exists.
  *
  * @param int $fieldid
  * @param int $userid
  */
 public function __construct($fieldid = 0, $userid = 0)
 {
     // First call parent constructor.
     parent::__construct($fieldid, $userid);
     // Param 1 for menu type is the options.
     if (isset($this->field->param1)) {
         $options = explode("\n", $this->field->param1);
     } else {
         $options = array();
     }
     $this->options = array();
     if (!empty($this->field->required)) {
         $this->options[''] = get_string('choose') . '...';
     }
     foreach ($options as $key => $option) {
         $this->options[$option] = format_string($option);
         // Multilang formatting with filters.
     }
     // Set the data key.
     if ($this->data !== null) {
         $key = $this->data;
         if (isset($this->options[$key]) || ($key = array_search($key, $this->options)) !== false) {
             $this->data = $key;
             $this->datakey = $key;
         }
     }
 }
Example #2
0
 /**
  * Constructor method.
  * Pulls out the options for the checkbox from the database and sets the
  * the corresponding key for the data if it exists
  *
  * @param int $fieldid
  * @param int $userid
  */
 public function __construct($fieldid = 0, $userid = 0)
 {
     global $DB;
     // First call parent constructor.
     parent::__construct($fieldid, $userid);
     if (!empty($this->field)) {
         $datafield = $DB->get_field('user_info_data', 'data', array('userid' => $this->userid, 'fieldid' => $this->fieldid));
         if ($datafield !== false) {
             $this->data = $datafield;
         } else {
             $this->data = $this->field->defaultdata;
         }
     }
 }