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"; }
protected function addRemoveFromList(&$script) { $useScope = $this->behavior->useScope(); $script .= "\n/**\n * Removes the current object from the list" . ($useScope ? ' (moves it to the null scope)' : '') . ".\n * The modifications are not persisted until the object is saved.\n *\n * @return {$this->objectClassName} the current object\n */\npublic function removeFromList()\n{"; $script .= "\n // Keep the list modification query for the save() transaction\n \$this->sortableQueries[] = array(\n 'callable' => array('{$this->queryFullClassName}', 'sortableShiftRank'),\n 'arguments' => array(-1, \$this->{$this->getColumnGetter()}() + 1, null" . ($useScope ? ", \$this->getScopeValue()" : '') . ")\n );\n // remove the object from the list\n \$this->{$this->getColumnSetter('rank_column')}(null);\n "; if ($useScope) { $script .= "\n // check if object is already removed\n if (\$this->getScopeValue() === null) {\n throw new PropelException('Object is already removed (has null scope)');\n }\n\n // move the object to the end of null scope\n \$this->setScopeValue(null);\n"; } $script .= "\n\n return \$this;\n}\n"; }
protected function addShiftRank(&$script) { $useScope = $this->behavior->useScope(); $peerClassname = $this->peerClassname; $script .= "\n/**\n * Adds \$delta to all Rank values that are >= \$first and <= \$last.\n * '\$delta' can also be negative.\n *\n * @param int \$delta Value to be shifted by, can be negative\n * @param int \$first First node to be shifted\n * @param int \$last Last node to be shifted"; if ($useScope) { $script .= "\n * @param mixed \$scope Scope to use for the shift. Scalar value (single scope) or array"; } $script .= "\n * @param PropelPDO \$con Connection to use.\n */\npublic static function shiftRank(\$delta, \$first = null, \$last = null, " . ($useScope ? "\$scope = null, " : "") . "PropelPDO \$con = null)\n{\n if (\$con === null) {\n \$con = Propel::getConnection({$peerClassname}::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n \$whereCriteria = {$this->queryClassname}::create();\n if (null !== \$first) {\n \$whereCriteria->add({$peerClassname}::RANK_COL, \$first, Criteria::GREATER_EQUAL);\n }\n if (null !== \$last) {\n \$whereCriteria->addAnd({$peerClassname}::RANK_COL, \$last, Criteria::LESS_EQUAL);\n }"; if ($useScope) { $script .= "\n {$this->peerClassname}::sortableApplyScopeCriteria(\$whereCriteria, \$scope);"; } $script .= "\n\n \$valuesCriteria = new Criteria({$peerClassname}::DATABASE_NAME);\n \$valuesCriteria->add({$peerClassname}::RANK_COL, array('raw' => {$peerClassname}::RANK_COL . ' + ?', 'value' => \$delta), Criteria::CUSTOM_EQUAL);\n\n {$this->builder->getPeerBuilder()->getBasePeerClassname()}::doUpdate(\$whereCriteria, \$valuesCriteria, \$con);\n {$peerClassname}::clearInstancePool();\n}\n"; }
protected function getColumnConstant($name) { return strtoupper($this->behavior->getColumnForParameter($name)->getName()); }