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 addElementFromProperty(AbstractProperty $property, $fname, $position = null) { $class = get_class($property); $class = substr($class, strrpos($class, '\\') + 1); switch ($class) { case 'EnumProperty': if ($property->getParameter('constraints.multiple') !== false) { $element = new Element\MultipleElement(); } else { $element = new Element\EnumElement(); } $element->setEnumValues($property->getValues()); break; case 'DateProperty': $element = new Element\DateElement(); break; case 'TimeProperty': $element = new Element\TimeElement(); break; case 'CurrencyProperty': $element = new Element\CurrencyElement(); break; case 'StringProperty': if ($property->getParameter('multilines')) { $element = new Element\TextElement(); } else { $element = new Element\FieldElement(); } break; case 'ObjectProperty': // @todo join this code and the one in CollectionProperty::getValue if ($property->getParameter('instanceof') == 't41\\ObjectModel\\MediaObject') { $element = new Element\MediaElement(); } else { $element = new Element\ListElement(); $element->setParameter('display', $property->getParameter('display')); $collection = new ObjectModel\Collection($property->getParameter('instanceof')); /* inject the condition that allows to find collection members */ if ($property->getParameter('keyprop')) { $collection->having($property->getParameter('keyprop'))->equals($property->getParent()); } if ($property->getParameter('depends')) { $element->setParameter('dependency', $property->getParameter('depends')); } if ($property->getParameter('morekeyprop')) { foreach ($property->getParameter('morekeyprop') as $value) { if (strstr($value, ' ') !== false) { // if value contains spaces, it's a pattern $parts = explode(' ', $value); if (count($parts) == 3) { if (strstr($parts[2], ',') !== false) { $parts[2] = explode(',', $parts[2]); } $collection->having($parts[0])->{$parts}[1]($parts[2]); } else { if (strstr($parts[1], ',') !== false) { $parts[1] = explode(',', $parts[1]); } $collection->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 $collection->having($value)->equals($property->getParent()->getProperty($value)->getValue()); } } } if ($property->getParameter('sorting')) { $element->setParameter('sorting', $property->getParameter('sorting')); } if ($property->getParameter('search')) { $element->setParameter('search', $property->getParameter('search')); } if ($property->getParameter('sdisplay')) { $element->setParameter('sdisplay', $property->getParameter('sdisplay')); } $element->setCollection($collection); } break; case 'CollectionProperty': $element = new Element\GridElement(); $element->setCollection($property->getValue()); break; case 'MediaProperty': $element = new Element\MediaElement(); break; default: $element = new Element\FieldElement(); break; } $element->setId(str_replace('.', '-', $fname)); $element->setTitle($property->getLabel()); $element->setDefaultValue($property->getDefaultValue()); $element->setHelp($property->getParameter('help')); if ($property instanceof MetaProperty) { $value = $property->getDisplayValue(); } else { $value = $property->getValue(); if ($value instanceof ObjectModel\ObjectUri) { $value = $value->__toString(); } else { if ($value instanceof ObjectModel\BaseObject) { $value = $value->getUri() ? $value->getUri()->__toString() : null; } } } $element->setValue($value); $constraints = $property->getParameter('constraints'); foreach (self::$constraintsList as $key) { if (isset($constraints[$key])) { $element->setConstraint($key, $constraints[$key] != '0' && empty($constraints[$key]) ? true : $constraints[$key]); } } // property uses a special format for which we should have a decorator if (isset($constraints['format'])) { $element->setDecorator($constraints['format']); } return $this->addElement($element, $position); }
/** * 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(); }