Development

Changeset 3519

You must first sign up to be able to contribute.

Changeset 3519

Show
Ignore:
Timestamp:
02/19/07 15:57:51 (2 years ago)
Author:
tristan
Message:

sfPropelActAsNestedSetBehaviorPlugin :

Implemented :

  • deleteChildren
  • deleteDescendants

releasing 0.7.0

Files:

Legend:

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

    r3512 r3519  
    164164=== Insertion methods === 
    165165 
    166  * {{{void insertAsFirstChildOf(BaseObject $dest_node)}}} : Inserts node as first child of given node. 
    167  * {{{void insertAsLastChildOf(BaseObject $dest_node)}}} : Inserts node as last child of given node. 
    168  * {{{void insertAsNextSiblingOf(BaseObject $dest_node)}}} : Inserts node as next sibling of given node. 
    169  * {{{void insertAsPrevSiblingOf(BaseObject $dest_node)}}} : Inserts node as previous sibling of given node. 
     166 * `void insertAsFirstChildOf(BaseObject $dest_node)` : Inserts node as first child of given node. 
     167 * `void insertAsLastChildOf(BaseObject $dest_node)` : Inserts node as last child of given node. 
     168 * `void insertAsNextSiblingOf(BaseObject $dest_node)` : Inserts node as next sibling of given node. 
     169 * `void insertAsPrevSiblingOf(BaseObject $dest_node)` : Inserts node as previous sibling of given node. 
     170 * `void insertAsParentOf(BaseObject $dest_node)` : '''NOT IMPLEMENTED YET''' 
    170171 
    171172=== Informational methods === 
    172173 
    173  * {{{bool hasChildren()}}} : Returns true if given node as one or several children. 
    174  * {{{bool isRoot()}}} : Returns true if given node is a root node. 
    175  * {{{bool hasParent()}}} : Returns true if given node has a parent node. 
    176  * {{{bool hasNextSibling()}}} : Returns true if given node has a next sibling. 
    177  * {{{bool hasPrevSibling()}}} : Returns true if given node has a previous sibling. 
    178  * {{{bool isLeaf()}}} : Returns true if given node does not have children. 
    179  * {{{integer getNumberOfChildren()}}} : Returns given node number of direct children. 
    180  * {{{integer getNumberOfDescendants()}}} : Returns given node number of descendants (n level). 
    181  * {{{integer getLevel()}}} : Returns given node level. 
     174 * `bool hasChildren()` : Returns true if given node as one or several children. 
     175 * `bool isRoot()` : Returns true if given node is a root node. 
     176 * `bool hasParent()` : Returns true if given node has a parent node. 
     177 * `bool hasNextSibling()` : Returns true if given node has a next sibling. 
     178 * `bool hasPrevSibling()` : Returns true if given node has a previous sibling. 
     179 * `bool isLeaf()` : Returns true if given node does not have children. 
     180 * `bool isChildOf()` : '''NOT IMPLEMENTED YET''' 
     181 * `bool isChildOfOrSiblingTo()` : '''NOT IMPLEMENTED YET''' 
     182 * `integer getNumberOfChildren()` : Returns given node number of direct children. 
     183 * `integer getNumberOfDescendants()` : Returns given node number of descendants (n level). 
     184 * `integer getLevel()` : Returns given node level. 
    182185 
    183186=== Node retrieval methods === 
    184187 
    185  * {{{array getChildren($peer_method = 'doSelect')}}} : Returns given node direct children. 
    186  * {{{array getDescendants($peer_method = 'doSelect')}}} : Returns given node descendants (n level). 
    187  * {{{BaseObject retrieveNextSibling()}}} : Returns given node next sibling. 
    188  * {{{BaseObject retrievePrevSibling()}}} : Returns given node previous sibling. 
    189  * {{{BaseObject retrieveFirstChild()}}} : Returns given node first child. 
    190  * {{{BaseObject retrieveLastChild()}}} : Returns given node last child. 
    191  * {{{BaseObject retrieveParent()}}} : Returns given node parent. 
    192  * {{{array getPath()}}} : Returns path to a specific node as an array, useful to create breadcrumbs. 
     188 * `array getChildren($peer_method = 'doSelect')` : Returns given node direct children. 
     189 * `array getDescendants($peer_method = 'doSelect')` : Returns given node descendants (n level). 
     190 * `BaseObject retrieveNextSibling()` : Returns given node next sibling. 
     191 * `BaseObject retrievePrevSibling()` : Returns given node previous sibling. 
     192 * `BaseObject retrieveFirstChild()` : Returns given node first child. 
     193 * `BaseObject retrieveLastChild()` : Returns given node last child. 
     194 * `BaseObject retrieveParent()` : Returns given node parent. 
     195 * `array retrieveSiblings()` : '''NOT IMPLEMENTED YET''' 
     196 * `array getPath()` : Returns path to a specific node as an array, useful to create breadcrumbs. 
    193197 
    194198=== Tree modification methods === 
    195199 
    196  * {{{void moveToFirstChildOf(BaseObject $dest_node)}}} : Moves node to first child of given node. 
    197  * {{{void moveToLastChildOf(BaseObject $dest_node)}}} : Moves node to last child of given node. 
    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. 
    200  * {{{void deleteChildren()}}} : '''NOT IMPLEMENTED YET''' 
    201  * {{{void deleteTree()}}} : '''NOT IMPLEMENTED YET''' 
     200 * `void moveToFirstChildOf(BaseObject $dest_node)` : Moves node to first child of given node. 
     201 * `void moveToLastChildOf(BaseObject $dest_node)` : Moves node to last child of given node. 
     202 * `void moveToNextSiblingOf(BaseObject $dest_node)` : Moves node to next sibling of given node. 
     203 * `void moveToPrevSiblingOf(BaseObject $dest_node)` : Moves node to previous sibling of given node. 
     204 * `void deleteChildren()` : Deletes node direct children 
     205 * `void deleteDescendants()` : Deletes node descendants (n level) 
    202206 
    203207=== Helper methods === 
    204208 
    205  * {{{void makeRoot()}}} : Sets node properties to make it a root node. 
    206  * {{{BaseObject reload()}}} : Returns an up to date version of node 
     209 * `void makeRoot()` : Sets node properties to make it a root node. 
     210 * `BaseObject reload()` : Returns an up to date version of node 
    207211 
    208212== Changelog == 
    209213 
    210 === trunk === 
    211  
    212 Implemented methods (+ unit tests) : 
     214=== 2007-02-19 | 0.7.0 === 
     215 
     216Implemented missing methods (+ unit tests) : 
    213217  
    214  * `moveToPrevSiblingOf`   
    215  * `moveToNextSiblingOf`   
     218 * `moveToPrevSiblingOf` 
     219 * `moveToNextSiblingOf` 
     220 * `deleteChildren` 
     221 * `deleteDescendants` 
    216222 
    217223=== 2007-02-19 | 0.6.2 === 
     
    221227=== 2007-02-15 | 0.6.1 === 
    222228 
    223 Fixed minor bug in getPath() 
     229Fixed minor bug in `getPath()` 
    224230 
    225231=== 2007-02-15 | 0.6.0 === 
     
    227233Implemented missing node retrieval methods :  
    228234 
    229  * retrieveFirstChild 
    230  * retrieveLastChild 
    231  * retrieveParent 
    232  * getPath 
     235 * `retrieveFirstChild` 
     236 * `retrieveLastChild` 
     237 * `retrieveParent` 
     238 * `getPath` 
    233239  
    234240Updated docs and unit tests accordingly 
     
    242248Initial public release. The behavior is stable and fully unit-tested, but the API is not yet complete. Missing methods : 
    243249 
    244  * retrieveFirstChild 
    245  * retrieveLastChild    
    246  * moveToPrevSiblingOf 
    247  * moveToNextSiblingOf 
    248  * deleteChildren 
    249  * deleteTree 
    250  * getPath  
     250 * `retrieveFirstChild` 
     251 * `retrieveLastChild` 
     252 * `moveToPrevSiblingOf` 
     253 * `moveToNextSiblingOf` 
     254 * `deleteChildren` 
     255 * `deleteTree` 
     256 * `getPath` 
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/config/config.php

    r3460 r3519  
    125125  array ( 
    126126    'sfPropelActAsNestedSetBehavior', 
     127    'deleteChildren' 
     128  ), 
     129  array ( 
     130    'sfPropelActAsNestedSetBehavior', 
     131    'deleteDescendants' 
     132  ), 
     133  array ( 
     134    'sfPropelActAsNestedSetBehavior', 
    127135    'retrieveFirstChild' 
    128136  ), 
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/lib/sfPropelActAsNestedSetBehavior.class.php

    r3512 r3519  
    673673  } 
    674674 
    675   public function deleteChildren() 
    676   { 
    677     throw new Exception(__FUNCTION__ . ' is not implemented'); 
    678   } 
    679  
    680   public function deleteTree() 
    681   { 
    682     throw new Exception(__FUNCTION__ . ' is not implemented'); 
     675  /** 
     676   * Deletes given node direct children. 
     677   *  
     678   * @param      BaseObject      $node 
     679   */ 
     680  public function deleteChildren(BaseObject $node) 
     681  { 
     682    // array_reverse() call is necessary for root node properties to be correctly updated 
     683    foreach (array_reverse($node->getChildren()) as $child) 
     684    { 
     685      $child->delete(); 
     686    } 
     687  } 
     688 
     689  /** 
     690   * Deletes all nodes below given node (n level). 
     691   *  
     692   * @param      BaseObject      $node 
     693   */ 
     694  public function deleteDescendants(BaseObject $node) 
     695  { 
     696    $peer_name = get_class($node->getPeer()); 
     697    $stub_name = get_class($node); 
     698     
     699    $c = new Criteria(); 
     700    $c1 = $c->getNewCriterion(self::getColumnConstant($stub_name, 'left'), $node->getLeftValue(), Criteria::GREATER_THAN); 
     701    $c2 = $c->getNewCriterion(self::getColumnConstant($stub_name, 'right'), $node->getRightValue(), Criteria::LESS_THAN); 
     702 
     703    $c1->addAnd($c2); 
     704 
     705    $c->add($c1); 
     706    $c->addDescendingOrderByColumn(self::getColumnConstant($stub_name, 'right')); 
     707 
     708    // Nodes are not directly deleted because we need to maintain adjacency list properties 
     709    $descendants = call_user_func(array($peer_name, 'doSelect'), $c); 
     710 
     711    foreach ($descendants as $descendant) 
     712    { 
     713      $descendant->delete(); 
     714    } 
     715     
     716    /* 
     717     * This is somewhat hackish... 
     718     *  
     719     * This implementation is probably more elegant :  
     720     * http://propel.phpdb.org/trac/browser/branches/1.3/generator/classes/propel/engine/builder/om/php5/PHP5NestedSetPeerBuilder.php?rev=501#L1139 
     721     */ 
     722    $node = $node->reload(); 
     723    $node->setRightValue($node->getRightValue() - 1); 
     724    $node->save(); 
    683725  } 
    684726   
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/package.xml

    r3504 r3519  
    1313 <date>2007-02-19</date> 
    1414 <version> 
    15    <release>0.6.2</release> 
    16    <api>0.6.2</api> 
     15   <release>0.7.0</release> 
     16   <api>0.7.0</api> 
    1717 </version> 
    1818 <stability> 
     
    5353 
    5454 <changelog> 
     55 
     56  <release> 
     57   <version> 
     58    <release>0.7.0</release> 
     59    <api>0.7.0</api> 
     60   </version> 
     61   <stability> 
     62    <release>beta</release> 
     63    <api>beta</api> 
     64   </stability> 
     65   <date>2007-02-19</date> 
     66   <license uri="http://www.symfony-project.com/license">MIT license</license> 
     67   <notes> 
     68Implemented missing methods (+ unit tests) : 
     69  
     70 * `moveToPrevSiblingOf` 
     71 * `moveToNextSiblingOf` 
     72 * `deleteChildren` 
     73 * `deleteDescendants` 
     74   </notes> 
     75  </release> 
    5576 
    5677  <release> 
  • plugins/sfPropelActAsNestedSetBehaviorPlugin/test/unit/PropelActAsNestedSetBehaviorTest.php

    r3512 r3519  
    2929 
    3030// -- path to the symfony project where the plugin resides 
    31 $sf_path = '/home/trivoallan/workspace/ipc-cb-trunk'; 
     31$sf_path = '/home/trivoallan/workspace/'; 
    3232  
    3333// bootstrap 
     
    792792$t->is($n4->getScopeIdValue(), $n8->getScopeIdValue(), 'N4 scope id equals N8 scope id'); 
    793793 
     794// deleteChildren 
     795$t = new lime_test(22, new lime_output_color()); 
     796$t->diag('deleteChildren'); 
     797$t->diag('Delete ROOT children'); 
     798$t->diag('root'); 
     799$t->diag(' |-N4'); 
     800$t->diag(' |-N8'); 
     801$t->diag('   |-N3'); 
     802$t->diag('   |-N6'); 
     803$t->diag(' |-N7'); 
     804 
     805$root->deleteChildren(); 
     806 
     807// -- reload nodes 
     808$n3 = $n3->reload(); 
     809$n4 = $n4->reload(); 
     810$n6 = $n6->reload(); 
     811$n7 = $n7->reload(); 
     812$n8 = $n8->reload(); 
     813$root = $root->reload(); 
     814 
     815$t->is($root->getLeftValue(), 1, 'root "left" is "1"'); 
     816$t->is($root->getRightValue(), 12, 'root "right" is "12"'); 
     817$t->is($n3->getLeftValue(), 5, 'N3 "left" is "5"'); 
     818$t->is($n3->getRightValue(), 6, 'N3 "right" is "6"'); 
     819$t->is($n3->getParentIdValue(), $n8->getPrimaryKey(), 'N3 parent is N8'); 
     820$t->is($n3->getScopeIdValue(), $n8->getScopeIdValue(), 'N3 scope id equals N8 scope id'); 
     821$t->is($n4->getLeftValue(), 2, 'N4 "left" is "2"'); 
     822$t->is($n4->getRightValue(), 3, 'N4 "right" is "3"'); 
     823$t->is($n4->getParentIdValue(), $root->getPrimaryKey(), 'N4 parent is ROOT'); 
     824$t->is($n4->getScopeIdValue(), $root->getScopeIdValue(), 'N4 scope id equals ROOT scope id'); 
     825$t->is($n6->getLeftValue(), 7, 'N6 "left" is "7"'); 
     826$t->is($n6->getRightValue(), 8, 'N6 "right" is "8"'); 
     827$t->is($n6->getParentIdValue(), $n8->getPrimaryKey(), 'N6 parent is N8'); 
     828$t->is($n6->getScopeIdValue(), $n8->getScopeIdValue(), 'N6 scope id equals N8 scope id'); 
     829$t->is($n7->getLeftValue(), 10, 'N7 "left" is "10"'); 
     830$t->is($n7->getRightValue(), 11, 'N7 "right" is "11"'); 
     831$t->is($n7->getParentIdValue(), $root->getPrimaryKey(), 'N7 parent is ROOT'); 
     832$t->is($n7->getScopeIdValue(), $root->getScopeIdValue(), 'N7 scope id equals ROOT scope id'); 
     833$t->is($n8->getLeftValue(), 4, 'N8 "left" is "4"'); 
     834$t->is($n8->getRightValue(), 9, 'N8 "right" is "9"'); 
     835$t->is($n8->getParentIdValue(), $root->getPrimaryKey(), 'N8 parent is ROOT'); 
     836$t->is($n8->getScopeIdValue(), $root->getScopeIdValue(), 'N8 scope id equals ROOT scope id'); 
     837 
     838// deleteDescendants 
     839$t = new lime_test(22, new lime_output_color()); 
     840$t->diag('deleteDescendants'); 
     841$t->diag('Delete N8 descendants'); 
     842$t->diag('root'); 
     843$t->diag(' |-N4'); 
     844$t->diag(' |-N8'); 
     845$t->diag(' |-N7'); 
     846 
     847// Insert this node for more meaningful unit test 
     848$n9 = _create_node(); 
     849$n9->insertAsLastChildOf($n6); 
     850$n9->save(); 
     851 
     852// -- reload nodes 
     853$n4 = $n4->reload(); 
     854$n7 = $n7->reload(); 
     855$n8 = $n8->reload(); 
     856$root = $root->reload(); 
     857 
     858$n8->deleteDescendants(); 
     859 
     860// -- reload nodes 
     861$n4 = $n4->reload(); 
     862$n7 = $n7->reload(); 
     863$n8 = $n8->reload(); 
     864$root = $root->reload(); 
     865 
     866$t->is($root->getLeftValue(), 1, 'root "left" is "1"'); 
     867$t->is($root->getRightValue(), 8, 'root "right" is "8"'); 
     868$t->is($n4->getLeftValue(), 2, 'N4 "left" is "2"'); 
     869$t->is($n4->getRightValue(), 3, 'N4 "right" is "3"'); 
     870$t->is($n4->getParentIdValue(), $root->getPrimaryKey(), 'N4 parent is ROOT'); 
     871$t->is($n4->getScopeIdValue(), $root->getScopeIdValue(), 'N4 scope id equals ROOT scope id'); 
     872$t->is($n7->getLeftValue(), 6, 'N7 "left" is "6"'); 
     873$t->is($n7->getRightValue(), 7, 'N7 "right" is "7"'); 
     874$t->is($n7->getParentIdValue(), $root->getPrimaryKey(), 'N7 parent is ROOT'); 
     875$t->is($n7->getScopeIdValue(), $root->getScopeIdValue(), 'N7 scope id equals ROOT scope id'); 
     876$t->is($n8->getLeftValue(), 4, 'N8 "left" is "4"'); 
     877$t->is($n8->getRightValue(), 5, 'N8 "right" is "5"'); 
     878$t->is($n8->getParentIdValue(), $root->getPrimaryKey(), 'N8 parent is ROOT'); 
     879$t->is($n8->getScopeIdValue(), $root->getScopeIdValue(), 'N8 scope id equals ROOT scope id'); 
     880 
    794881// Helper functions 
    795882