コード例 #1
0
ファイル: MongoDBAdapter.php プロジェクト: crapougnax/t41
 /**
  * Enregistre les modifications de l'Objet correspondant au DataObject donné en paramètres
  *
  * @param t41_Data_Object $do
  * @return mixed
  */
 public function update(ObjectModel\DataObject $do)
 {
     $uri = $do->getUri();
     // get table to use, from mapper if available, else from data object
     $table = $this->_mapper instanceof Backend\Mapper ? $this->_mapper->getDatastore($uri->getClass()) : $do->getClass();
     // prepare data
     $data = $do->toArray();
     // Mapping et conversion de valeurs
     $data = $this->_mapper->objectToArray($data, $uri->getClass());
     $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($uri->getClass()) : 'id';
     return $this->_ressource->update($table, $data, $this->_ressource->quoteInto("{$pkey} = ?", $uri->getIdentifier()));
 }
コード例 #2
0
ファイル: AbstractAdapter.php プロジェクト: crapougnax/t41
 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;
 }
コード例 #3
0
ファイル: PdoAdapter.php プロジェクト: crapougnax/t41
 /**
  * Delete record in backend 
  * 
  * @param t41\ObjectModel\DataObject $do
  * @return boolean
  */
 public function delete(ObjectModel\DataObject $do)
 {
     $uri = $do->getUri();
     $table = $this->_mapper instanceof Backend\Mapper ? $this->_mapper->getDatastore($uri->getClass()) : $do->getClass();
     $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($uri->getClass()) : 'id';
     // @todo add a try/catch block
     return (bool) $this->_ressource->delete($table, $this->_ressource->quoteInto("{$pkey} = ?" . $uri->getIdentifier()));
 }
コード例 #4
0
ファイル: LdapAdapter.php プロジェクト: crapougnax/t41
 /**
  * Update record data in the backend with passed data object properties values 
  *
  * @param t41_Data_Object $do
  * @return boolean
  */
 public function update(ObjectModel\DataObject $do)
 {
     // Properties mapping (to array)
     if ($this->_mapper) {
         $data = $do->map($this->_mapper, $do->getClass());
     } else {
         $data = $do->toArray();
     }
     $data = $this->_unflattenArray($data);
     return (bool) $this->_ressource->update($do->getUri()->getIdentifier(), $data);
 }
コード例 #5
0
ファイル: XmlAdapter.php プロジェクト: crapougnax/t41
 /**
  * Enregistre les modifications de l'Objet correspondant au DataObject donné en paramètres
  *
  * @param t41_Data_Object $do
  * @return mixed
  */
 public function update(ObjectModel\DataObject $do)
 {
     if (!$this->_setRessource($do->getClass())) {
         die('BACKEND_RESSOURCE_ERROR');
     }
     try {
         $uri = $do->getUri();
         $xpath = new \DOMXPath($this->_ressource);
         $expr = sprintf("//%s[@%s='%s']", $this->_itemName, $this->_pkey, $uri->getIdentifier());
         $node = $xpath->query($expr)->item(0);
         // prepare data
         $data = $this->_mapper ? $this->_mapper->objectToArray($do->toArray(), $do->getClass()) : $do->toArray();
         // update existing nodes
         foreach ($node->getElementsByTagName('*') as $val) {
             if (isset($data[$val->nodeName])) {
                 $val->nodeValue = $data[$val->nodeName];
                 unset($data[$val->nodeName]);
             }
         }
         // then add new data
         foreach ($data as $key => $val) {
             $elem = $this->_ressource->createElement($key, $val);
             $node->appendChild($elem);
         }
         $this->_saveRessource();
     } catch (Exception $e) {
         die($e->getMessage());
     }
     return true;
 }
コード例 #6
0
ファイル: AbstractPdoAdapter.php プロジェクト: crapougnax/t41
 /**
  * Query and return a blob column
  * @param ObjectModel\DataObject $do
  * @param Property\AbstractProperty $property
  * @throws Exception
  * @return binary
  */
 public function loadBlob(ObjectModel\DataObject $do, Property\AbstractProperty $property)
 {
     // get table to use
     $table = $this->_getTableFromUri($do->getUri());
     if (!$table) {
         throw new Exception('MISSING_DBTABLE_PARAM');
     }
     $column = $this->_mapper ? $this->_mapper->propertyToDatastoreName($do->getClass(), $property->getId()) : $property->getId();
     // primary key is either part of the mapper configuration or 'id'
     $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($do->getUri()->getClass()) : Backend::DEFAULT_PKEY;
     $this->_connect();
     // get data from backend
     // @todo Handle complex pkeys (via mapper definition)
     $select = $this->_ressource->select()->from($table, $column)->where("{$pkey} = ?", $do->getUri()->getIdentifier())->limit(1);
     return $this->_ressource->fetchOne($select);
 }
コード例 #7
0
ファイル: Backend.php プロジェクト: crapougnax/t41
 /**
  * Delete the given data object in its backend
  * 
  * @param ObjectModel\DataObject $do
  * @param Backend\Adapter\AbstractAdapter $backend
  * @throws Backend\Exception
  */
 public static function delete(ObjectModel\DataObject $do, Backend\Adapter\AbstractAdapter $backend = null)
 {
     if (is_null($backend)) {
         if ($do->getUri()) {
             /* uri n'est pas vide, on peu alors essayer d'y trouver le backend */
             $backend = self::getInstance($do->getUri()->getBackendUri());
         } else {
             /* get object definition default backend */
             $backend = ObjectModel::getObjectBackend($do->getClass());
         }
         if (is_null($backend)) {
             /* get object default backend if exists */
             $backend = self::getDefaultBackend();
         }
     }
     if (!$backend) {
         throw new Backend\Exception("NO_AVAILABLE_BACKEND");
     }
     return $backend->delete($do);
 }