Example #1
0
 public function getValue($param = null)
 {
     if ($this->_value != null) {
         return parent::getValue();
     }
     if (!$this->getParent()) {
         throw new Exception(sprintf("Meta property '%s' missing a parent reference", $this->_id));
     }
     $property = $this->getParent()->getRecursiveProperty($this->getParameter('property'));
     if ($property instanceof CollectionProperty) {
         $subParts = explode('.', $this->getParameter('action'));
         $collection = $property->getValue();
         return $collection->{$subParts[0]}(isset($subParts[1]) ? $subParts[1] : null);
     } else {
         if ($property instanceof ObjectProperty) {
             $subParts = explode('.', $this->getParameter('action'));
             $object = $property->getValue(ObjectModel::MODEL);
             return $object instanceof BaseObject ? $object->{$subParts[0]}(isset($subParts[1]) ? $subParts[1] : null) : null;
         } else {
             $class = $this->_parent->getClass();
             $action = $this->getParameter('action');
             $array = array($this->_parent->getClass(), $this->getParameter('action'));
             try {
                 $val = forward_static_call($array, $this->_parent);
             } catch (\Exception $e) {
                 throw new Exception($e->getMessage());
             }
             return $val;
         }
     }
 }
Example #2
0
 /**
  * Set a value for the property
  * 
  * Value can be either:
  * the full path to a file
  * the binary content of the file
  * 
  * @param string $value
  */
 public function setValue($value)
 {
     // @todo implement constraints
     if (substr($value, 0, 1) == DIRECTORY_SEPARATOR) {
         return $this->setValueFromFile($value);
     } else {
         return parent::setValue($value);
     }
 }
Example #3
0
 public function setValue($value)
 {
     switch ($value) {
         case self::TODAY:
             $value = date('Y-m-d H:i:s');
             break;
         case self::TOMORROW:
             $value = date('Y-m-d H:i:s', time() + 86400);
             break;
         case self::TODAY_DATE:
             $value = date('Y-m-d');
             break;
         case self::TODAY_TIME:
             $value = date('H:i:s');
             break;
         default:
             if ($this->getParameter('format') && !\Zend_Date::isDate($value, $this->getParameter('format'))) {
                 throw new Exception(array("VALUE_NOT_A_DATE", array($this->_id, $value)));
             }
             break;
     }
     parent::setValue($value);
 }
Example #4
0
 /**
  * Query and return a blob column
  * @param ObjectModel\DataObject $do
  * @param Property\AbstractProperty $property
  * @throws Exception
  * @return binary
  */
 public function loadBlob(ObjectModel\DataObject $do, Property\AbstractProperty $property)
 {
     // get table to use
     $table = $this->_getTableFromUri($do->getUri());
     if (!$table) {
         throw new Exception('MISSING_DBTABLE_PARAM');
     }
     $column = $this->_mapper ? $this->_mapper->propertyToDatastoreName($do->getClass(), $property->getId()) : $property->getId();
     // primary key is either part of the mapper configuration or 'id'
     $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($do->getUri()->getClass()) : Backend::DEFAULT_PKEY;
     $this->_connect();
     // get data from backend
     // @todo Handle complex pkeys (via mapper definition)
     $select = $this->_ressource->select()->from($table, $column)->where("{$pkey} = ?", $do->getUri()->getIdentifier())->limit(1);
     return $this->_ressource->fetchOne($select);
 }
Example #5
0
 /**
  * Add a dynamic property to an already declared data object
  * @param AbstractProperty $property
  * @return t41\ObjectModel\DataObject
  */
 public function addProperty(AbstractProperty $property)
 {
     $property->setParent($this);
     $this->_data[$property->getId()] = $property;
     $this->_dna['custom'] = true;
     return $this;
 }
Example #6
0
 public function reduce(array $params = array(), $cache = true)
 {
     if (!$this->_value) {
         return parent::reduce($params, $cache);
     } else {
         // @todo improve performances !!
         $uuid = Core\Registry::set($this->getValue(ObjectModel::DATA));
         if (isset($params['extprops']) && ($params['extprops'] === true || array_key_exists($this->_id, $params['extprops']))) {
             $value = $this->getValue(ObjectModel::DATA)->reduce(array('props' => $params['extprops'][$this->_id], 'extprops' => $params['extprops']), $cache);
         } else {
             $value = $this->getDisplayValue();
         }
         return array_merge(parent::reduce($params, $cache), array('value' => $value, 'uuid' => $uuid));
     }
 }
Example #7
0
 public function reduce(array $params = array(), $cache = true)
 {
     if (isset($params['collections']) && $params['collections'] > 0) {
         $value = $this->getValue();
         $value = $value->reduce($params, $cache);
     }
     return array_merge(parent::reduce($params), array('value' => isset($value) ? $value['collection'] : $this->_value, 'type' => 'Collection'));
 }