示例#1
0
 /**
  * Convert posted to model values after submit (based on field type)
  * @param array $data
  * @return void
  */
 protected function convertToData(&$data)
 {
     $model = new e_model($data);
     foreach ($this->getFields() as $key => $attributes) {
         $value = vartrue($attributes['dataPath']) ? $model->getData($attributes['dataPath']) : $model->get($key);
         if (null === $value) {
             continue;
         }
         switch ($attributes['type']) {
             case 'password':
                 //TODO more encryption options.
                 if (strlen($value) < 30) {
                     $value = md5($value);
                 }
                 break;
             case 'datestamp':
                 if (!is_numeric($value)) {
                     if (!empty($attributes['writeParms'])) {
                         if (is_string($attributes['writeParms'])) {
                             parse_str($attributes['writeParms'], $opt);
                         } elseif (is_array($attributes['writeParms'])) {
                             $opt = $attributes['writeParms'];
                         }
                     }
                     $format = $opt['type'] ? 'input' . $opt['type'] : 'inputdate';
                     $value = trim($value) ? e107::getDate()->toTime($value, $format) : 0;
                 }
                 break;
             case 'ip':
                 $value = trim($value) ? e107::getIPHandler()->ipEncode($value) : '';
                 break;
             case 'dropdown':
                 // TODO - ask Steve if this check is required
             // TODO - ask Steve if this check is required
             case 'lanlist':
             case 'userclasses':
             case 'comma':
             case 'checkboxes':
                 if (is_array($value)) {
                     // no sanitize here - data is added to model posted stack
                     // and validated & sanitized before sent to db
                     //$value = array_map(array(e107::getParser(), 'toDB'), $value);
                     $value = implode(',', $value);
                 }
                 break;
             case 'images':
             case 'files':
                 //	XXX Cam @ SecretR: didn't work here. See model_class.php line 2046.
                 // if(!is_array($value))
                 //		{
                 //		$value = e107::unserialize($value);
                 //	}
                 break;
         }
         /*
         			if($attributes['serialize'] == true)
         			{
         				$attributes['data'] = 'array';		
         			}
         
         			if($attributes['data'] != 'array')
         			{
         				$value = e107::unserialize($value);	
         			}
         */
         if (vartrue($attributes['dataPath'])) {
             $model->setData($attributes['dataPath'], $value);
         } else {
             $model->set($key, $value);
         }
     }
     $data = $model->getData();
     unset($model);
     $this->toData($data);
 }
示例#2
0
 public function destroy()
 {
     parent::destroy();
     $this->_validator = null;
     $this->_validation_rules = array();
     $this->_db_errno = null;
     $this->_posted_data = array();
     $this->data_has_changed = array();
     $this->_FIELD_TYPES = array();
 }