Wrong order

tomwo - May 5, 2008 - 08:41
Project:Taxonomy VTN
Version:6.x-1.0-rc5
Component:Code
Category:support request
Priority:normal
Assigned:tomaszx
Status:closed
Description

Hi!

Thanks for a great module :-) I can't get it to sort my terms in the correct order, though. It seems like the terms are ordered by their URL, not their name. What can I do to correct this?

--tom

#1

tomaszx - May 5, 2008 - 12:52

Hi ,

You saw settings in options?
Tell me whats is your language of terms.

#2

tomaszx - May 6, 2008 - 08:56
Status:active» postponed (maintainer needs more info)

give me some screenshots for your problem.

#3

tomwo - May 6, 2008 - 13:01

Hi,

Yes, I have checked the settings, and must admit I get the message that "Your server not support setlocale." I'm not sure how to fix that - do you have any advice? I have installed the D6 module Locale. My system: PHP 5.2.0, Apache 2.2.3, MySQL 5.0.33. But I'm not sure that the locale is the problem.

My point is that the module uses URL aliases for sorting, not the words within the <a>-tags. Here is an example:

B

The URLs for the last few items are /kategori/okonomi/xxx etc. The word "okonomi" is a transliteration for the Norwegian word "økonomi" - and is therefore ordered correctly.

Thanks for any advice.

-- tom

#4

tomaszx - May 6, 2008 - 17:54

Hi,

ad 1.
"setlocale" is server side support for locale not Drupal locale.
Your server probably not support this. That is half ok.

ad2.
hm... i not index with link alias but link name.

<?php
           
.....

           
$arr_terms[$term->name]['term'][] = l($term->name, $term_goto_path) . $count_nodes . $term_desc ;
           
// if is not empty term or we show empty terms
            // and we will show synonyms then get for this
           
if ($show_synonyms) {
             
$synonyms = taxonomy_get_synonyms($term->tid);
              foreach (
$synonyms as $synonym_name) {
               
// $synonym_term = taxonomy_get_synonym_root($synonym_name);
                // all synonyms have a target - this term
               
$arr_terms[$synonym_name]['synonym'][] = l($term->name, $term_goto_path);
              }
            }
           
            ..........
?>

You have beta4 ?
Tell me about your settings more.

regards.

#5

tomwo - May 6, 2008 - 18:01

Ad2:
Am I right to believe that

l($term->name, $term_goto_path)

produces something like "Barnehage" ?

There you have it, if you sort a bunch of such lines, you're sorting on the URL, not the name. For each record everything is equal at the start"

#6

tomaszx - May 6, 2008 - 18:13

Tell me, you show me a Term list or nodes list for term?
I'm not sure what i see.

#7

tomaszx - May 6, 2008 - 18:22

i use pathauto and terms and is sorted ok. i dont understand your error..... strange.
your path for terms are very strange...

look, this should be a link to "taxonomy_vtn/term/XXX" where XXX is a term id not like you have.
This is once, and two: you can only change this to "taxonomy/term/XXX" on settings page.

Then your links looks like you modify self some code or use some module what change the link to term.
I dont support this method. If is it then please show me patch for this.

#8

tomwo - May 6, 2008 - 20:33

Sorry about the last message, I forgot to make the code readable:

My point was that l($term->name, $term_goto_path) produses something like <a href="/kategori/utdanning/barnehage">Barnehage</a> - and that the sorting of this string will be on the URL inside the tag.

But now I have removed Pathauto and reinstalled Taxonomy VTN - and the problem is still there. I use the taxonomy/term/XXX. The list now looks like this - still the sorting is wrong ...

I don't use any patches, just normal modules. It makes no difference if the language for the site is set to English or Norwegian. I don't understand this - will look more into it tomorrow.

#9

tomaszx - May 6, 2008 - 20:51

Ok, strange situation, it looks like problem with ksort and names.

for you ( when not use setlocale ), only is used

ksort($arr);

with this not exists any my locale method for sorting.
Maybe ksort is a problem? or extensions for php on server?

On my machine problem not exists .. then i dont know how can i give the same and test this situation.

anyone have this problem? anyone could confirm this problem?

#10

tomaszx - May 6, 2008 - 20:54

Please look for this:

http://api.drupal.org/api/function/taxonomy_get_tree/6

    $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid);

You see? ORDER BY weight, name', 't', 'tid'), $vid);

maybe you was set weight for some terms? check this and confirm or not.

#11

tomwo - May 6, 2008 - 21:00

Shouldn't there be a ksort($arr_terms) too? Anyway, I've made a small modification that solves the problem:

if ($tcount || $show_empty_terms) {

// MY PATCH
setlocale(LC_ALL, 'nb_NO.UTF8');
ksort($arr_terms, SORT_LOCALE_STRING);
// set locale back to default
setlocale(LC_ALL, NULL); // without this count($arr) not work properly
// End MY PATCH

$arr_terms[$term->name]['term'][] = l($term->name, $term_goto_path) . $count_nodes . $term_desc ;
// if is not empty term or we show empty terms
// and we will show synonyms then get for this
if ($show_synonyms) {
$synonyms = taxonomy_get_synonyms($term->tid);
foreach ($synonyms as $synonym_name) {
// $synonym_term = taxonomy_get_synonym_root($synonym_name);
// all synonyms have a target - this term
$arr_terms[$synonym_name]['synonym'][] = l($term->name, $term_goto_path);
}
}

Please observe that the PHP function setlocale works just fine - even though the module reports that the server doesn't support setlocale. Are those two different things?

Thanks!

#12

tomwo - May 6, 2008 - 21:03

ORDER BY weight is not the issue here - I'm not using weight-ordering so far.

-t

#13

tomaszx - May 7, 2008 - 11:26

hm, i know.

I use check for master locale of instalation drupal site.

Maybe you install drupal as English (or master locale) and try use as Norwegian ?
Look, if more users set own locale to other settings as you then this not work.
My think is ok, but probably you set English as master locale.

Look here (line 260 in taxonomy_vtn.pages.inc):

$xlanguage = language_default();

and here: http://api.drupal.org/api/function/language_default/6

Please check this and tell me.

#14

tomwo - May 7, 2008 - 19:33

My server was set up with nb_NO as locale. I have changed it to no_NO and now it works ok to use

setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');

instead of

setlocale(LC_ALL, 'nb_NO.UTF8');

But the Taxonomy VTN module settings still report that my server doesn't support setlocale - even though I'm actually now using it to fix the sort order.

I didn't mean that everybody should hard code the locale value into the script.

#15

tomaszx - May 7, 2008 - 20:20

Hi,

i dont understand you. Sorry.
You changed my script or only changed your settings for default language?

what is a language nb_NO and what is a different for no_NO ? i don't know.

Please help me make better my module. Sorry for my english :)

About error that you dont have support for setlocale is a problem ... but i know why :)
Please disable and re-enable my module.. then error should go on.
I check for setlocale only once when module is enable.

But i see that:

setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');

is not good when you use mixed name of locale like: nb_NO :(

have you a solutions for this?

#16

tomwo - May 7, 2008 - 21:15

In Norway we have to languages:

Nynorsk: nn - the traditional, old norwegian (vaguely related to islandic)
Bokmål: nb - more like danish

The difference between the two are microscopic.

So nb_NO means I'm using bokmål and not nynorsk. Many Norwegian computers are set up with one of these two locales. This is important for spell checking, thesaurus etc. But I can also use no_NO. This is probably the same as nb_NO, I'm not sure.

I guess many countries have several languages like us. In Finland, for instance, they use both finnish (fi_FI) and swedish (sv_FI). If you type locale -a in a Unix shell, you get a long list ...

You should find a way to deal with this.

I tried disabling and enabling the module, but the setlocale error message is still there.

My taxonomy_vtn.pages.inc file now looks like this and works fine - as long as the locale on the server is no_NO:

if ($tcount || $show_empty_terms) {

// MY PATCH
setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');
ksort($arr_terms, SORT_LOCALE_STRING);
// set locale back to default
setlocale(LC_ALL, NULL); // without this count($arr) not work properly
// End MY PATCH

$arr_terms[$term->name]['term'][] = l($term->name, $term_goto_path) . $count_nodes . $term_desc ;
// if is not empty term or we show empty terms
// and we will show synonyms then get for this
if ($show_synonyms) {
$synonyms = taxonomy_get_synonyms($term->tid);
foreach ($synonyms as $synonym_name) {
// $synonym_term = taxonomy_get_synonym_root($synonym_name);
// all synonyms have a target - this term
$arr_terms[$synonym_name]['synonym'][] = l($term->name, $term_goto_path);
}
}

#17

tomaszx - May 7, 2008 - 21:49

Try implemet this like:

<?php

        
/// more code

         
if ($tcount || $show_empty_terms) {
           
$arr_terms[$term->name]['term'][] = l($term->name, $term_goto_path) . $count_nodes . $term_desc ;
           
// if is not empty term or we show empty terms
            // and we will show synonyms then get for this
           
if ($show_synonyms) {
             
$synonyms = taxonomy_get_synonyms($term->tid);
              foreach (
$synonyms as $synonym_name) {
               
// $synonym_term = taxonomy_get_synonym_root($synonym_name);
                // all synonyms have a target - this term
               
$arr_terms[$synonym_name]['synonym'][] = l($term->name, $term_goto_path);
              }
            }
          }
      }
// end foreach terms as term prepare
     

      // PATCH
     
$xlanguage = language_default();
     
// change locale to sort
     
if (variable_get('taxonomy_vtn_use_setlocale', 1) == 1 && variable_get('taxonomy_vtn_server_support_setlocale', 0) == 1 ) {
       
setlocale(LC_ALL, $xlanguage->language .'_'. strtoupper($xlanguage->language) .'.UTF8');
       
ksort($arr_terms, SORT_LOCALE_STRING);
       
// set locale back to default
       
setlocale(LC_ALL, NULL); // without this count($arr) not work properly
     
}
      else {
       
ksort($arr_terms); //--- this not support languages
     
}
     
// END PATCH


      // Now we make index with links to proper terms for synonyms
     
foreach ($arr_terms as $name => $types) {

    
/// more code
?>

I try identify why you have still this error even you re-enable module ... strange.

#18

tomaszx - May 7, 2008 - 22:06

Please check how work your locale when you remove your patch but set master locale to no_NO
then work correctly?

#19

tomwo - May 8, 2008 - 09:11

If I remove the patch and set locale to no_NO the problem is back. The terms-array must be sorted, naturally.

#20

tomaszx - May 8, 2008 - 10:46

ok, now we know this :) but strange why this work for my language pl_PL where i have some special chars like: ą ę ń ł ó etc.

Tell me you changed location your patch like i present above?

Before you had in wrong place (in foreach) and many times this could be executed (not good).

#21

tomaszx - May 9, 2008 - 07:36
Assigned to:Anonymous» tomaszx
Status:postponed (maintainer needs more info)» won't fix

Hi,

Please check this version in attachment... i add support to select locale from server support and
checking for support is changed.

Please test this and tell me if this work for you.

regards.

AttachmentSize
taxonomy_vtn-dev-setlocale.tar_.gz 45.33 KB

#22

tomwo - May 13, 2008 - 07:46

Yes - this version works: I am able to select my locale from a list - and the sorting of the terms is correct when I select no_NO.UTF8. The only problem is that the screen displays nothing (just a grey background) when I click on the Save button to change the settings. But the settings are still correctly saved.

-- tom

#23

tomaszx - May 13, 2008 - 08:17

fixed in rc1 - please test if you can. Thanks for your tests Tom :)
Tell me about RC1... if is ok, then i set to fixed this issue.

Regards.

#24

tomwo - May 14, 2008 - 07:47

RC1 is working just fine - problems are fixed. Thanks Tomasz :-)

#25

tomaszx - May 14, 2008 - 09:05
Status:won't fix» fixed

Thanks.

I release on few days new rc2 and then check for php version and support for setlocale
not only on enabling module but on settings page.

i'm happy could have good tester :)

#26

Anonymous (not verified) - May 28, 2008 - 09:11
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#27

Equ - August 5, 2008 - 21:48
Status:closed» active

Hey!
I have the same error :( The last RC5 doesn't fix this problem for me.
My nodes look like:
(it's in Russian)
Агент
Администратор гостиницы
Агент коммерческий
Администратор зала (метрдотель)
Агент по продаже недвижимости
Администратор офиса
Агент по закупкам
Администратор сетей
Агент по розыску грузов и багажа
Администратор
Агент по снабжению
Акушерка
Агент по туризму
Архивариус
Агент рекламный

At first it was almost ok, and just couple of nodes messed up, but after "playing" with locale settings and trying to set different options (ru_RU, ru_RU.utf8, etc.) it totally messed up the order...

Thanks for any help!

#28

tomaszx - August 8, 2008 - 15:30

Hi,

http://1medical.ru/taxonomy_vtn/voc/2

they use my module and maybe you should ask they what this work correct or no... maybe help you.

What is your verion of PHP? etc...

Anyone can confirm this problem?

#29

Equ - August 8, 2008 - 18:39

Hello!

Thanx for reply! My version of PHP is 5.2.5.

#30

Equ - August 8, 2008 - 19:27

It's really weird that my terms and vocabularies are sorted in proper alphabetical order... This happens only with nodes. Btw, if I have very few nodes per letter it works fine, but after adding more and more nodes for that letter after some point it breaks the order.

#31

tomaszx - August 8, 2008 - 20:23

This mean that only with nodes you have a problem?
Hm.... i must look ... sorry for delay but i go today to vacation.

I will try help you .... maybe next week. Sorry.

#32

Equ - August 9, 2008 - 09:01

Ok! Will be waiting for your help!
And look at this http://www.russiajournal.com/taxonomy_vtn/term/3, if you carefully look at that you'll notice that nodes on that page are also in wrong order (well, this doesn't mean they have the same problem, but anyways...).

#33

tomaszx - August 17, 2008 - 23:43

Hi,

This is strange ,... i was tested localy and all work correctly .. maybe version of php or something else ...
I will be testing but i dont know why this happen...

regards.

#34

Equ - March 20, 2009 - 18:30

Hm... try testing with 50-60 nodes per letter, maybe this way you'll be able to get this error...

#35

tomaszx - August 27, 2008 - 21:45
Version:6.x-1.0-beta4» 6.x-1.0-rc5
Status:active» needs review

Hi

in line 490 in taxonomy_vtn.pages.inc change:

from:

$nodes = taxonomy_vtn_select_nodes(array($own_tid), $operator = 'or', $depth = 'all', $use_pager, $order = 'n.sticky DESC', $links_per_page);

to:

$nodes = taxonomy_vtn_select_nodes(array($own_tid), $operator = 'or', $depth = 'all', $use_pager, $order = 'n.title, n.sticky DESC', $links_per_page);

n.title in order is needed :) now works correct for me ...

Regards and sorry for long support.

#36

tomaszx - August 27, 2008 - 21:45
Status:needs review» fixed

fixed in rc6

#37

Equ - August 31, 2008 - 18:46

Wohoo!!! Thank you, tomaszx! Works great! :)

#38

Anonymous (not verified) - September 14, 2008 - 18:51
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.