/** * Append (default), prepend or remove a member from the collection * * @todo inconsistant: value should be a collection and individual members added from object * * @param t41\ObjectModel\BaseObject $value * @param string $action * @return boolean */ public function setValue($value, $action = Collection::MEMBER_APPEND) { $res = true; // instanciate collection jit if (is_null($this->_value)) { $this->getValue(); } switch ($action) { case Collection::MEMBER_APPEND: case Collection::MEMBER_PREPEND: // check that new member abides by optional unicity parameter (which contains a property name) if ($this->getParameter('unique')) { $token = $value->getProperty($this->getParameter('unique'))->getValue(); // try to find an existing record with same values $reqcol = clone $this->getValue(); $reqcol->having($this->getParameter('unique'))->equals($token); if ($reqcol->getMax() > 0) { return false; } // @todo also test members not already saved or save before testing ! } // $value should contain a property where to store the relation $value->getProperty($this->getParameter('keyprop'))->setValue($this->_parent); $this->_value->addMember($value, $action); break; case Collection::MEMBER_REMOVE: $res = $this->_value->removeMember($value); break; } $this->_changed = true; return true; }