Ejemplo n.º 1
0
 /**
  * creates a new config entry in database
  * @param string name of entry
  * @param array data to insert as assoc array
  * @throws InvalidArgumentException
  * @return Ambigous <NULL, ConfigEntry>
  */
 function create($field, $data = array())
 {
     if (!$field) {
         throw new InvalidArgumentException("config fieldname is mandatory");
     }
     $exists = ConfigEntry::findByField($field);
     if (count($exists)) {
         throw new InvalidArgumentException("config {$field} already exists");
     }
     $entry = new ConfigEntry();
     $entry->setData($data);
     $entry->setId(md5($field));
     $entry->field = $field;
     $entry->is_default = 1;
     $entry->comment = '';
     if (!isset($data['value'])) {
         $entry->value = '';
     }
     if (!$entry->type) {
         $entry->type = 'string';
     }
     $ret = $entry->store() ? $entry : null;
     if ($ret) {
         $this->fetchData();
     }
     return $ret;
 }