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)); }
public function getOriginal() { Centurion_Db_Table_Abstract::setFiltersStatus(false); $row = null; $columnName = 'original'; $referenceMap = $this->getTable()->info('referenceMap'); if (isset($referenceMap[$columnName])) { $column = $referenceMap[$columnName]['columns']; $className = $referenceMap[$columnName]['refTableClass']; $row = $this->findParentRow($referenceMap[$columnName]['refTableClass'], $columnName); } Centurion_Db_Table_Abstract::restoreFiltersStatus(); return $row; }
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(); } }
/** * 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; }
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); } }
/** * Magic method to get relationship. * * @param string $columnName Column name. * @return Centurion_Db_Table_Row_Abstract|Centurion_Db_Table_Rowset_Abstract */ public function __get($columnName) { $columnName = $this->_transformColumn($columnName); if (array_key_exists($columnName, $this->_specialGets)) { if (is_string($this->_specialGets[$columnName])) { if (!method_exists($this, $this->_specialGets[$columnName])) { throw new Centurion_Db_Table_Exception(sprintf("Specified method \"%s\" does not exist", $this->_specialGets[$columnName])); } else { return call_user_func(array($this, $this->_specialGets[$columnName])); } } elseif (is_array($this->_specialGets[$columnName]) && 2 == count($this->_specialGets[$columnName])) { if (is_object($this->_specialGets[$columnName][0]) && is_string($this->_specialGets[$columnName][1]) && method_exists($this->_specialGets[$columnName][0], $this->_specialGets[$columnName][1])) { return call_user_func_array($this->_specialGets[$columnName], array()); } else { if (!method_exists($this, (string) $this->_specialGets[$columnName][0])) { throw new Centurion_Db_Table_Exception(sprintf("Specified method \"%s\" does not exist", $this->_specialGets[$columnName][0])); } else { return call_user_func_array(array($this, $this->_specialGets[$columnName][0]), (array) $this->_specialGets[$columnName][1]); } } } } if (array_key_exists($columnName, $this->_data)) { return $this->_getRawData($columnName); } //TODO: cascade object__attribute__object__atribute... if (null !== ($pos = strpos($columnName, '+')) && $pos !== false) { $part1 = $this->{trim(substr($columnName, 0, $pos))}; $part2 = $this->{trim(substr($columnName, $pos + 1))}; return $part1 . '' . $part2; } if (null !== ($pos = strpos($columnName, '__')) && $pos !== false) { $row = $this->{substr($columnName, 0, $pos)}; if ($row == null) { return null; } return $row->{substr($columnName, $pos + 2)}; } $referenceMap = $this->getTable()->info('referenceMap'); if (isset($referenceMap[$columnName])) { $columns = $referenceMap[$columnName]['columns']; $className = $referenceMap[$columnName]['refTableClass']; if (is_string($columns)) { $pkValue = $this->{$columns}; } else { foreach ($columns as $column) { $pkValue[] = $this->{$column}; } $pkValue = md5(implode('___', $pkValue)); } if (!isset(self::$_relationship[$className][$pkValue])) { self::$_relationship[$className][$pkValue] = $this->findParentRow($referenceMap[$columnName]['refTableClass'], $columnName); } return self::$_relationship[$className][$pkValue]; } $dependentTables = $this->getTable()->info('dependentTables'); if (isset($dependentTables[$columnName])) { if (!isset($this->_children[$columnName])) { $this->_children[$columnName] = $this->findDependentRowset($dependentTables[$columnName]); } return $this->_children[$columnName]; } $manyDependentTables = $this->getTable()->info('manyDependentTables'); if (isset($manyDependentTables[$columnName])) { if (!isset($this->_children[$columnName])) { Centurion_Db_Table_Abstract::setFiltersStatus(true); $this->_children[$columnName] = $this->findManyToManyRowset($manyDependentTables[$columnName]['refTableClass'], $manyDependentTables[$columnName]['intersectionTable'], substr($manyDependentTables[$columnName]['columns']['local'], 0, -3), substr($manyDependentTables[$columnName]['columns']['foreign'], 0, -3)); $this->_children[$columnName]->setIntersectionColumns($manyDependentTables[$columnName]['columns']); Centurion_Db_Table_Abstract::restoreFiltersStatus(); } return $this->_children[$columnName]; } throw new Zend_Db_Table_Row_Exception("Specified column \"{$columnName}\" is not in the row"); }
/** * Magic method to get relationship. * * @param string $columnName Column name. * @return Centurion_Db_Table_Row_Abstract|Centurion_Db_Table_Rowset_Abstract */ public function __get($columnName) { $columnName = $this->_transformColumn($columnName); if (array_key_exists($columnName, $this->_specialGets)) { if (is_string($this->_specialGets[$columnName])) { if (!method_exists($this, $this->_specialGets[$columnName])) { throw new Zend_Db_Table_Row_Exception(sprintf("Specified method \"%s\" does not exist", $this->_specialGets[$columnName])); } else { return call_user_func(array($this, $this->_specialGets[$columnName])); } } elseif (is_array($this->_specialGets[$columnName]) && 2 == count($this->_specialGets[$columnName])) { if (is_object($this->_specialGets[$columnName][0]) && is_string($this->_specialGets[$columnName][1]) && method_exists($this->_specialGets[$columnName][0], $this->_specialGets[$columnName][1])) { return call_user_func_array($this->_specialGets[$columnName], array()); } else { if (!method_exists($this, (string) $this->_specialGets[$columnName][0])) { throw new Zend_Db_Table_Row_Exception(sprintf("Specified method \"%s\" does not exist", $this->_specialGets[$columnName][0])); } else { return call_user_func_array(array($this, $this->_specialGets[$columnName][0]), (array) $this->_specialGets[$columnName][1]); } } } } if (array_key_exists($columnName, $this->_data)) { return $this->_getRawData($columnName); } //TODO: cascade object__attribute__object__atribute... if (null !== ($pos = strpos($columnName, '+')) && $pos !== false) { $part1 = $this->{trim(substr($columnName, 0, $pos))}; $part2 = $this->{trim(substr($columnName, $pos + 1))}; return $part1 . '' . $part2; } if (null !== ($pos = strpos($columnName, '__')) && $pos !== false) { $row = $this->{substr($columnName, 0, $pos)}; if ($row == null) { return null; } return $row->{substr($columnName, $pos + 2)}; } $referenceMap = $this->getTable()->info('referenceMap'); if (isset($referenceMap[$columnName])) { $columns = $referenceMap[$columnName]['columns']; $className = $referenceMap[$columnName]['refTableClass']; if (is_string($columns)) { $pkValue = $this->{$columns}; } else { $pkValue = array(); foreach ($columns as $column) { $pkValue[] = $this->{$column}; } $pkValue = md5(implode('___', $pkValue)); } if (!isset(self::$_relationship[$className][$pkValue])) { self::$_relationship[$className][$pkValue] = $this->findParentRow($referenceMap[$columnName]['refTableClass'], $columnName); if (null === self::$_relationship[$className][$pkValue]) { self::$_relationship[$className][$pkValue] = false; } } if (false == self::$_relationship[$className][$pkValue]) { return null; } return self::$_relationship[$className][$pkValue]; } $dependentTables = $this->getTable()->info('dependentTables'); if (isset($dependentTables[$columnName])) { if (!isset($this->_children[$columnName])) { $this->_children[$columnName] = $this->findDependentRowset($dependentTables[$columnName]); } return $this->_children[$columnName]; } $manyDependentTables = $this->getTable()->info('manyDependentTables'); if (isset($manyDependentTables[$columnName])) { if (!isset($this->_children[$columnName])) { $data = $manyDependentTables[$columnName]; Centurion_Db_Table_Abstract::setFiltersStatus(true); $select = Centurion_Db::getSingletonByClassName($data['refTableClass'])->select(); $refForeignCond = null; if (isset($data['refforeigncond'])) { $refForeignCond = $data['refforeigncond']; } //TODO: this should be remove after. It's only for retrocompatibility if (!isset($data['refforeign']) && isset($data['columns'])) { $data['refforeign'] = substr($data['columns']['foreign'], 0, -3); $data['reflocal'] = substr($data['columns']['local'], 0, -3); } //Support of ordered many to many to avoid regression $intersectionTable = $data['intersectionTable']; if (is_string($intersectionTable)) { //this operation is also performed in the next call to findManyToManyRowset() $intersectionTable = $this->_getTableFromString($intersectionTable); } if (in_array('order', $intersectionTable->info('cols'))) { // Use adapter from intersection table to ensure correct query construction $interName = $intersectionTable->info(Centurion_Db_Table::NAME); //findManyToManyRowset() not perform this because we send a select object to the method $select->order($interName . '.order asc'); } $this->_children[$columnName] = $this->findManyToManyRowset($data['refTableClass'], $intersectionTable, $data['reflocal'], $data['refforeign'], $select, $refForeignCond); //todo: fix this //$this->_children[$columnName]->setIntersectionColumns($manyDependentTables[$extractedColumnName]['columns']); Centurion_Db_Table_Abstract::restoreFiltersStatus(); } return $this->_children[$columnName]; } throw new Zend_Db_Table_Row_Exception("Specified column \"{$columnName}\" is not in the row"); }
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; }
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); } } }