I have taxonomies with large numbers of nodes. When using taxonomy_dhtml the sort order seemed quite weird, after checking the code, I noticed that the SELECT query to get the nodes uses ORDER BY n.changed DESC... that is, it was supposedly ordered by changed date, newest first... however, reviewing the outcome, I saw that the order was actually oldest first (which I almost see no case where it could be useful, but that's a personal opinion).

Reading a couple lines more of code, I noticed that the nodes obtained by the query were inserted in the final array in reverse order... or, more to the point, the nodes were inserted always at the beginining of the array.

As my actual need is to have the items sorted alphabetically by title (and in order to change the least possible code, since I'm by no means a php wizard), changed the SELECT statement to use ORDER BY n.title DESC... since the nodes are still inserted one by one at the begining, the viewed order is straight alphabetical.

If I knew how to program, it might be a nice addition to make the sort order configurable in admin/settings/taxonomy_dhtml

Comments

meba’s picture

Assigned: Unassigned » meba
Status: Needs review » Closed (won't fix)

Sorry, i can't alter the module to just your needs. However, the second option (configurable) seems reasonable. Please add new issue for this

el_baby’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new1.8 KB

Hi Jakub,

I did my homework and, after reading a bit, I did the minimium possible change so as to make the sort order handled by the module settings.

Currently you can only choose between the "by last modified" order (which is the default, so as to not break previous installations), and "by title", which is the only one I needed.

When you have the time (and the will), please take a look.

Regards.

meba’s picture

Version: 4.7.x-1.x-dev » 5.x-2.2

Seems reasonable. I will try next week.

meba’s picture

StatusFileSize
new1.92 KB

Can you please try attached patch with 5.x version? Does it work as expected?

el_baby’s picture

Jakub,

I'm working remote with Really Bad Connectivity (TM)... I'll be at home by next Tuesday (April 10th) and will try to look at it... I don't have a 5.x installation, but can set up one and give it a try... maybe I'll get a friend to do it for me before that.

Regards.

meba’s picture

Status: Needs review » Postponed (maintainer needs more info)
el_baby’s picture

Status: Postponed (maintainer needs more info) » Needs work
StatusFileSize
new2.31 KB

Well, I suck at this... sorry... I installed drupal 5.1 and added a taxonomy with a couple of terms... I tried a million times changing the sort order and the page stood the same... up until I noticed that the problem was that the trees were cached...

I made a wild attempt at somehow invalidating the cache whenever the value of the taxonomy_dhtml_sort_order variable changed but it was obviously wrong. I modified line 50 in order to ignore the cache but this is wrong... if you know how to invalidate the cache when an option in the settings change, that is what should be done... if there's no way to do this, maybe the cache shouldn't be used at all... I dunno...

The other thing I noticed is that somehow title ascending was actually reverse alphabetical... I thought it might have to do with the fact that you make a tree with the results of the query and maybe you filled it up one way and traversed it in the other (I didn't actually tried to understand the code)... but surprisely, Time of last modification, descending was actually newest first... I took an awfully pragmatic approach here and named the options after the results instead of trying to understand what happens :-(

Im attaching a patch with (the little) I did, so that you can do it right... I'm sorry that my sloppyness with php is only topped by my ignorance of the drupal api...

Regards.

meba’s picture

Thank you. The cache problem is related to another issue and should be fixed after some time.

el_baby’s picture

OK, but at least, before committing the patch (or a modification of it), the cache problem should be noticed to users... maybe in the README.txt under Known Issues

meba’s picture

I will commit it after fixing the cache problem...

el_baby’s picture

Oki... I have no hurry, since the site I'm using tax_dh is the one with drupal 4.7 for which I made the original patch and it just works.

Thanx for your commitment.

Regards.

el_baby’s picture

Well... now I'm using it in a drupal 5.1 site... as the cache is still doing weird things, I downloaded from cvs and patched the latest module again... I still didn't try the cache, but our tiny modification to the settings still works.

Just to keep you eager to apply it, I'm enclosing a new patch that applies to the current DRUPAL-5 branch in cvs.

Regards.

v8powerage’s picture

I'm struggling with option "sort nodes by last comment", I've tryied replace sql query from forum.module, where is the block which shows active threads, but which is very strange nothing happened, and it shows still the same order like before. Here's the query:

    $type_q = ($type ? "n.type = '$type'" : 1);    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type = 'forum' ORDER BY l.last_comment_timestamp" . variable_get("forum_dhtml_sort_order", 'changed'). " DESC"), 0, variable_get("forum_dhtml_overview_count", 50))
Anonymous’s picture

Assigned: meba » Unassigned
Status: Needs work » Closed (fixed)

This module is no longer being actively developed as it duplicates functionality that can be obtained through the usage of taxonomy_menu ( http://drupal.org/project/taxonomy_menu ) and dhtml_menu ( http://drupal.org/project/dhtml_menu ).