public function build(ObjectModel\DataObject $do, array $display = null, $identifier = false) { if ($identifier === true) { $identifier = new FieldElement(ObjectUri::IDENTIFIER); $identifier->setTitle("Identifiant unique")->setConstraint(Property::CONSTRAINT_MANDATORY, true)->setConstraint(Property::CONSTRAINT_MAXLENGTH, 10); $this->addElement($identifier); } if (is_null($display)) { $display = array_keys($do->getProperties()); } foreach ($display as $element) { $property = $do->getRecursiveProperty($element); if ($property instanceof AbstractProperty) { /* convert property to form element */ $this->addElementFromProperty($property, $element, (count($this->_elements) + 1) * 100); } } }
/** * Save new set of data from a t41_Data_Object object * * @param t41_Data_Object $do * @return boolean * @throws t41_Backend_Exception */ public function create(ObjectModel\DataObject $do) { $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($do->getClass()) : 'uid'; $recordSet = $do->toArray($this->_uri->getAlias()); // get a valid data array passing mapper if any if ($this->_mapper) { // get object class $objectClass = $this->_mapper->getDataclass($do->getClass()); $subDn = $this->_mapper->getDatastore($do->getClass()); $recordSet = $do->map($this->_mapper, $this->_uri->getAlias()); } else { /* * If no mapper is available, LDAP objectClass is supposed to be the same as PHP object class * CN is a MD5 hash of recordSet */ $objectClass = $do->getClass(); $subDn = null; } $recordSet['data']['objectClass'] = $objectClass; try { if (!$this->_ressource) { $this->_connect($subDn); } // Define unique part of the record DN // If no value is specified, get a unique identifier $dn = sprintf('%s=%s', $pkey, isset($recordSet['data'][$pkey]) ? $recordSet['data'][$pkey] : $this->_getIdentifier($this->_mapper->getDatastore($do->getClass()))); // Datastore value may contain supplemental path like 'ou=...' if (($ou = $this->_mapper->getDatastore($do->getClass())) != null) { $dn = $dn . ',' . $ou; } $dn .= ',' . $this->_baseDN; $this->_ressource->save($dn, $recordSet['data']); } catch (Exception $e) { // @todo decide wether throw an exception or just save last message in a property die($e->getMessage()); return false; } $uri = new ObjectModel\ObjectUri(); $do->setUri($this->getAlias() . '/' . $dn); /* get collection handling properties (if any) and process them */ foreach ($do->getProperties() as $property) { if (!$property instanceof Property\CollectionProperty) { continue; } $collection = $property->getValue(); var_dump($collection->getMembers()); /* @var $member t41_Object_Model */ foreach ($collection->getMembers() as $member) { $member->setProperty($property->getParameter('keyprop'), $uri); $member->save(); } } return true; }
protected function _getColumns(DataObject $do) { $columns = array(); foreach ($do->getProperties() as $property) { if ($property instanceof Property\BlobProperty || $property instanceof Property\CollectionProperty || $property instanceof Property\MetaProperty) { continue; } $columns[] = $this->_mapper ? $this->_mapper->propertyToDatastoreName($do->getClass(), $property->getId()) : $property->getId(); } return $columns; }
/** * Save new set of data from a t41_Data_Object object using INSERT * * @param \t41\ObjectModel\DataObject $do * @return boolean * @throws \t41\Backend\Adapter\Exception */ public function create(ObjectModel\DataObject $do) { $table = $this->_getTableFromClass($do->getClass()); if (!$table) { throw new Exception('BACKEND_MISSING_DBTABLE_PARAM'); } // get a valid data array passing mapper if any if ($this->_mapper) { $recordSet = $do->map($this->_mapper, $this); } else { $recordSet = $do->toArray($this); } // Zend_Debug::dump($recordSet); $this->_setLastQuery('insert', $recordSet); try { $this->_connect(); $this->_ressource->insert(isset($table) ? $table : $do->getClass(), $recordSet['data']); } catch (Exception $e) { if (true) { throw new Exception("Error Creating Record: " . $e->getMessage); } else { return false; } } // inject new t41_Object_Uri object in data object // @todo provide support for primary keys that are not generated by DB (not AUTO INCREMENTED INTEGER) $id = $this->_ressource->lastInsertId(); $uri = $id; if (!$this->_mapper instanceof Backend\Mapper) { $uri = $table . '/' . $uri; } $uri = new ObjectModel\ObjectUri($uri); $do->setUri($uri); /* get collection handling properties (if any) and process them */ foreach ($do->getProperties() as $property) { if (!$property instanceof Property\CollectionProperty) { continue; } $collection = $property->getValue(); //var_dump($collection->getMembers()); /* @var $member t41_Object_Model */ foreach ($collection->getMembers() as $member) { $member->setProperty($property->getParameter('keyprop'), $uri); $member->save(); } } return true; }