Development

Changeset 3512

You must first sign up to be able to contribute.

Changeset 3512

Show
Ignore:
Timestamp:
02/19/07 14:02:29 (6 years ago)
Author:
tristan
Message:

sfPropelActAsNestedSetBehaviorPlugin :

Implemented methods (+ unit tests) :


  • moveToPrevSiblingOf
  • moveToNextSiblingOf
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/README

    r3505 r3512  
    196196 * {{{void moveToFirstChildOf(BaseObject $dest_node)}}} : Moves node to first child of given node. 
    197197 * {{{void moveToLastChildOf(BaseObject $dest_node)}}} : Moves node to last child of given node. 
    198  * {{{void moveToNextSiblingOf()}}} : '''NOT IMPLEMENTED YET''' 
    199  * {{{void moveToPrevSiblingOf()}}} : '''NOT IMPLEMENTED YET''' 
     198 * {{{void moveToNextSiblingOf(BaseObject $dest_node)}}} : Moves node to next sibling of given node. 
     199 * {{{void moveToPrevSiblingOf(BaseObject $dest_node)}}} : Moves node to previous sibling of given node. 
    200200 * {{{void deleteChildren()}}} : '''NOT IMPLEMENTED YET''' 
    201201 * {{{void deleteTree()}}} : '''NOT IMPLEMENTED YET''' 
     
    207207 
    208208== Changelog == 
     209 
     210=== trunk === 
     211 
     212Implemented methods (+ unit tests) : 
     213  
     214 * `moveToPrevSiblingOf`   
     215 * `moveToNextSiblingOf`   
    209216 
    210217=== 2007-02-19 | 0.6.2 === 
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/lib/sfPropelActAsNestedSetBehavior.class.php

    r3504 r3512  
    245245    $node->setScopeIdValue($dest_node->getScopeIdValue()); 
    246246    $node->setParentIdValue($dest_node->getPrimaryKey()); 
    247     $this->addPreSaveStackEntries($this->shiftRLValues(get_class($node->getPeer()), $node->getLeftValue(), 2, $dest_node->getScopeIdValue())); 
     247    $this->addPreSaveStackEntries($this->shiftRLValues(get_class($node->getPeer()),  
     248                                                       $node->getLeftValue(),  
     249                                                       2,  
     250                                                       $dest_node->getScopeIdValue())); 
    248251     
    249252    $dest_node->setRightValue($dest_node->getRightValue() + 2); 
     
    264267    $node->setParentIdValue($dest_node->getPrimaryKey()); 
    265268    $this->addPreSaveStackEntries($this->shiftRLValues(get_class($node->getPeer()),  
    266                                               $node->getLeftValue(),  
    267                                               2,  
    268                                               $dest_node->getScopeIdValue())); 
     269                                  $node->getLeftValue(),  
     270                                  2,  
     271                                  $dest_node->getScopeIdValue())); 
    269272     
    270273    $dest_node->setRightValue($dest_node->getRightValue() + 2); 
     
    293296     
    294297    $this->addPreSaveStackEntries($this->shiftRLValues(get_class($node->getPeer()),  
    295                                               $node->getLeftValue(), 
    296                                               2, 
    297                                               $dest_node->getScopeIdValue())); 
     298                                  $node->getLeftValue(), 
     299                                  2, 
     300                                  $dest_node->getScopeIdValue())); 
    298301  } 
    299302 
     
    320323     
    321324    $this->addPreSaveStackEntries($this->shiftRLValues(get_class($node->getPeer()),  
    322                                               $node->getLeftValue(), 
    323                                               2, 
    324                                               $dest_node->getScopeIdValue())); 
     325                                  $node->getLeftValue(), 
     326                                  2, 
     327                                  $dest_node->getScopeIdValue())); 
    325328 
    326329    $dest_node->setLeftValue($dest_node->getLeftValue() + 2); 
     
    644647  } 
    645648 
    646   public function moveToNextSiblingOf() 
    647   { 
    648     throw new Exception(__FUNCTION__ . ' is not implemented'); 
    649   } 
    650  
    651   public function moveToPrevSiblingOf() 
    652   { 
    653     throw new Exception(__FUNCTION__ . ' is not implemented'); 
     649  /** 
     650   * Moves node to next sibling of given node. 
     651   *  
     652   * @param      BaseObject      $node 
     653   * @param      BaseObject      $dest_node 
     654   */ 
     655  public function moveToNextSiblingOf(BaseObject $node, BaseObject $dest_node) 
     656  { 
     657    $node->setParentIdValue($dest_node->getParentIdValue()); 
     658    $node->setScopeIdValue($dest_node->getScopeIdValue()); 
     659    $this->addPreSaveStackEntries($this->getUpdateTreeQueries($node, $dest_node->getRightValue() + 1)); 
     660  } 
     661 
     662  /** 
     663   * Moves node to previous sibling of given node. 
     664   *  
     665   * @param      BaseObject      $node 
     666   * @param      BaseObject      $dest_node 
     667   */ 
     668  public function moveToPrevSiblingOf(BaseObject $node, BaseObject $dest_node) 
     669  { 
     670    $node->setParentIdValue($dest_node->getParentIdValue()); 
     671    $node->setScopeIdValue($dest_node->getScopeIdValue()); 
     672    $this->addPreSaveStackEntries($this->getUpdateTreeQueries($node, $dest_node->getLeftValue())); 
    654673  } 
    655674 
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/test/unit/PropelActAsNestedSetBehaviorTest.php

    r3504 r3512  
    2929 
    3030// -- path to the symfony project where the plugin resides 
    31 $sf_path = '/home/trivoallan/workspace/'; 
     31$sf_path = '/home/trivoallan/workspace/ipc-cb-trunk'; 
    3232  
    3333// bootstrap 
     
    702702$t->is($n7_path_ids, $target_path_ids, 'getPath() returns the right nodes'); 
    703703 
     704// moveToNextSiblingOf 
     705$t = new lime_test(18, new lime_output_color()); 
     706$t->diag('moveToNextSiblingOf'); 
     707$t->diag('Move N7 to next sibling of N8'); 
     708$t->diag('root'); 
     709$t->diag(' |-N1'); 
     710$t->diag('   |-N8'); 
     711$t->diag('     |-N3'); 
     712$t->diag('     |-N4'); 
     713$t->diag('     |-N6'); 
     714$t->diag('   |-N7'); 
     715$t->diag(' |-N5'); 
     716 
     717$n7->moveToNextSiblingOf($n8); 
     718$n7->save(); 
     719 
     720// -- reload nodes 
     721$n1 = $n1->reload(); 
     722$n3 = $n3->reload(); 
     723$n4 = $n4->reload(); 
     724$n5 = $n5->reload(); 
     725$n6 = $n6->reload(); 
     726$n7 = $n7->reload(); 
     727$n8 = $n8->reload(); 
     728$root = $root->reload(); 
     729 
     730$t->is($root->getLeftValue(), 1, 'root "left" is "1"'); 
     731$t->is($root->getRightValue(), 16, 'root "right" is "16"'); 
     732$t->is($n1->getLeftValue(), 2, 'N1 "left" is "2"'); 
     733$t->is($n1->getRightValue(), 13, 'N1 "right" is "13"'); 
     734$t->is($n3->getLeftValue(), 4, 'N3 "left" is "4"'); 
     735$t->is($n3->getRightValue(), 5, 'N3 "right" is "5"'); 
     736$t->is($n4->getLeftValue(), 6, 'N4 "left" is "6"'); 
     737$t->is($n4->getRightValue(), 7, 'N4 "right" is "7"'); 
     738$t->is($n5->getLeftValue(), 14, 'N5 "left" is "14"'); 
     739$t->is($n5->getRightValue(), 15, 'N5 "right" is "15"'); 
     740$t->is($n6->getLeftValue(), 8, 'N6 "left" is "8"'); 
     741$t->is($n6->getRightValue(), 9, 'N6 "right" is "9"'); 
     742$t->is($n7->getLeftValue(), 11, 'N7 "left" is "11"'); 
     743$t->is($n7->getRightValue(), 12, 'N7 "right" is "12"'); 
     744$t->is($n8->getLeftValue(), 3, 'N8 "left" is "3"'); 
     745$t->is($n8->getRightValue(), 10, 'N8 "right" is "10"'); 
     746$t->is($n7->getParentIdValue(), $n8->getParentIdValue(), 'N7 parent id equals N8 id'); 
     747$t->is($n7->getScopeIdValue(), $n8->getScopeIdValue(), 'N7 scope id equals N8 scope id'); 
     748 
     749// moveToPrevSiblingOf 
     750$t = new lime_test(18, new lime_output_color()); 
     751$t->diag('moveToNextSiblingOf'); 
     752$t->diag('Move N4 to next sibling of N8'); 
     753$t->diag('root'); 
     754$t->diag(' |-N1'); 
     755$t->diag('   |-N4'); 
     756$t->diag('   |-N8'); 
     757$t->diag('     |-N3'); 
     758$t->diag('     |-N6'); 
     759$t->diag('   |-N7'); 
     760$t->diag(' |-N5'); 
     761 
     762$n4->moveToPrevSiblingOf($n8); 
     763$n4->save(); 
     764 
     765// -- reload nodes 
     766$n1 = $n1->reload(); 
     767$n3 = $n3->reload(); 
     768$n4 = $n4->reload(); 
     769$n5 = $n5->reload(); 
     770$n6 = $n6->reload(); 
     771$n7 = $n7->reload(); 
     772$n8 = $n8->reload(); 
     773$root = $root->reload(); 
     774 
     775$t->is($root->getLeftValue(), 1, 'root "left" is "1"'); 
     776$t->is($root->getRightValue(), 16, 'root "right" is "16"'); 
     777$t->is($n1->getLeftValue(), 2, 'N1 "left" is "2"'); 
     778$t->is($n1->getRightValue(), 13, 'N1 "right" is "13"'); 
     779$t->is($n3->getLeftValue(), 6, 'N3 "left" is "6"'); 
     780$t->is($n3->getRightValue(), 7, 'N3 "right" is "7"'); 
     781$t->is($n4->getLeftValue(), 3, 'N4 "left" is "3"'); 
     782$t->is($n4->getRightValue(), 4, 'N4 "right" is "4"'); 
     783$t->is($n5->getLeftValue(), 14, 'N5 "left" is "14"'); 
     784$t->is($n5->getRightValue(), 15, 'N5 "right" is "15"'); 
     785$t->is($n6->getLeftValue(), 8, 'N6 "left" is "8"'); 
     786$t->is($n6->getRightValue(), 9, 'N6 "right" is "9"'); 
     787$t->is($n7->getLeftValue(), 11, 'N7 "left" is "11"'); 
     788$t->is($n7->getRightValue(), 12, 'N7 "right" is "12"'); 
     789$t->is($n8->getLeftValue(), 5, 'N8 "left" is "5"'); 
     790$t->is($n8->getRightValue(), 10, 'N8 "right" is "10"'); 
     791$t->is($n4->getParentIdValue(), $n8->getParentIdValue(), 'N4 parent id equals N8 id'); 
     792$t->is($n4->getScopeIdValue(), $n8->getScopeIdValue(), 'N4 scope id equals N8 scope id'); 
     793 
    704794// Helper functions 
    705795