Re: Want generatetreelist() results in alphabetical order
On Nov 22, 1:09 am, AD7six andydawso...@gmail.com wrote: I'd recommend looking at the reorder method, which'll do what you want to the data itself, unless you're wanting to sort by a different field. http://api.cakephp.org/view_source/tree-behavior/#l-628 Thanks, reorder() was in fact the first thing I tried. It did not reorder all the nodes as I desired, and as my solution in this thread does. Can't remember why. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Want generatetreelist() results in alphabetical order
On Nov 22, 3:55 am, Johnny Cupcake sparklew...@hotmail.com wrote: OK, I decided to bake up a solution myself. I don't contend that it is the fastest or the best, but it is simple and it seems to work. Since MPTT doesn't care about sibling order, getting the wrong result from generatetreelist just means your data is in the wrong order in the db. I'd recommend looking at the reorder method, which'll do what you want to the data itself, unless you're wanting to sort by a different field. http://api.cakephp.org/view_source/tree-behavior/#l-628 AD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
Want generatetreelist() results in alphabetical order
http://book.cakephp.org/view/1348/generatetreelist generatetreelist() returns a pseudo-tree in a relative order, with children under parents. I would like results wherein the peers are also ordered, alphabetically by label. Here is a quick example if this isn't clear: array( [1] = My Categories, [2] = _Fun, [3] = __Sport, [4] = ___Surfing, [16] = ___Skating, ) This array is not fully ordered (to my liking anyway). Surfing is above Skating, when it should be below. When an array contains dozens of elements like this, it is difficult to find what you are looking for (without alphabetical ordering). The only past online discussions I can find on this issue, end with If you want this solved, then write the function yourself. So my question is... has anyone wrote the solution yet? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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: Want generatetreelist() results in alphabetical order
OK, I decided to bake up a solution myself. I don't contend that it is the fastest or the best, but it is simple and it seems to work. Drop these two functions into your model and call the first. // // Convert the results of a $this-find('threaded') call into a list, wherein all items // are ordered as a tree. Unlike generatetreelist() (as of Cake 1.3), peers in this // list are also ordered (however they were by the preceding find() ). // This is meant to be used in models with Tree behavior. // // Inputs: // $find_results - output from $this-find('threaded') // $table - the name of the model containing keys and values // $key - the name of the value in the model to become the key in the output array (e.g. 'id') // $value - the name of value in the model to become the value in the output array (e.g. 'name') // // Output: a flat, one-dimensional array similar to that from generatetreelist() // function _threadedFindToTreeList($find_results, $table, $key, $value, $spacer = '--') { $our_results = array(); $this-_threadedFindToTreeListR($find_results, $table, $key, $value, $spacer, 0, $our_results); return $our_results; } // // function _threadedFindToTreeListR($find_results, $table, $key, $value, $spacer, $recursion_lvl, $our_results) { foreach($find_results as $item) { if ( isset($item[$table]) ) { // Add one entry to the bottom of our accumulated results. $spaced_val = ''; for ($i = 0; $i $recursion_lvl; $i++) $spaced_val .= $spacer; $spaced_val .= $item[$table][$value]; $our_results[ $item[$table][$key] ] = $spaced_val; if ( isset($item['children']) ) $this-_threadedFindToTreeListR($item['children'], $table, $key, $value, $spacer, $recursion_lvl+1, $our_results); } } } On Nov 21, 6:12 pm, Johnny Cupcake sparklew...@hotmail.com wrote: http://book.cakephp.org/view/1348/generatetreelist generatetreelist() returns a pseudo-tree in a relative order, with children under parents. I would like results wherein the peers are also ordered, alphabetically by label. Here is a quick example if this isn't clear: array( [1] = My Categories, [2] = _Fun, [3] = __Sport, [4] = ___Surfing, [16] = ___Skating, ) This array is not fully ordered (to my liking anyway). Surfing is above Skating, when it should be below. When an array contains dozens of elements like this, it is difficult to find what you are looking for (without alphabetical ordering). The only past online discussions I can find on this issue, end with If you want this solved, then write the function yourself. So my question is... has anyone wrote the solution yet? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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