protected function addReorder(&$script) { $this->builder->declareClasses('Propel'); $peerClassname = $this->peerClassname; $columnGetter = 'get' . $this->behavior->getColumnForParameter('rank_column')->getPhpName(); $columnSetter = 'set' . $this->behavior->getColumnForParameter('rank_column')->getPhpName(); $script .= "\n/**\n * Reorder a set of sortable objects based on a list of id/position\n * Beware that there is no check made on the positions passed\n * So incoherent positions will result in an incoherent list\n *\n * @param array \$order id => rank pairs\n * @param PropelPDO \$con optional connection\n * @return boolean true if the reordering took place, false if a database problem prevented it\n * @throws Exception\n */\npublic function reorder(array \$order, PropelPDO \$con = null)\n{\n if (\$con === null) {\n \$con = Propel::getConnection({$peerClassname}::DATABASE_NAME);\n }\n\n \$con->beginTransaction();\n try {\n \$ids = array_keys(\$order);\n \$objects = \$this->findPks(\$ids, \$con);\n foreach (\$objects as \$object) {\n \$pk = \$object->getPrimaryKey();\n if (\$object->{$columnGetter}() != \$order[\$pk]) {\n \$object->{$columnSetter}(\$order[\$pk]);\n \$object->save(\$con);\n }\n }\n \$con->commit();\n\n return true;\n } catch (Exception \$e) {\n \$con->rollback();\n throw \$e;\n }\n}\n"; }
/** * @param OMBuilder $builder * @return string */ public function queryMethods(OMBuilder $builder) { $builder->declareClasses('BasePeer'); $this->builder = $builder; $script = ''; $this->addSetCacheEnable($script); $this->addSetCacheDisable($script); $this->addIsCacheEnable($script); $this->addGetCacheKey($script); $this->addResetCacheKey($script); $this->addSetCacheKey($script); $this->addSetLocale($script); $this->addSetLifeTime($script); $this->addGetLifeTime($script); $this->addAdd($script); $this->addClear($script); $this->addFind($script); $this->addFindOne($script); $this->addPurgeFromCache($script); $this->addDeleteFromCache($script); return $script; }