Example #1
0
 public function __construct($model)
 {
     parent::__construct($model);
     $this->_model = $model;
     $this->_modelInfo = $this->_model->info();
     $this->checkForRequiredColumn();
 }
Example #2
0
 /**
  * In Many To Many case, add a specific object, ex: add a permission to an user.
  *
  * @param Centurion_Db_Table_Row_Abstract $object
  * @return void|Centurion_Db_Table_Row_Abstract
  */
 public function add($object)
 {
     if (null !== $this->getIntersectionColumns()) {
         if (is_string($this->_intersectionTableClass)) {
             $this->_intersectionTableClass = Centurion_Db::getSingletonByClassName($this->_intersectionTableClass);
         }
         list($intersectionRow, $created) = $this->_intersectionTableClass->getOrCreate(array($this->_intersectionColumns['local'] => $this->getRefRow()->pk, $this->_intersectionColumns['foreign'] => $object->pk));
         return $intersectionRow;
     }
 }
Example #3
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 init()
 {
     $controller = $this->getActionController();
     if (!($requestedLocale = $controller->getRequest()->getParam('language', false))) {
         $local = new Zend_Locale();
         $requestedLocale = $local->getLanguage();
     }
     if (is_array($requestedLocale)) {
         $requestedLocale = current($requestedLocale);
     }
     $requestedLocale = strtolower($requestedLocale);
     try {
         Centurion_Db::getSingleton('translation/language')->get(array('locale' => $requestedLocale));
     } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) {
         $requestedLocale = Translation_Traits_Common::getDefaultLanguage();
         $requestedLocale = $requestedLocale->locale;
     }
     Zend_Registry::get('Zend_Translate')->setLocale($requestedLocale);
     Zend_Locale::setDefault($requestedLocale);
     Zend_Registry::set('Zend_Locale', $requestedLocale);
     $options = Centurion_Db_Table_Abstract::getDefaultFrontendOptions();
     if (!isset($options['cache_id_prefix'])) {
         $options['cache_id_prefix'] = '';
     }
     $options['cache_id_prefix'] = $requestedLocale . '_' . $options['cache_id_prefix'];
     Centurion_Db_Table_Abstract::setDefaultFrontendOptions($options);
     //TODO: fix this when in test unit environment
     if (!APPLICATION_ENV === 'testing') {
         $this->getActionController()->getFrontController()->getParam('bootstrap')->getResource('cachemanager')->addIdPrefix($requestedLocale . '_');
     }
     if (Centurion_Config_Manager::get('translation.global_param')) {
         $this->getFrontController()->getRouter()->setGlobalParam('language', $requestedLocale);
     }
 }
Example #5
0
 /**
  * @return Centurion_Db_Table_Select
  */
 protected function _getSelect()
 {
     if (null === $this->_select) {
         $this->_select = $this->_model->select(true, true, false);
     }
     return $this->_select;
 }
 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 #7
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 #8
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     $pk = $this->fetchRow($where)->pk;
     $object = parent::delete($where);
     try {
         unset(self::$_sites[$pk]);
     } catch (Exception $e) {
     }
     return $object;
 }
 /**
  * Generic test for findOneBy method.
  */
 public function testFindOneBy()
 {
     return;
     $modelId = $this->_model->insert($this->_getData());
     $this->assertFalse(null === $modelId);
     if (is_array($modelId)) {
         $this->_data = call_user_func_array(array($this->_model, 'find'), array_values($modelId))->current()->toArray();
     } else {
         $this->_data = $this->_model->find($modelId)->current()->toArray();
     }
     foreach ($this->_getData() as $key => $value) {
         if (null === $value) {
             continue;
         }
         $method = 'findOneBy' . Centurion_Inflector::classify($key);
         $modelRow = $this->_model->{$method}($value);
         $this->assertEquals($this->_getData(), $modelRow->toArray(), sprintf('Method %s of %s object doesn\'t return the expected values', $method, get_class($this->_model)));
     }
 }
Example #10
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;
 }
Example #11
0
 protected function _initDb()
 {
     try {
         Zend_Db_Table_Abstract::setDefaultAdapter($this->getPluginResource('db')->getDbAdapter());
         Zend_Db_Table_Abstract::setDefaultMetadataCache($this->_getCache('core'));
         Centurion_Db_Table_Abstract::setDefaultBackendOptions(Centurion_Config_Manager::get('resources.cachemanager.class.backend.options'));
         Centurion_Db_Table_Abstract::setDefaultFrontendOptions(Centurion_Config_Manager::get('resources.cachemanager.class.frontend.options'));
     } catch (Exception $e) {
         exit($e->getMessage());
     }
 }
Example #12
0
    public function __construct($config = array())
    {
        $this->getDefaultAdapter()->query(<<<EOS
            CREATE TABLE test_multiple_pk (
            `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
            `title` VARCHAR( 255 ) NOT NULL ,
            PRIMARY KEY (  `id` ,  `title` )
            ) ENGINE = INNODB;
EOS
);
        parent::__construct($config);
    }
 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 #14
0
 public function insert(array $data)
 {
     if (!isset($data['width']) || $data['width'] == 0) {
         $data['width'] = (int) $this->_getWidth($data['local_filename']);
     }
     if (!isset($data['height']) || $data['height'] == 0) {
         $data['height'] = (int) $this->_getHeight($data['local_filename']);
     }
     if (!isset($data['duration']) || $data['duration'] == 0) {
         $data['duration'] = $this->_getDuration($data['local_filename']);
     }
     $data[Centurion_Db_Table_Abstract::VERBOSE] = false;
     return parent::insert($data);
 }
Example #15
0
 /**
  * add filters to the default select query
  * @param $select Zend_Db_Table_Select
  * @see Core_Traits_Version_Model_DbTable::onSelect()
  */
 public function onJoinInner($signal, $sender, $select, $name)
 {
     if (!$select instanceof Centurion_Db_Table_Select) {
         return;
     }
     if (is_array($name)) {
         $name = current($name);
     }
     if ($name !== $this->_model->info(Zend_Db_Table_Abstract::NAME)) {
         return;
     }
     if (!Centurion_Db_Table_Abstract::getFiltersStatus()) {
         return;
     }
     $select->order('auth_user.order asc');
 }
Example #16
0
 /**
  * add filters to the default select query
  * @see Centurion/Contrib/core/traits/Version/Model/Core_Traits_Version_Model_DbTable::onSelect()
  */
 public function onJoinInner($signal, $sender, $select, $name)
 {
     if (!$select instanceof Centurion_Db_Table_Select) {
         return;
     }
     if (is_array($name)) {
         $name = current($name);
     }
     if ($name !== $this->_model->info(Zend_Db_Table_Abstract::NAME)) {
         return;
     }
     if (!Centurion_Db_Table_Abstract::getFiltersStatus()) {
         return;
     }
     /**
      * @TODO: add manage of alias
      */
     $select->where($name . '.is_deleted  = 0');
 }
Example #17
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 #18
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 #19
0
 public function update(array $data, $where)
 {
     $currentFileRow = $this->fetchRow($where);
     if (null !== $currentFileRow->proxy_model) {
         $oldProxyTableClass = $currentFileRow->proxy_model;
     }
     foreach ($currentFileRow->duplicates as $duplicate) {
         $duplicate->delete();
     }
     foreach ($this->_dependentProxies as $key => $dependentProxy) {
         $proxyTable = Centurion_Db::getSingletonByClassName($dependentProxy);
         $mimes = array_keys($proxyTable->getMimeTypes());
         if (!in_array($data['mime'], $mimes)) {
             continue;
         }
         if (in_array($data['mime'], $mimes)) {
             $newProxyTableClass = $dependentProxy;
             break;
         }
     }
     if (!isset($data['sha1'])) {
         $data['sha1'] = sha1_file(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']);
     }
     if (isset($oldProxyTableClass) && $oldProxyTableClass != $newProxyTableClass) {
         $currentProxyRow = Centurion_Db::getRow($oldProxyTableClass, $currentFileRow->proxy_pk);
         if (null !== $currentProxyRow) {
             $data = array_merge($data, array('proxy_model' => null, 'proxy_pk' => null));
             $currentProxyRow->delete();
         }
     }
     if (null !== $newProxyTableClass) {
         $newProxyTable = Centurion_Db::getSingletonByClassName($newProxyTableClass);
         if (isset($oldProxyTableClass) && $oldProxyTableClass == $newProxyTableClass) {
             $pk = $newProxyTable->update($data, $newProxyTable->getAdapter()->quoteInto('id = ?', $currentFileRow->proxy_pk));
         } else {
             $pk = $newProxyTable->insert($data);
             $data['proxy_model'] = $newProxyTableClass;
         }
         $data['proxy_pk'] = $pk;
     }
     if (array_key_exists(self::BELONG_TO, $data)) {
         list($model, $pk) = $this->_setupProxyBelong($data[self::BELONG_TO]);
         $data = array_merge($data, array('belong_model' => $model, 'belong_pk' => $pk));
         unset($data[self::BELONG_TO]);
     }
     return parent::update($data, $where);
 }
Example #20
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 #21
0
 /**
  * Set the default frontend options for all tables.
  *
  * @param array $options
  * @return void
  */
 public static function setDefaultFrontendOptions(array $options = array())
 {
     self::$_defaultFrontendOptions = $options;
 }
Example #22
0
 public function setFilters($filters)
 {
     $this->cleanForm();
     foreach ($filters as $key => &$filterData) {
         if (!is_array($filterData)) {
             $filterData = array('label' => $filterData);
             if ($this->_table !== null) {
                 $reference = $this->_table->info(Centurion_Db_Table_Abstract::REFERENCE_MAP);
                 if (isset($reference[$key])) {
                     $refTable = Centurion_Db::getSingletonByClassName($reference[$key]['refTableClass']);
                     $rowset = $refTable->all();
                     $data = array();
                     foreach ($rowset as $row) {
                         $data[] = (string) $row;
                     }
                     $filterData['type'] = Centurion_Controller_CRUD::FILTER_TYPE_CHECKBOX;
                     $filterData['data'] = $data;
                 }
             }
         }
         if (isset($filterData['label'])) {
             $label = $filterData['label'];
         } else {
             $label = '';
         }
         $checkboxType = 'multiCheckbox';
         $element = null;
         if (!isset($filterData['type'])) {
             $filterData['type'] = Centurion_Controller_CRUD::FILTER_TYPE_TEXT;
         }
         if (!isset($filterData['column'])) {
             $filterData['column'] = $key;
         }
         if (!isset($filterData['behavior'])) {
             $filterData['behavior'] = Centurion_Controller_CRUD::FILTER_BEHAVIOR_CONTAINS;
         }
         switch ($filterData['type']) {
             case Centurion_Controller_CRUD::FILTER_TYPE_RADIO:
                 $checkboxType = 'radio';
             case Centurion_Controller_CRUD::FILTER_TYPE_SELECT:
                 if ($checkboxType === 'multiCheckbox') {
                     $checkboxType = 'select';
                 }
             case Centurion_Controller_CRUD::FILTER_TYPE_CHECKBOX:
                 $element = $this->createElement($checkboxType, $key, array('label' => $label));
                 if (!isset($filterData['data'])) {
                     $manyDependentTables = $this->_table->info('manyDependentTables');
                     if (isset($manyDependentTables[$key])) {
                         $refRowSet = Centurion_Db::getSingletonByClassName($manyDependentTables[$key]['refTableClass'])->fetchAll();
                         $filterData['data'] = array();
                         foreach ($refRowSet as $refRow) {
                             $filterData['data'][$refRow->id] = $refRow->__toString();
                         }
                         asort($filterData['data']);
                     }
                 }
                 $element->addMultiOptions($filterData['data']);
                 $element->setSeparator('');
                 if ($checkboxType === 'multiCheckbox') {
                     $element->setIsArray(true);
                 }
                 break;
             case Centurion_Controller_CRUD::FILTER_TYPE_TEXT:
             case Centurion_Controller_CRUD::FILTER_TYPE_NUMERIC:
                 $element = $this->createElement('text', $key, array('label' => $label));
                 break;
             case Centurion_Controller_CRUD::FILTER_TYPE_DATE:
                 $element = $this->createElement('text', $key, array('label' => $label, 'class' => 'datepicker'));
                 break;
             case Centurion_Controller_CRUD::FILTER_TYPE_BETWEEN_DATE:
             case Centurion_Controller_CRUD::FILTER_TYPE_BETWEEN_DATETIME:
                 $form = new self();
                 if ($filterData['type'] == Centurion_Controller_CRUD::FILTER_TYPE_BETWEEN_DATETIME) {
                     $class = 'field-datetimepicker';
                 } else {
                     $class = 'datepicker';
                 }
                 $element = $form->createElement('text', 'gt', array('class' => $class, 'belongsTo' => $key, 'label' => $this->_translate('From'), 'value' => '26/08/11 03:00'));
                 $form->addElement($element, 'gt');
                 $element = $form->createElement('text', 'lt', array('class' => $class, 'belongsTo' => $key, 'label' => $this->_translate('To'), 'value' => '26/08/11 03:00'));
                 $form->addElement($element, 'lt');
                 $element = null;
                 $form->setDescription($label);
                 $this->addSubForm($form, $key);
                 $this->getSubForm($key)->setDecorators($this->defaultDisplayGroupDecorators);
                 $form->getElement('lt')->setDecorators($this->defaultElementDecoratorsInDisplayGroup);
                 $form->getElement('gt')->setDecorators($this->defaultElementDecoratorsInDisplayGroup);
                 //                    $this->addDisplayGroup(array('lt', 'gt'), $key, array('description' => $label));
                 break;
         }
         if (null !== $element) {
             $this->addElement($element, $key);
         }
     }
     $this->_filters = $filters;
 }
Example #23
0
 public function errorAction()
 {
     $this->view->headMeta()->appendName('robots', 'noindex,follow');
     $this->view->headTitle()->prepend('Error - ');
     $cachePage = $this->getInvokeArg('bootstrap')->getResource('cachemanager')->getCache('_page');
     if (null !== $cachePage && method_exists($cachePage, 'cancel')) {
         $cachePage->cancel();
     }
     $cachePage = $this->getInvokeArg('bootstrap')->getResource('cachemanager')->getCache('page');
     if (null !== $cachePage && method_exists($cachePage, 'cancel')) {
         $cachePage->cancel();
     }
     if ($this->_httpCode) {
         $this->getResponse()->setHttpResponseCode($this->_httpCode);
     }
     $params = array();
     if ($log = $this->_getLog()) {
         if ($this->_exception) {
             if (method_exists($this->_request, 'getRequestUri')) {
                 $uri = $this->_request->getRequestUri();
             } else {
                 $uri = $this->view->url();
             }
             $referer = '';
             if (isset($_SERVER['HTTP_REFERER'])) {
                 $referer = ' (' . $_SERVER['HTTP_REFERER'] . ')';
             }
             $log->log(sprintf("%d: \n%s \n%s: %s\n\n%s\n\n", $this->_httpCode, $uri, $referer, $this->_exception->exception->getMessage(), $this->_exception->exception->getTraceAsString()), $this->_priority);
         }
     }
     if ($this->getInvokeArg('displayExceptions') == true) {
         $params = array();
         if ($this->_exception) {
             $params = array('exception' => $this->_exception->exception, 'trace' => Zend_Debug::dump($this->_exception->exception->getTraceAsString(), null, false));
         }
         $params['profiler'] = Centurion_Db_Table_Abstract::getDefaultAdapter()->getProfiler()->getQueryProfiles(null, true);
         $this->renderToResponse(array('error/error-dev.phtml', 'centurion/error.phtml'), $params);
     } else {
         $this->renderToResponse(array('error/error.phtml', 'centurion/error.phtml'), $params);
     }
 }
Example #24
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 #25
0
 public function update(array $data, $where)
 {
     return parent::update($this->_getImageSize($data['local_filename']), $where);
 }
Example #26
0
 /**
  * add filters to the default select query
  * @see Centurion/Contrib/core/traits/Version/Model/Core_Traits_Version_Model_DbTable::onSelect()
  */
 public function onJoinInner($signal, $sender, $select, $name)
 {
     if (!$select instanceof Centurion_Db_Table_Select) {
         return;
     }
     $corellationName = 0;
     if (is_array($name)) {
         $corellationName = key($name);
         $name = current($name);
     }
     if (0 === $corellationName) {
         $corellationName = $name;
     }
     if ($name !== $this->_modelName) {
         return;
     }
     if (!Centurion_Db_Table_Abstract::getFiltersStatus()) {
         return;
     }
     $childName = 'child_' . $corellationName;
     //$this->_modelName;
     if (array_key_exists($childName, $select->getPart(Centurion_Db_Table_Select::FROM))) {
         return;
     }
     $select->setIntegrityCheck(false);
     $currentLanguage = Translation_Model_DbTable_Language::getCurrentLanguageInfo();
     /*
     $currentLocale = Zend_Registry::get('Zend_Translate')->getLocale();
     $session = new Zend_Session_Namespace('translation_current');
     
     if (!isset($session->language) || $session->language['locale'] != $currentLocale) {
         try {
             $languageRow = Centurion_Db::getSingleton('translation/language')->get(array('locale' => $currentLocale));
         } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) {
             $languageRow = Translation_Traits_Common::getDefaultLanguage();
         }
     
         $session->language = $languageRow->toArray();
     }
     */
     //        if ($this->_model->ifNotExistsGetDefault()) {
     //            if ($session->language['locale'] == Centurion_Config_Manager::get('translation.default_language', false)) {
     //                $select->filter(array('language_id' => $session->language['id']));
     //                return;
     //            }
     //        }
     $originalCols = array();
     $childCols = array();
     $spec = $this->getTranslationSpec();
     //foreach ($this->_modelInfo[Centurion_Db_Table_Abstract::COLS] as $col) {
     foreach ($spec[Translation_Traits_Model_DbTable::TRANSLATED_FIELDS] as $col) {
         array_push($childCols, sprintf('%s.%s AS %s%s', $childName, $col, $this->_localizedColsPrefix, $col));
         array_push($originalCols, sprintf('%s.%s', $this->_modelInfo[Centurion_Db_Table_Abstract::NAME], $col));
     }
     $tableName = $this->_modelInfo[Centurion_Db_Table_Abstract::NAME];
     $joined = false;
     foreach ($select->getPart(Zend_Db_Select::FROM) as $key => $val) {
         if (strcmp($val['tableName'], $tableName) === 0) {
             $joined = true;
             $alias = $key;
         }
     }
     if (!$joined) {
         $select->from($this->_modelInfo[Centurion_Db_Table_Abstract::NAME], new Zend_Db_Expr(implode(', ', $originalCols)));
         $alias = $tableName;
     }
     $select->where(sprintf('%s.original_id IS NULL', $alias));
     //        if ($this->_model->ifNotExistsGetDefault())
     $method = 'joinLeft';
     //        else
     //            $method = 'joinInner';
     $select->{$method}(sprintf('%s AS ' . $childName, $this->_modelInfo[Centurion_Db_Table_Abstract::NAME]), new Zend_Db_Expr(sprintf($childName . '.original_id = %s.id AND ' . $childName . '.language_id = %s', $alias, $currentLanguage['id'])), new Zend_Db_Expr(implode(', ', $childCols)));
     if (!$this->_model->ifNotExistsGetDefault()) {
         $select->where(new Zend_Db_Expr(sprintf($childName . '.language_id = %u OR %s.language_id = %u', $currentLanguage['id'], $alias, $currentLanguage['id'])));
     }
 }
 public function filterCaseInsensitive($value, &$sqlFilter)
 {
     $sqlFilter[] = new Zend_Db_Expr(Centurion_Db_Table_Abstract::getDefaultAdapter()->quoteInto('uid like ? COLLATE utf8_general_ci', '%' . $value . '%'));
 }
Example #28
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 #29
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 #30
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;
 }