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; } } }
/** * Return current ObjecModel\Collection instance handled by current instance * instant instanciation is performed if $_value is null or $force is true * * @param boolean $force * @return t41\ObjectModel\Collection */ public function getValue($force = false) { if (is_null($this->_value) || $force === true) { /* set a new Collection based on instanceof parameter value */ $this->_value = new ObjectModel\Collection($this->getParameter('instanceof')); $this->_value->setBoundaryBatch(-1); $this->_value->setParent($this->_parent); /* inject the condition that allows to find collection members */ if ($this->getParameter('keyprop')) { $this->_value->having($this->getParameter('keyprop'))->equals($this->_parent); } /* inject any other defined condition */ if ($this->getParameter('morekeyprop')) { foreach ($this->getParameter('morekeyprop') as $value) { if (strstr(trim($value), ' ') !== false) { // if value contains spaces, it's a pattern $parts = explode(' ', $value); if (count($parts) == 3) { if ($parts[2] == 'novalue') { $parts[2] = Condition::NO_VALUE; } if ($parts[2] == ObjectUri::IDENTIFIER) { $parts[2] = $this->_parent->getUri(); } if (substr($parts[2], 0, 1) == '%' && substr($parts[2], -1) == '%') { $prop = substr($parts[2], 1, strlen($parts[2]) - 2); if (($prop = $this->_parent->getProperty($prop)) !== false) { $parts[2] = $prop->getValue(); } } if (strstr($parts[2], ',') !== false) { $parts[2] = explode(',', $parts[2]); } $this->_value->having($parts[0])->{$parts}[1]($parts[2]); } else { if ($parts[1] == 'novalue') { $parts[1] = Condition::NO_VALUE; } if (substr($parts[1], 0, 1) == '%' && substr($parts[1], -1) == '%') { $prop = substr($parts[1], 1, strlen($parts[1]) - 2); if (($prop = $this->_parent->getProperty($prop)) !== false) { $parts[1] = $prop->getValue(); } } if (strstr($parts[1], ',') !== false) { $parts[1] = explode(',', $parts[1]); } $this->_value->having($parts[0])->equals($parts[1]); } } else { // default case, we expect the member to hold a property // with the same name and value as the current object if (($property = $this->_parent->getProperty($value)) === false) { throw new Exception(sprintf("keyprop value '%s' doesn't match any property of class '%s'", $value, $this->_parent->getClass())); } $this->_value->having($value)->equals($property->getValue()); } } } // set sorting if ($this->getParameter('sorting')) { foreach ($this->getParameter('sorting') as $key => $val) { if ($this->_value->getDataObject()->getRecursiveProperty($key) !== false) { $this->_value->setSorting(array($key, $val)); } else { Core::log(sprintf("Can't sort %s property with unknown property %s", $this->_id, $key), \Zend_Log::WARN); } } } // DON'T POPULATE THERE, IT IS DONE IMPLICITELY IN Collection::getMembers() //$this->_value->debug(); } return parent::getValue(); }