public function init() { $hasMaxRecordLimit = $this->getMaxRecordLimit() !== false; $maxRecordLimit = $this->getMaxRecordLimit(); if (!$this->results) { $cForCount = clone $this->getCriteria(); $cForCount->setOffset(0); $cForCount->setLimit(0); $cForCount->clearGroupByColumns(); } // require the model class (because autoloading can crash under some conditions) if (!($classPath = sfCore::getClassPath($this->getClassPeer()))) { throw new sfException(sprintf('Unable to find path for class "%s".', $this->getClassPeer())); } require_once $classPath; $count = count($this->getResults(true)); $this->setNbResults($hasMaxRecordLimit ? min($count, $maxRecordLimit) : $count); if (!$this->results) { $c = $this->getCriteria(); $c->setOffset(0); $c->setLimit(0); } else { $this->offset = 0; $this->limit = 0; } if ($this->getPage() == 0 || $this->getMaxPerPage() == 0) { $this->setLastPage(0); } else { $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage())); $offset = ($this->getPage() - 1) * $this->getMaxPerPage(); $this->offset = $offset; if ($c) { $c->setOffset($this->offset); } if ($hasMaxRecordLimit) { $maxRecordLimit = $maxRecordLimit - $offset; if ($maxRecordLimit > $this->getMaxPerPage()) { if ($c) { $c->setLimit($this->getMaxPerPage()); } $this->limit = $this->getMaxPerPage(); } else { if ($c) { $c->setLimit($maxRecordLimit); } $this->limit = $maxRecordLimit; } } else { if ($c) { $c->setLimit($this->getMaxPerPage()); } $this->limit = $this->getMaxPerPage(); } } }
public static function retrieveObjects($class, $peerMethod = null) { if (!($classPath = sfCore::getClassPath($class . 'Peer'))) { throw new sfException(sprintf('Unable to find path for class "%s".', $class . 'Peer')); } require_once $classPath; if (!$peerMethod) { $peerMethod = 'doSelect'; } $classPeer = $class . 'Peer'; if (!is_callable(array($classPeer, $peerMethod))) { throw new sfException(sprintf('Peer method "%s" not found for class "%s"', $peerMethod, $classPeer)); } $objects = call_user_func(array($classPeer, $peerMethod), new Criteria()); return $objects; }
public function getView($moduleName, $actionName, $viewName) { $file = sfConfig::get('sf_app_module_dir') . '/' . $moduleName . '/' . sfConfig::get('sf_app_module_view_dir_name') . '/' . $actionName . $viewName . 'View.class.php'; if (is_readable($file)) { require_once $file; $class = $actionName . $viewName . 'View'; $moduleClass = $moduleName . '_' . $class; if (class_exists($moduleClass, false)) { $class = $moduleClass; } } else { $viewName = $this->getContext()->getRequest()->getAttribute($moduleName . '_' . $actionName . '_view_name', sfConfig::get('mod_' . strtolower($moduleName) . '_view_class'), 'symfony/action/view'); $class = sfCore::getClassPath($viewName . 'View') ? $viewName . 'View' : 'sfPHPView'; } return new $class(); }
/** * Hook function to the Base Class function Save (post) * * @param array $object The name of the object * @param Connection $con The connection to use (specify Connection object to exert more control over transactions). * @return bool */ public function postDelete($object, $con = null) { if (!$object->isDeleted()) { return false; } $domain_id = 0; $changes = array(); if (get_class($object) == 'Record') { $peer_class = 'RecordPeer'; $domain_id = $object->getDomainId(); $classMapBuilder = 'RecordMapBuilder'; if (!($classPath = sfCore::getClassPath($classMapBuilder))) { throw new sfException(sprintf('Unable to find path for class "%s".', $classMapBuilder)); } require_once $classPath; $map = new $classMapBuilder(); $map->doBuild(); $tableMap = $map->getDatabaseMap()->getTable(constant($peer_class . '::TABLE_NAME')); foreach (call_user_func(array($peer_class, 'getFieldNames'), BasePeer::TYPE_COLNAME) as $column) { // do not keep track of changes for fields that are primary keys // or for the field 'updated_at' if ($tableMap->getColumn($column)->getColumnName() == 'UPDATED_AT') { continue; } if ($tableMap->getColumn($column)->isPrimaryKey()) { continue; } $column_phpname = call_user_func(array($peer_class, 'translateFieldName'), $column, BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME); $method = 'get' . sfInflector::camelize($column_phpname); $changes[$column_phpname] = $object->{$method}(); } } $this->save(get_class($object), $object->getPrimaryKey(), serialize($changes), $this->getLastQuery($con), self::TYPE_DELETE, $domain_id); }
/** * Loads the mappings for the classes * * @param string The model class name * * @throws sfException If the class cannot be found */ protected function loadMapBuilder($class) { $mapBuilderClass = $class . 'MapBuilder'; if (!isset($this->maps[$class])) { if (!($classPath = sfCore::getClassPath($mapBuilderClass))) { throw new sfException(sprintf('Unable to find path for class "%s".', $mapBuilderClass)); } require_once $classPath; $this->maps[$class] = new $mapBuilderClass(); $this->maps[$class]->doBuild(); } }