Example #1
0
 /**
  * getConfiguration
  *
  * Loads configuration information from database into hashtable format.
  * Also, the defaults from ::getConfigurationOptions() are integrated
  * into the database-backed options, so that if options have not yet
  * been set or a new option has been added and not saved for this field,
  * the default value will be reflected in the returned configuration.
  */
 function getConfiguration()
 {
     if (!$this->_config) {
         $this->_config = $this->get('configuration');
         if (is_string($this->_config)) {
             $this->_config = JsonDataParser::parse($this->_config);
         } elseif (!$this->_config) {
             $this->_config = array();
         }
         foreach ($this->getConfigurationOptions() as $name => $field) {
             if (!isset($this->_config[$name])) {
                 $this->_config[$name] = $field->get('default');
             }
         }
     }
     return $this->_config;
 }
Example #2
0
 private function getProperties()
 {
     if (!isset($this->_properties)) {
         $this->_properties = $this->get('properties');
         if (is_string($this->_properties)) {
             $this->_properties = JsonDataParser::parse($this->_properties);
         } elseif (!$this->_properties) {
             $this->_properties = array();
         }
     }
     return $this->_properties;
 }
 function getConfiguration()
 {
     if (!$this->_config) {
         $this->_config = $this->get('properties');
         if (is_string($this->_config)) {
             $this->_config = JsonDataParser::parse($this->_config);
         } elseif (!$this->_config) {
             $this->_config = array();
         }
     }
     return $this->_config;
 }
 function to_php($value, $id = false)
 {
     if (is_string($value)) {
         $value = JsonDataParser::parse($value) ?: $value;
     }
     if (!is_array($value)) {
         $values = array();
         $choices = $this->getChoices();
         foreach (explode(',', $value) as $V) {
             if (isset($choices[$V])) {
                 $values[$V] = $choices[$V];
             }
         }
         if ($id && isset($choices[$id])) {
             $values[$id] = $choices[$id];
         }
         if ($values) {
             return $values;
         }
         // else return $value unchanged
     }
     // Don't set the ID here as multiselect prevents using exactly one
     // ID value. Instead, stick with the JSON value only.
     return $value;
 }
Example #5
0
 function parse($stream)
 {
     return $this->fixup(parent::parse($stream));
 }
Example #6
0
 function to_php($value)
 {
     if (is_string($value)) {
         $value = JsonDataParser::parse($value) ?: $value;
     }
     // CDATA table may be built with comma-separated key,value,key,value
     if (is_string($value)) {
         $values = array();
         $choices = $this->getChoices();
         foreach (explode(',', $value) as $V) {
             if (isset($choices[$V])) {
                 $values[$V] = $choices[$V];
             }
         }
         if (array_filter($values)) {
             $value = $values;
         }
     }
     $config = $this->getConfiguration();
     if (!$config['multiselect'] && is_array($value) && count($value) < 2) {
         reset($value);
         $value = key($value);
     }
     return $value;
 }
 function to_php($value, $id = false)
 {
     if (is_string($value)) {
         $value = JsonDataParser::parse($value) ?: $value;
     }
     if (!is_array($value)) {
         $config = $this->getConfiguration();
         if (!$config['multiselect']) {
             // CDATA may be built with comma-list
             list($value, ) = explode(',', $value, 2);
         }
         $choices = $this->getChoices();
         if (isset($choices[$value])) {
             $value = array($value => $choices[$value]);
         } elseif ($id && isset($choices[$id])) {
             $value = array($id => $choices[$id]);
         }
     }
     // Don't set the ID here as multiselect prevents using exactly one
     // ID value. Instead, stick with the JSON value only.
     return $value;
 }
 function to_php($value)
 {
     if (is_string($value)) {
         $array = JsonDataParser::parse($value) ?: $value;
     } else {
         $array = $value;
     }
     $config = $this->getConfiguration();
     if (!$config['multiselect']) {
         if (is_array($array) && count($array) < 2) {
             reset($array);
             return key($array);
         }
         if (is_string($array) && strpos($array, ',') !== false) {
             list($array, ) = explode(',', $array, 2);
         }
     }
     return $array;
 }