コード例 #1
0
ファイル: TableComponent.php プロジェクト: crapougnax/t41
 /**
  * Add content from a data object and optional columns ids
  * 
  * @param t41\ObjectModel\DataObject $do
  * @param array $columns
  * @return t41\View\TableComponent
  */
 public function setContent(DataObject $do, array $columns = array())
 {
     foreach ($columns as $column) {
         if (($prop = $do->getRecursiveProperty($column)) !== false) {
             $format = $prop instanceof CurrencyProperty ? self::FORM_CURRENCY : self::FORM_DEFAULT;
             $this->addColumn($column, $prop->getLabel(), $format);
         }
     }
     $data = $do->toArray(null, false, true);
     //	\Zend_Debug::dump($data); die;
     $this->addDataRow($data['data']);
     return $this;
 }
コード例 #2
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()));
 }
コード例 #3
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;
 }
コード例 #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
ファイル: Db2Adapter.php プロジェクト: crapougnax/t41
 /**
  * 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;
 }