Page 1 of 1
CompanyDirectory: browsehier action does not sort A-Z
Posted: Sat Jan 05, 2013 8:56 pm
by Quintijn
CMSMS 1.11.4
CompanyDirectory 1.16.2
Question: How to sort the browsehier output alphabetically?
Example: {CompanyDirectory action="categorylist"} does sort A-Z, but {CompanyDirectory action="browsehier"} doesn't.
I like to sort it (automatically) like this:
A
- A
- B
- C
B
- X
- Z
At this moment you need to add hierarchy items exactly right, or start all over again
Please help.
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Mon Jan 07, 2013 10:41 pm
by Rolf
And you cant change the order in the admin?
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Wed Jan 09, 2013 3:33 pm
by Quintijn
The only option available (in my case) is to add or remove parents or children from the hierarchy list. Everything seems to be sorted at 'auto increment ID'.
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Thu Jan 10, 2013 8:46 am
by Rolf
I looks like correct to me when it displays:
parent
child
child
child
parent
child
child
child
What template do you use? Don't know if you could something there with some Smarty tricks...
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Thu Jan 10, 2013 8:51 am
by Quintijn
It does display:
parent
- child
- child
parent
- child
- child
But it doesn't order A-Z, like:
Aparent
- Achild
- Bchild
Cparent
- Ychild
- Zchild
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Fri Jan 18, 2013 10:04 am
by Quintijn
I tried to sort the array with a SMARTY modifier script in PHP...
<?php
#
# Modifier: sortby - allows arrays of named arrays to be sorted by a given field
#
function smarty_modifier_sortby($data) {
usort($data, function($a, $b){
$a = strnatcmp($a['node']['name']);
$b = strnatcmp($b['node']['name']);
if ($a == $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
});
print_r($data);
};
?>
It still doesn't sort. Maybe it has to do something with the multidimensional array depth.
Someone with a fresh view, please

Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Fri Jan 18, 2013 2:14 pm
by Rolf
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Fri Jan 18, 2013 3:22 pm
by Quintijn
No results. Maybe the multidimensional output does the harm.
Array ( [00001] => Array ( [00002] => Array ( [node] => Array ( [id] => 2
[name] => Bedum
[parent_id] => 1 [hierarchy] => 00001.00002
[long_name] => Groningen | Bedum
[count] => 0
[depth] => 2
[url] =>
http://alink
)
)
[00003] => Array ( [node] => Array ( [id] => 3
[name] => Zuidwolde
[parent_id] => 1
[hierarchy] => 00001.00003
[long_name] => Groningen | Zuidwolde
[count] => 0 [depth] => 2
[url] =>
http://alink
)
)
[00007] => Array ( [node] => Array ( [id] => 7
[name] => AAA
[parent_id] => 1
[hierarchy] => 00001.00007
[long_name] => Groningen | AAA
[count] => 0
[depth] => 2
[url] =>
http://alink
)
)
)
)
Try to sort by name.
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Fri Jan 18, 2013 7:55 pm
by Quintijn
This script sorts the child arrays by name, but strips the first parent arrays. The question is, how to get the parent arrays in order and working again?
<?php
#
# Modifier: sortby - allows arrays of named arrays to be sorted by a given field
#
function smarty_modifier_sortby($data) {
$nodes = array();
// Strips the parent arrays..
foreach($data as $arrayA) {
foreach($arrayA as $arrayB) {
$nodes[] = $arrayB;
}
}
function cmp($a, $b) {
return strcmp($a[node][name], $b[node][name]);
}
usort($nodes, 'cmp');
print_r($nodes);
};
?>
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Sun Jul 14, 2013 6:44 am
by Rolf
You tried the latest release?
Re: CompanyDirectory: browsehier action does not sort A-Z
Posted: Sun Jul 14, 2013 4:16 pm
by calguy1000
New versions of CompanyDirectory have the ability to re-order the hierarchy in the admin panel.