public function staticAttributes($builder)
 {
     $tableName = $this->table->getName();
     $col = '';
     if ($this->behavior->useScope()) {
         if ($this->behavior->hasMultipleScopes()) {
             foreach ($this->behavior->getScopes() as $scope) {
                 $col[] = "{$tableName}." . strtoupper($scope);
             }
             $col = json_encode($col);
             $col = "'{$col}'";
         } else {
             $colNames = $this->getColumnConstant('scope_column');
             $col = "'{$tableName}.{$colNames}'";
         }
     }
     return $this->behavior->renderTemplate('tableMapSortable', array('rankColumn' => $this->getColumnConstant('rank_column'), 'multiScope' => $this->behavior->hasMultipleScopes(), 'scope' => $col, 'tableName' => $this->table->getName(), 'useScope' => $this->behavior->useScope()));
 }
コード例 #2
0
 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";
 }
コード例 #4
0
 protected function addGetMaxRankArray(&$script)
 {
     $this->builder->declareClasses('Propel');
     $useScope = $this->behavior->useScope();
     $script .= "\n/**\n * Get the highest rank by a scope with a array format.\n * ";
     if ($useScope) {
         $script .= "\n * @param     int \$scope\t\tThe scope value as scalar type or array(\$value1, ...).\n";
     }
     $script .= "\n * @param     PropelPDO \$con optional connection\n * @return    int highest position\n */\npublic function getMaxRankArray(" . ($useScope ? "\$scope, " : "") . "PropelPDO \$con = null)\n{\n    if (\$con === null) {\n        \$con = Propel::getConnection({$this->peerClassname}::DATABASE_NAME);\n    }\n    // shift the objects with a position lower than the one of object\n    \$this->addSelectColumn('MAX(' . {$this->peerClassname}::RANK_COL . ')');";
     if ($useScope) {
         $script .= "\n    {$this->peerClassname}::sortableApplyScopeCriteria(\$this, \$scope);";
     }
     $script .= "\n    \$stmt = \$this->doSelect(\$con);\n\n    return \$stmt->fetchColumn();\n}\n";
 }