Ejemplo n.º 1
0
 public function testTrait()
 {
     $simpleTable = new Asset_Model_DbTable_Simple();
     //We make sure that we have nothing in the table
     $this->assertCount(0, $simpleTable);
     //We ensure that filter status is at true
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     //We create a row
     $row = $simpleTable->createRow();
     $row->save();
     //it's in the table
     $this->assertCount(1, $simpleTable);
     //We delete it
     $row->delete();
     //It should disappear from table
     $this->assertCount(0, $simpleTable);
     //Even if we set filter to false
     Centurion_Db_Table_Abstract::setFiltersStatus(false);
     $this->assertCount(0, $simpleTable);
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     //We make a injection to add trait to the table
     Centurion_Traits_Common::addTraits($simpleTable, 'Core_Traits_SoftDelete_Model_DbTable_Interface');
     //We create a new row
     $row = $simpleTable->createRow();
     $row->save();
     //It's in the table
     $this->assertCount(1, $simpleTable);
     //We remove it
     $row->delete();
     //The row is no more visible in table
     $this->assertCount(0, $simpleTable);
     //But this time it must be still here, but filtered by the trait.
     Centurion_Db_Table_Abstract::setFiltersStatus(false);
     $this->assertCount(1, $simpleTable);
 }
Ejemplo n.º 2
0
 public function __call($method, $args)
 {
     try {
         parent::__call($method, $args);
     } catch (Zend_Form_Exception $e) {
         list($found, $retVal) = Centurion_Traits_Common::checkTraitOverload($this, $method, $args);
         if ($found) {
             return $retVal;
         }
         throw $e;
     }
 }
Ejemplo n.º 3
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     Centurion_Signal::factory('pre_delete')->send($this, array($where));
     list($found, $return) = Centurion_Traits_Common::checkTraitOverload($this, 'delete', array($where));
     if (!$found) {
         $return = parent::delete($where);
     }
     Centurion_Signal::factory('post_delete')->send($this, array($where));
     return $return;
 }
Ejemplo n.º 4
0
 public function __call($method, array $args)
 {
     $lcMethod = strtolower($method);
     //TODO: change all substr by strncmp
     if (!strncmp($lcMethod, 'getnextby', 9)) {
         $by = substr($method, 9, strlen($method));
         $method = 'getNextBy';
     } else {
         if (substr($lcMethod, 0, 13) == 'getpreviousby') {
             $by = substr($method, 13, strlen($method));
             $method = 'getPreviousBy';
         } else {
             if (substr($lcMethod, 0, 10) == 'getfirstby') {
                 $by = substr($method, 10, strlen($method));
                 $method = 'getFirstBy';
             } else {
                 if (substr($lcMethod, 0, 9) == 'getlastby') {
                     $by = substr($method, 9, strlen($method));
                     $method = 'getLastBy';
                 } else {
                     if (substr($lcMethod, 0, 15) == 'getdateobjectby') {
                         $by = substr($method, 15, strlen($method));
                         $method = 'getDateObjectBy';
                     } else {
                         if (substr($lcMethod, 0, 16) == 'getpictureorpxby') {
                             $by = substr($method, 16, strlen($method));
                             $method = 'getPictureOrPxBy';
                         } else {
                             if (substr($lcMethod, 0, 3) == 'get' && preg_match('`get((.+)Or(.+))+`', $method)) {
                                 $lcMethod = substr($lcMethod, 3);
                                 $columns = explode('or', $lcMethod);
                                 foreach ($columns as $column) {
                                     if (isset($this->{$column}) && null !== $this->{$column}) {
                                         return $this->{$column};
                                     }
                                 }
                                 return null;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($by)) {
         return call_user_func_array(array($this, $method), array_merge(array($by), $args));
     }
     if (is_array($args) && count($args) == 1 && $args[0] instanceof Centurion_Db_Table_Select) {
         $columnName = $this->_transformColumn($method);
         $referenceMap = $this->getTable()->info('referenceMap');
         $select = $args[0];
         if (isset($referenceMap[$columnName])) {
             $column = $referenceMap[$columnName]['columns'];
             $className = $referenceMap[$columnName]['refTableClass'];
             if (!isset(self::$_relationship[$className][$this->{$column}])) {
                 self::$_relationship[$className][$this->{$column}] = $this->findParentRow($referenceMap[$columnName]['refTableClass'], $columnName, $select);
             }
             return self::$_relationship[$className][$this->{$column}];
         }
         $dependentTables = $this->getTable()->info('dependentTables');
         if (isset($dependentTables[$columnName])) {
             if (!isset($this->_children[$columnName])) {
                 $this->_children[$columnName] = $this->findDependentRowset($dependentTables[$columnName], null, $select);
             }
             return $this->_children[$columnName];
         }
         $manyDependentTables = $this->getTable()->info('manyDependentTables');
         if (isset($manyDependentTables[$columnName])) {
             if (!isset($this->_children[$columnName])) {
                 $this->_children[$columnName] = $this->findManyToManyRowset($manyDependentTables[$columnName]['refTableClass'], $manyDependentTables[$columnName]['intersectionTable'], null, null, $select);
                 $this->_children[$columnName]->setIntersectionColumns($manyDependentTables[$columnName]['columns']);
             }
             return $this->_children[$columnName];
         }
     }
     try {
         $retVal = parent::__call($method, $args);
     } catch (Zend_Db_Table_Row_Exception $e) {
         list($found, $retVal) = Centurion_Traits_Common::checkTraitOverload($this, $method, $args);
         if (!$found) {
             throw $e;
         }
     }
     return $retVal;
 }
Ejemplo n.º 5
0
 /**
  * Generate & display the grid with the filter form, toolbar action & pagination
  *
  * @return void
  */
 public function indexAction()
 {
     Centurion_Traits_Common::checkTraitOverload($this, 'indexAction', array(), false);
     // Get all the params used to generate the list
     $this->_getParams();
     $this->generateList();
     $this->_setViewParams();
     $this->renderIfNotExists('grid/list', null, true);
 }
Ejemplo n.º 6
0
 public function __call($method, $args)
 {
     $retVal = null;
     try {
         $retVal = parent::__call($method, $args);
     } catch (Zend_Controller_Action_Exception $e) {
         list($found, $retVal) = Centurion_Traits_Common::checkTraitOverload($this, $method, $args);
         if (!$found) {
             throw $e;
         }
     }
     return $retVal;
 }
Ejemplo n.º 7
0
 /**
  * Adds support for magic finders, inspired by Doctrine_Table.
  *
  * This method add support for calling methods not defined in code, such as:
  * findByColumnName, findByRelationAlias
  * findOneByColumnName, findOneByNotColumnName
  * findById, findByContactId, etc.
  *
  * @return Centurion_Db_Table_Row|Centurion_Db_Table_Rowset The result of the finder
  */
 public function __call($method, array $args)
 {
     $lcMethod = strtolower($method);
     if (substr($lcMethod, 0, 6) == 'findby') {
         $by = substr($method, 6, strlen($method));
         $method = '_findBy';
     } else {
         if (substr($lcMethod, 0, 9) == 'findoneby') {
             $by = substr($method, 9, strlen($method));
             $method = '_findOneBy';
         }
     }
     if (isset($by)) {
         if (!isset($args[0])) {
             throw new Centurion_Db_Table_Exception('You must specify the value to ' . $method);
         }
         return $this->{$method}($by, $args);
     }
     list($found, $retVal) = Centurion_Traits_Common::checkTraitOverload($this, $method, $args);
     if ($found) {
         return $retVal;
     }
     throw new Centurion_Db_Table_Exception(sprintf("method %s does not exist", $method));
 }
Ejemplo n.º 8
0
 protected function _preSave()
 {
     Centurion_Traits_Common::checkTraitOverload($this, '_preSave', array(), false);
 }
Ejemplo n.º 9
0
 /**
  * 
  * Generate Csv Function
  * @param int $itemPerPage
  * @param int $page
  */
 public function generateCsvAction($itemPerPage = 0, $page = 0)
 {
     Centurion_Traits_Common::checkTraitOverload($this, 'indexAction', array(), false);
     $this->_getParams();
     $this->_itemPerPage = $itemPerPage;
     $this->_page = $page;
     //create headers array
     $headers = array();
     $select = $this->_getSelect();
     $modelTable = $select->getTable();
     $naturals = $modelTable->info(Centurion_Db_Table_Abstract::COLS);
     $tabKeyUnset = array();
     foreach ($this->_displays as $key => $options) {
         if (is_array($options) && $options['type'] !== self::COLS_ROW_COL) {
             $tabKeyUnset[] = $key;
         } else {
             $headers[] = $options;
         }
     }
     $select = $this->generateList();
     //unset useless columns
     foreach ($select as $key => $row) {
         unset($row['checkbox']);
         unset($row['row']);
         foreach ($tabKeyUnset as $keyUnset => $rowUnset) {
             unset($row[$rowUnset]);
         }
         $rowSet[] = $row;
     }
     //generate csv
     if (null !== $rowSet) {
         $this->getHelper('Csv')->direct($rowSet, $headers);
     }
 }
Ejemplo n.º 10
0
 /**
  * Import from Centurion_Controller_CRUD to call trait to overload form rendering
  */
 public function _preRenderForm()
 {
     Centurion_Traits_Common::checkTraitOverload($this, '_preRenderForm', array(), false);
 }