コード例 #1
0
 /**
  * Add the rank_column to the current table
  */
 public function modifyTable()
 {
     $table = $this->getTable();
     if (!$table->containsColumn($this->getParameter('rank_column'))) {
         $table->addColumn(array('name' => $this->getParameter('rank_column'), 'type' => 'INTEGER'));
     }
     if ($this->useScope() && !$this->hasMultipleScopes() && !$table->containsColumn($this->getParameter('scope_column'))) {
         $table->addColumn(array('name' => $this->getParameter('scope_column'), 'type' => 'INTEGER'));
     }
     if ($this->useScope()) {
         $scopes = $this->getScopes();
         if (0 === count($scopes)) {
             throw new \InvalidArgumentException(sprintf('The sortable behavior in `%s` needs a `scope_column` parameter.', $this->getTable()->getName()));
         }
         foreach ($scopes as $scope) {
             $keys = $table->getColumnForeignKeys($scope);
             foreach ($keys as $key) {
                 if ($key->isForeignPrimaryKey() && $key->getOnDelete() == ForeignKey::SETNULL) {
                     $foreignTable = $key->getForeignTable();
                     $relationBehavior = new SortableRelationBehavior();
                     $relationBehavior->addParameter(array('name' => 'foreign_table', 'value' => $table->getName()));
                     $relationBehavior->addParameter(array('name' => 'foreign_scope_column', 'value' => $scope));
                     $relationBehavior->addParameter(array('name' => 'foreign_rank_column', 'value' => $this->getParameter('rank_column')));
                     $foreignTable->addBehavior($relationBehavior);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Add the rank_column to the current table
  */
 public function modifyTable()
 {
     $table = $this->getTable();
     if (!$table->containsColumn($this->getParameter('rank_column'))) {
         $table->addColumn(array('name' => $this->getParameter('rank_column'), 'type' => 'INTEGER'));
     }
     if ($this->useScope() && !$table->containsColumn($this->getParameter('scope_column'))) {
         $table->addColumn(array('name' => $this->getParameter('scope_column'), 'type' => 'INTEGER'));
     }
     if ($this->useScope()) {
         $keys = $table->getColumnForeignKeys($this->getParameter('scope_column'));
         foreach ($keys as $key) {
             if ($key->isForeignPrimaryKey() && $key->getOnDelete() == ForeignKey::SETNULL) {
                 $foreignTable = $key->getForeignTable();
                 $relationBehavior = new SortableRelationBehavior();
                 $relationBehavior->addParameter(array('name' => 'foreign_table', 'value' => $table->getName()));
                 $relationBehavior->addParameter(array('name' => 'foreign_scope_column', 'value' => $this->getParameter('scope_column')));
                 $relationBehavior->addParameter(array('name' => 'foreign_rank_column', 'value' => $this->getParameter('rank_column')));
                 $foreignTable->addBehavior($relationBehavior);
             }
         }
     }
 }