public function readAction() { $collection = new Collection($this->_class); if ($this->_getParam('id')) { $collection->having(ObjectUri::IDENTIFIER)->equals($this->_getParam('id')); $collection->setBoundaryBatch(1)->find(); if ($collection->getTotalMembers() == 1) { $form = new FormComponent($collection->getMember(Collection::POS_FIRST)); $form->register(); } } else { $list = new ListComponent($collection); $list->addRowAction($_SERVER['REQUEST_URI'], 'Read', array('icon' => 'tool-blue')); $list->register(); } }
/** * returns a collection of objects matching the dependency parameter */ public function dependAction() { if (($property = $this->_obj->getProperty($this->_post['destProperty']['id'])) !== false) { // @todo implement cache mechanism for the following collection $collection = new Collection($property->getParameter('instanceof')); foreach ($this->_post['srcProperty'] as $key => $val) { $collection->having($key)->equals($val); } $collection->setBoundaryBatch(50000); $collection->find(ObjectModel::MODEL); $data = array(); foreach ($collection->getMembers() as $member) { $reduced = $member->reduce(); $data[$member->getUri()->getIdentifier()] = $reduced; if ($property->getValue() && $property->getValue()->getIdentifier() == $member->getIdentifier()) { $this->_data['value'] = $reduced['uuid']; } } $this->_data['total'] = $collection->getTotalMembers(); $this->_data['collection'] = $data; } else { $this->_status = 'NOK'; } }
public function find(array $conditions = null, array $sortings = null, $offset = 0, $batch = 10) { $co = new Collection(clone $this->_dataObject); if (is_array($conditions)) { $co->setConditions($conditions); } if (is_array($sortings)) { $co->setSortings($sortings); } $co->setBoundaryOffset($offset); $co->setBoundaryBatch($batch); $co->find(); return $co; }
/** * 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(); }