Example #1
0
 /**
  * Efface la ligne la base identifié par l'Uri en paramètre
  *
  * @param t41_Data_Object $do
  * @return mixed
  */
 public function delete(ObjectModel\DataObject $do)
 {
     // on découpe l'url de l'URI afin d'obtenir les parties qui nous interesse.
     $uri = $do->getUri();
     // on trouve la base de donnée à utiliser
     $database = $this->_selectDatabase($uri);
     // on trouve la table à utiliser
     $table = $this->_selectTable($uri);
     //return $this->_ressource->delete($table, $table . "_id = " . $url['id']);
 }
Example #2
0
 /**
  * Return a key/value array of all backend keys needed to build a query for a unique record
  * 
  * @param t41\ObjectModel\DataObject $do
  * @return array
  */
 protected function _preparePrimaryKeyClauses(DataObject $do)
 {
     /* no mapper or no pkey definition in mapper */
     if (!$this->_mapper || $this->_mapper->getPrimaryKey($do->getUri()->getClass()) == Backend::DEFAULT_PKEY) {
         return array(Backend::DEFAULT_PKEY => $do->getUri()->getIdentifier());
     }
     $array = array();
     // example of mapper definition: <mapper id="myid" pkey="key1:string,key2:integer">...</mapper>
     $pkeyVals = explode(Backend\Mapper::VALUES_SEPARATOR, $do->getUri()->getIdentifier());
     /* @var $obj t41_Backend_Key */
     foreach ($this->_mapper->getPrimaryKey($do->getClass()) as $key => $obj) {
         if (!isset($pkeyVals[$key])) {
             continue;
         }
         $array[$obj->getName()] = $obj->castValue($pkeyVals[$key]);
     }
     return $array;
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 /**
  * 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()));
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 /**
  * Delete record in backend 
  * 
  * @param t41\ObjectModel\DataObject $do
  * @return boolean
  */
 public function delete(ObjectModel\DataObject $do)
 {
     $uri = $do->getUri();
     if (!$uri) {
         return false;
     }
     // get table to use
     $table = $this->_getTableFromUri($uri);
     if (!$table) {
         throw new Exception('MISSING_DBTABLE_PARAM');
     }
     $pkey = $this->_mapper ? $this->_mapper->getPrimaryKey($uri->getClass()) : Backend::DEFAULT_PKEY;
     try {
         $this->_connect();
         $res = $this->_ressource->delete($table, $this->_ressource->quoteInto("{$pkey} = ?", $uri->getIdentifier()));
         $this->_setLastQuery('delete', null, array('table' => $table));
     } catch (\Exception $e) {
         $this->_setLastQuery('delete', null, array('table' => $table, 'context' => $e->getMessage()));
         return false;
     }
     return (bool) $res;
 }
Example #7
0
 /**
  * Load and return a blob
  * @param ObjectModel\DataObject $do
  * @param Property\AbstractProperty $property
  * @return binary
  */
 public static function loadBlob(ObjectModel\DataObject $do, Property\AbstractProperty $property)
 {
     $backend = self::getInstance($do->getUri()->getBackendUri()->getAlias());
     if ($backend instanceof Backend\Adapter\AbstractAdapter) {
         return $backend->loadBlob($do, $property);
     }
     return null;
 }
Example #8
0
 public function delete(ObjectModel\DataObject $do)
 {
     return unlink($this->_basePath . $do->getUri()->getUrl());
 }
Example #9
0
 protected function _contentRendering()
 {
     $i = 0;
     $p = '';
     $aliases = $this->_obj->getAliases();
     // print out rows
     foreach ($this->_obj->getCollection()->getMembers(ObjectModel::DATA) as $this->_key => $this->_do) {
         $css = $i % 2 == 0 ? 'odd' : 'even';
         //	\Zend_Debug::dump($this->_do->getProperty('marche')->getValue(ObjectModel::MODEL)); die;
         // @todo handle objects coming from different backends
         $p .= sprintf('<tr data-member="%s" data-alias="%s" class="%s">', $this->_key, $this->_do->getUri() ? $aliases[$this->_do->getUri()->getIdentifier()] : null, $css);
         $i++;
         if ($this->_obj->getParameter('selectable') === true) {
             // make list items selectable
             $p .= sprintf('<td><input type="checkbox" name="t41_selection[]" value="%s"/></td>', $this->_do->getUri()->getIdentifier());
         }
         $altDec = (array) $this->_obj->getParameter('decorators');
         foreach ($this->_obj->getColumns() as $column) {
             if ($column instanceof Element\IdentifierElement) {
                 $p .= sprintf('<td>%s</td>', $this->_do->getUri()->getIdentifier());
                 continue;
             }
             if ($column instanceof Element\MetaElement) {
                 $attrib = $column->getParameter('type') == 'currency' ? ' class="cellcurrency"' : null;
                 $p .= "<td{$attrib}>" . $column->getDisplayValue($this->_do) . '</td>';
                 continue;
             }
             $property = $this->_do->getProperty($column->getParameter('property'));
             if (!$property) {
                 $p .= '<td>??</td>';
                 continue;
             }
             $column->setValue($property->getValue());
             /* if a decorator has been declared for property/element, use it */
             if (isset($altDec[$column->getId()])) {
                 $column->setDecorator($altDec[$column->getId()]);
                 $deco = Decorator::factory($column);
                 $p .= sprintf('<td>%s</td>', $deco->render());
                 continue;
             }
             $attrib = sprintf(' class="tb-%s', $column->getId());
             $attrib .= $property instanceof Property\CurrencyProperty ? ' cellcurrency"' : '"';
             if ($column->getParameter('recursion')) {
                 $parts = $column->getParameter('recursion');
                 foreach ($parts as $rkey => $recursion) {
                     if ($property instanceof ArrayProperty) {
                         // property won't be a property here !
                         $property = $property->getValue();
                         $property = $property[$recursion];
                         if ($property instanceof BaseObject && isset($parts[$rkey + 1])) {
                             $property = $property->{$parts[$rkey + 1]};
                         }
                         break;
                     }
                     // property is an object property
                     if ($property instanceof AbstractProperty && $property->getValue()) {
                         $property = $property->getValue(ObjectModel::DATA)->getProperty($recursion);
                     }
                     if ($property instanceof ObjectModel || $property instanceof DataObject) {
                         $property = $property->getProperty($recursion);
                     } else {
                         if ($property instanceof ObjectUri) {
                             $property = ObjectModel::factory($property)->getProperty($recursion);
                         }
                     }
                 }
             }
             if ($property instanceof Property\MediaProperty) {
                 $column->setValue($property->getDisplayValue());
                 $deco = Decorator::factory($column);
                 $value = $deco->render();
             } else {
                 $value = $property instanceof Property\AbstractProperty ? $property->getDisplayValue() : $property;
             }
             //$p .= "<td$attrib>" . $this->_escape($value) . '</td>';
             $p .= "<td{$attrib}>" . $value . '</td>';
         }
         $p .= '<td class="tb-actions">';
         foreach ($this->_obj->getEvents('row') as $button) {
             $button->setParameter('uri', $this->_do->getUri());
             $p .= $this->_renderButton($button, $aliases[$this->_do->getUri()->getIdentifier()]);
         }
         $p .= '</td></tr>' . "\n";
     }
     return $p;
 }