Re: Tree reorder tweaking

2009-11-21 Thread Kerr
Zoe -- Sorry, I just now saw your reply!  You can use $this-Category-
reorder(); just like that to reorder the entire tree from top to
bottom... very handy!

On Nov 9, 10:19 am, MonkeyGirl z...@monkeehouse.com wrote:
 OK, so using $this-Category-reorder(); reorders all the children of
 a given category (in this example), and their children, and so on, but
 is there any way to reorder _all_ the categories, including the top
 level ones?

 I see now the point about my code not doing anything more than the
 original CakePHP code, as either way, nothing's reorganising the top
 level categories.  Either I'm missing something or that functionality
 simply isn't available, is that right?

 It's good to know that it's recursive though, that's great.

 Thanks,
 Zoe.

--

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-...@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.




Re: Tree reorder tweaking

2009-11-09 Thread MonkeyGirl

OK, so using $this-Category-reorder(); reorders all the children of
a given category (in this example), and their children, and so on, but
is there any way to reorder _all_ the categories, including the top
level ones?

I see now the point about my code not doing anything more than the
original CakePHP code, as either way, nothing's reorganising the top
level categories.  Either I'm missing something or that functionality
simply isn't available, is that right?

It's good to know that it's recursive though, that's great.

Thanks,
Zoe.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tree reorder tweaking

2009-11-02 Thread Kerr

Hi, I've been playing around with the tree functionality as well.
Looking at the code, you'll notice that the reorder method calls
itself recursively.  If you want to reorder the entire tree, simply
pass no arguments... e.g.

$this-reorder();

  Overall, I'm pretty impressed so far with how easy the tree methods
make it to deal with the adjacency list hierarchy model.  I've had to
code this kind of stuff from the ground up in SQL Server, and it was a
major PITA.

On Oct 29, 5:27 am, MonkeyGirl z...@monkeehouse.com wrote:
 Hi.

 I'm trying to order atreesuch that for any given node on thetree,
 all its children appear alphabetically, including the top level.

 If I understand thereorder() method correctly (it has sparse
 documentation athttp://book.cakephp.org/view/229/Advanced-Usage#reorder-518
 but the API 
 athttp://api.cakephp.org/class/tree-behavior#method-TreeBehaviorreorder
 is more informative), then you need to pass it the IDs that need
 editing.  I want toreorderthe whole entiretreethough, so I made my
 own reorderAll() method in /app/app_model.php:

   function reorderAll($options = array()) {
     $parentIDs = $this-find('list', array(
       'fields' = array(
         'parent_id'
       )
     ));

     $parentIDs = array_unique($parentIDs);

     foreach ($parentIDs as $parentID) {
       if (!empty($parentID)) {
         $options['id'] = $parentID;
         $this-reorder($options);
       }
     }
   }

 Is this a good way of approaching it?  The most obvious problem I can
 see at the moment is that the top level still isn't getting
 alphabetised, and I'm not sure how to do this.  I'm also still not
 sure ifreorder() recurses as far as it can, or just one level.

 Thanks for any help or suggestions!

 Zoe.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tree reorder tweaking

2009-11-02 Thread Kerr

To be more specific in addressing, I'm also still not
sure if reorder() recurses as far as it can, or just one level.  --
Yes, it will recurse the tree until it finds no children in all
affected branches.


On Nov 2, 8:25 pm, Kerr hayl...@gmail.com wrote:
 Hi, I've been playing around with thetreefunctionality as well.
 Looking at the code, you'll notice that thereordermethod calls
 itself recursively.  If you want toreorderthe entiretree, simply
 pass no arguments... e.g.

 $this-reorder();

   Overall, I'm pretty impressed so far with how easy thetreemethods
 make it to deal with the adjacency list hierarchy model.  I've had to
 code this kind of stuff from the ground up in SQL Server, and it was a
 major PITA.

 On Oct 29, 5:27 am, MonkeyGirl z...@monkeehouse.com wrote:

  Hi.

  I'm trying to order atreesuch that for any given node on thetree,
  all its children appear alphabetically, including the top level.

  If I understand thereorder() method correctly (it has sparse
  documentation athttp://book.cakephp.org/view/229/Advanced-Usage#reorder-518
  but the API 
  athttp://api.cakephp.org/class/tree-behavior#method-TreeBehaviorreorder
  is more informative), then you need to pass it the IDs that need
  editing.  I want toreorderthe whole entiretreethough, so I made my
  own reorderAll() method in /app/app_model.php:

    function reorderAll($options = array()) {
      $parentIDs = $this-find('list', array(
        'fields' = array(
          'parent_id'
        )
      ));

      $parentIDs = array_unique($parentIDs);

      foreach ($parentIDs as $parentID) {
        if (!empty($parentID)) {
          $options['id'] = $parentID;
          $this-reorder($options);
        }
      }
    }

  Is this a good way of approaching it?  The most obvious problem I can
  see at the moment is that the top level still isn't getting
  alphabetised, and I'm not sure how to do this.  I'm also still not
  sure ifreorder() recurses as far as it can, or just one level.

  Thanks for any help or suggestions!

  Zoe.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tree reorder tweaking

2009-11-02 Thread Robert P

Also note that one issue with your reorderAll() function is that it
loops through all non-empty parent IDs. The only problem with this is
that top-level items WILL have an empty parent.

On Nov 3, 10:27 am, Kerr hayl...@gmail.com wrote:
 To be more specific in addressing, I'm also still not
 sure if reorder() recurses as far as it can, or just one level.  --
 Yes, it will recurse the tree until it finds no children in all
 affected branches.

 On Nov 2, 8:25 pm, Kerr hayl...@gmail.com wrote:

  Hi, I've been playing around with thetreefunctionality as well.
  Looking at the code, you'll notice that thereordermethod calls
  itself recursively.  If you want toreorderthe entiretree, simply
  pass no arguments... e.g.

  $this-reorder();

    Overall, I'm pretty impressed so far with how easy thetreemethods
  make it to deal with the adjacency list hierarchy model.  I've had to
  code this kind of stuff from the ground up in SQL Server, and it was a
  major PITA.

  On Oct 29, 5:27 am, MonkeyGirl z...@monkeehouse.com wrote:

   Hi.

   I'm trying to order atreesuch that for any given node on thetree,
   all its children appear alphabetically, including the top level.

   If I understand thereorder() method correctly (it has sparse
   documentation 
   athttp://book.cakephp.org/view/229/Advanced-Usage#reorder-518
   but the API 
   athttp://api.cakephp.org/class/tree-behavior#method-TreeBehaviorreorder
   is more informative), then you need to pass it the IDs that need
   editing.  I want toreorderthe whole entiretreethough, so I made my
   own reorderAll() method in /app/app_model.php:

     function reorderAll($options = array()) {
       $parentIDs = $this-find('list', array(
         'fields' = array(
           'parent_id'
         )
       ));

       $parentIDs = array_unique($parentIDs);

       foreach ($parentIDs as $parentID) {
         if (!empty($parentID)) {
           $options['id'] = $parentID;
           $this-reorder($options);
         }
       }
     }

   Is this a good way of approaching it?  The most obvious problem I can
   see at the moment is that the top level still isn't getting
   alphabetised, and I'm not sure how to do this.  I'm also still not
   sure ifreorder() recurses as far as it can, or just one level.

   Thanks for any help or suggestions!

   Zoe.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Tree reorder tweaking

2009-11-02 Thread Kerr

One more note, MonkeyGirl, and I'm sure we're already on the same
page, but the syntax should be $this-ModelName-reorder();  Using the
categories example from http://book.cakephp.org/view/228/Basic-Usage
, the syntax to reorder the entire tree by name is $this-Category-
reorder();

On Nov 2, 9:22 pm, Robert P shiftyrobs...@gmail.com wrote:
 Also note that one issue with your reorderAll() function is that it
 loops through all non-empty parent IDs. The only problem with this is
 that top-level items WILL have an empty parent.

 On Nov 3, 10:27 am, Kerr hayl...@gmail.com wrote:

  To be more specific in addressing, I'm also still not
  sure ifreorder() recurses as far as it can, or just one level.  --
  Yes, it will recurse thetreeuntil it finds no children in all
  affected branches.

  On Nov 2, 8:25 pm, Kerr hayl...@gmail.com wrote:

   Hi, I've been playing around with thetreefunctionality as well.
   Looking at the code, you'll notice that thereordermethod calls
   itself recursively.  If you want toreorderthe entiretree, simply
   pass no arguments... e.g.

   $this-reorder();

     Overall, I'm pretty impressed so far with how easy thetreemethods
   make it to deal with the adjacency list hierarchy model.  I've had to
   code this kind of stuff from the ground up in SQL Server, and it was a
   major PITA.

   On Oct 29, 5:27 am, MonkeyGirl z...@monkeehouse.com wrote:

Hi.

I'm trying to order atreesuch that for any given node on thetree,
all its children appear alphabetically, including the top level.

If I understand thereorder() method correctly (it has sparse
documentation 
athttp://book.cakephp.org/view/229/Advanced-Usage#reorder-518
but the API 
athttp://api.cakephp.org/class/tree-behavior#method-TreeBehaviorreorder
is more informative), then you need to pass it the IDs that need
editing.  I want toreorderthe whole entiretreethough, so I made my
own reorderAll() method in /app/app_model.php:

  function reorderAll($options = array()) {
    $parentIDs = $this-find('list', array(
      'fields' = array(
        'parent_id'
      )
    ));

    $parentIDs = array_unique($parentIDs);

    foreach ($parentIDs as $parentID) {
      if (!empty($parentID)) {
        $options['id'] = $parentID;
        $this-reorder($options);
      }
    }
  }

Is this a good way of approaching it?  The most obvious problem I can
see at the moment is that the top level still isn't getting
alphabetised, and I'm not sure how to do this.  I'm also still not
sure ifreorder() recurses as far as it can, or just one level.

Thanks for any help or suggestions!

Zoe.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---