CompanyDirectory: browsehier action does not sort A-Z

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

CompanyDirectory: browsehier action does not sort A-Z

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: CompanyDirectory: browsehier action does not sort A-Z

Post by Rolf »

And you cant change the order in the admin?
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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'.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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...
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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 :)
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: CompanyDirectory: browsehier action does not sort A-Z

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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.
Quintijn
Forum Members
Forum Members
Posts: 17
Joined: Mon Oct 15, 2012 7:23 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post 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);

};

?>
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: CompanyDirectory: browsehier action does not sort A-Z

Post by Rolf »

You tried the latest release?
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: CompanyDirectory: browsehier action does not sort A-Z

Post by calguy1000 »

New versions of CompanyDirectory have the ability to re-order the hierarchy in the admin panel.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Modules/Add-Ons”