Example #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);
 }
 public function preDispatch()
 {
     $bootstrap = $this->getActionController()->getInvokeArg('bootstrap');
     $config = $bootstrap->getOptions();
     $controller = $this->getRequest()->getControllerName();
     if (isset($config['admin']['controllers']) && in_array($controller, $config['admin']['controllers'])) {
         Centurion_Db_Table_Abstract::setFiltersStatus(Centurion_Db_Table_Abstract::FILTERS_OFF);
     }
 }
Example #3
0
 /**
  * Convert the navigation DbTable object to Zend_Navigation.
  *
  * @return Zend_Navigation
  */
 public function toNavigation()
 {
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     //return new Zend_Navigation($this->_navigation($this->fetchAll('navigation_parent_id IS NULL')));
     //        $rowset = $this->fetchAll();
     //        $navigations = $this->_navigation2($rowset);
     $navigations = $this->_navigation($this->getRootNodes()->fetchAll());
     return $navigations;
 }
Example #4
0
 public function __toString()
 {
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     if ($this->getProxy() !== null) {
         Centurion_Db_Table_Abstract::restoreFiltersStatus();
         return $this->getProxy()->__toString();
     }
     Centurion_Db_Table_Abstract::restoreFiltersStatus();
     return $this->label;
 }
 public function getAction()
 {
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     $flatpageRow = $this->_helper->getObjectOr404('cms/flatpage', array('id' => $this->_getParam('id'), 'is_published' => 1, 'published_at__lt' => new Zend_Db_Expr('NOW()')));
     Centurion_Db_Table_Abstract::restoreFiltersStatus();
     Centurion_Cache_TagManager::addTag($flatpageRow);
     $navRow = Centurion_Db::getSingleton('core/navigation')->findOneByProxy($flatpageRow);
     if (null !== $navRow) {
         $navigation = $this->view->navigation()->getContainer();
         $this->view->currentNavigation = $navigation->findOneById($navRow->id);
     }
     return $this->renderToResponse($flatpageRow->flatpage_template->view_script, array('flatpageRow' => $flatpageRow));
 }
Example #6
0
 public function translateAction()
 {
     $form = $this->_getForm();
     $fromPk = $this->_controller->getRequest()->getParam('from');
     $targetLang = $this->_controller->getRequest()->getParam('lang');
     $this->_controller->getRequest()->setParam('from', null);
     $this->_controller->getRequest()->setParam('lang', null);
     $model = Centurion_Db::getSingletonByClassName(get_class($form->getModel()));
     Centurion_Db_Table_Abstract::setFiltersStatus(false);
     try {
         $row = $model->get(array('language_id' => $targetLang, 'original_id' => $fromPk));
         Centurion_Db_Table_Abstract::restoreFiltersStatus();
         $this->_form = null;
         $this->_controller->getRequest()->setParam('id', $row->id);
         self::$_filters = false;
         Centurion_Db_Table_Abstract::setFiltersStatus(self::$_filters);
         $this->getAction();
     } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) {
         $this->_controller->getRequest()->setParam(Centurion_Controller_CRUD::PARAM_FORM_VALUES, array('original_id' => $fromPk, 'language_id' => $targetLang));
         $this->newAction();
     }
 }
Example #7
0
 public function _getRawData($col)
 {
     $spec = $this->getTable()->getTranslationSpec();
     if ($this->_data[Translation_Traits_Model_DbTable::ORIGINAL_FIELD] && in_array($col, $spec[Translation_Traits_Model_DbTable::SET_NULL_FIELDS])) {
         Centurion_Db_Table_Abstract::setFiltersStatus(false);
         $originalRow = $this->getTable()->get(array('id' => $this->_data[Translation_Traits_Model_DbTable::ORIGINAL_FIELD]));
         Centurion_Db_Table_Abstract::setFiltersStatus(true);
         return $originalRow->{$col};
     }
     if (!array_key_exists($this->_prefix . $col, $this->_data) || !in_array($col, $spec[Translation_Traits_Model_DbTable::TRANSLATED_FIELDS])) {
         return $this->_data[$col];
     }
     if (Centurion_Config_Manager::get(Translation_Traits_Common::GET_DEFAULT_CONFIG_KEY, Translation_Traits_Common::NOT_EXISTS_GET_DEFAULT)) {
         if (null == $this->_data[$this->_prefix . $col]) {
             return $this->_data[$col];
         }
     }
     if (isset($this->_data[$this->_prefix . $col])) {
         return $this->_data[$this->_prefix . $col];
     } else {
         return $this->_data[$col];
     }
 }
Example #8
0
 /**
  * Creates a Centurion_Db_Table_Select containing root nodes.
  *
  * @return Centurion_Db_Table_Select
  */
 public function getRootNodesSelect()
 {
     Centurion_Db_Table_Abstract::setFiltersStatus(true);
     $select = $this->select(true, true)->filter(array(sprintf("%s", self::MPTT_LEFT) => 1));
     Centurion_Db_Table_Abstract::restoreFiltersStatus();
     return $select;
 }
Example #9
0
 protected function _generateRoutes()
 {
     $this->bootstrap('FrontController');
     $application = $this->getApplication();
     $application->bootstrap('router');
     $router = $application->getResource('router');
     $baseRoute = null;
     $this->_routePrefix = '';
     //TODO: put in cache !!!
     if (false === ($data = $this->_getCache('core')->load('Cms_Flatpage_Route'))) {
         if (Zend_Registry::isRegistered('Centurion_Route_Queue')) {
             $routeQueue = Zend_Registry::get('Centurion_Route_Queue');
             $r = reset($routeQueue);
             if (is_array($r)) {
                 $this->_routePrefix .= $r['name'] . '-';
                 $r = $r['route'];
             }
             while ($rn = next($routeQueue)) {
                 if (is_array($rn)) {
                     $this->_routePrefix .= $rn['name'] . '-';
                     $r = $r->chain($rn['route']);
                 } else {
                     $r = $r->chain($rn);
                 }
             }
             $baseRoute = $r;
         }
         $routes = array();
         $flatpageModel = Centurion_Db::getSingleton('cms/flatpage');
         Centurion_Db_Table_Abstract::setFiltersStatus(false);
         $flatpageRowset = $flatpageModel->select(true)->filter(array('is_published' => 1, 'published_at__lt' => new Zend_Db_Expr('NOW()')))->fetchAll();
         Centurion_Db_Table_Abstract::restoreFiltersStatus(true);
         foreach ($flatpageRowset as $key => $flatpageRow) {
             if ($flatpageRow->flatpage_type == Cms_Model_DbTable_Flatpage::NORMAL && trim($flatpageRow->url) !== '') {
                 $route = $flatpageRow->_getRoute();
                 $routes[sprintf('%sflatpage_%d', $this->_routePrefix, $flatpageRow->id)] = $route;
             }
         }
         $this->_getCache('core')->save(array($this->_routePrefix, $routes, $baseRoute), 'Cms_Flatpage_Route');
     } else {
         $this->_routePrefix = $data[0];
         $routes = $data[1];
         $baseRoute = $data[2];
     }
     Zend_Registry::set('ROUTE_PREFIX', $this->_routePrefix);
     foreach ($routes as $name => $route) {
         if (null !== $baseRoute) {
             $route = $baseRoute->chain($route);
         }
         $router->addRoute($name, $route);
     }
 }
Example #10
0
 /**
  * Retrieve the parent object.
  *
  * @return Centurion_Db_Table_Row_Mptt
  */
 public function getParent()
 {
     if (null === $this->_parent) {
         Centurion_Db_Table_Abstract::setFiltersStatus(false);
         //Not working because mptt_parent_id seems to not be updated all times
         //$return = $this->{$this->getTable()->getParentRefRule()};
         $select = $this->getAncestorsSelect();
         if ($select !== null) {
             $this->_parent = $select->fetchRow();
         } else {
             $this->_parent = null;
         }
         Centurion_Db_Table_Abstract::setFiltersStatus(true);
     }
     return $this->_parent;
 }
Example #11
0
 protected function _refresh()
 {
     $initialStatus = Centurion_Db_Table_Abstract::getFiltersStatus();
     Centurion_Db_Table_Abstract::setFiltersStatus(Centurion_Db_Table_Abstract::FILTERS_OFF);
     parent::_refresh();
     Centurion_Db_Table_Abstract::setFiltersStatus($initialStatus);
 }
Example #12
0
 protected function _buildOptions($table, $key, $nullable = false)
 {
     if (method_exists($table, 'buildOptions')) {
         return $table->buildOptions($nullable);
     }
     if (isset($this->_select[$key])) {
         if ($this->_select[$key] instanceof Centurion_Db_Table_Select) {
             $rowset = $table->fetchAll($this->_select[$key]);
         } else {
             if (is_array($this->_select[$key]) && is_callable($this->_select[$key])) {
                 $rowset = call_user_func_array($this->_select[$key], array($table->fetchAll($table->select(true))));
             } else {
                 if (is_array($this->_select[$key])) {
                     $rowset = $table->select(true)->filter($this->_select[$key])->fetchAll();
                 }
             }
         }
     } else {
         Centurion_Db_Table_Abstract::setFiltersStatus(true);
         $rowset = $table->getCache()->fetchAll();
         Centurion_Db_Table_Abstract::restoreFiltersStatus();
     }
     $options = true === $nullable ? array(null => '') : array();
     foreach ($rowset as $related) {
         $options[$related->id] = (string) $related;
     }
     return $options;
 }
Example #13
0
 protected function _postInitForm()
 {
     $id = $this->_getParam('id', null);
     if (null !== $id) {
         Centurion_Db_Table_Abstract::setFiltersStatus(false);
         $form = $this->_getForm();
         $object = $this->_getModel()->find($id)->current();
         $action = $this->_helper->url->url(array_merge($this->_extraParam, array('controller' => $this->_request->getControllerName(), 'id' => $id, 'action' => 'put', 'saving' => null, 'module' => $this->_request->getModuleName())), null, true);
         Centurion_Db_Table_Abstract::restoreFiltersStatus();
         $form->setAction($action);
         if (!$form->hasInstance()) {
             $form->setInstance($object);
         }
     }
 }