chamilo / chamilo-lms

Chamilo is a learning management system focused on ease of use and accessibility
https://chamilo.org
GNU General Public License v3.0
790 stars 479 forks source link

Documents (in a group) : folders are not always correctly sorted in the "Folder selector" #3620

Closed tanchon closed 3 years ago

tanchon commented 3 years ago

Hi,

Into a course with some groups, when i open the document tool of the group, an issue occurs : folders are not always correctly sorted in some groups ! But they are always correctly sorted in the document list.

See here, a group with this issue : Capture3

See here another group without any issue (into the same course) Capture4

Expected behavior The folders into the folder selector should always be correctly sorted.

**Server Chamilo 1.11.12 ; PHP 7.3

Additional context I've made a lot of tests... but I found no explanation.

Thanks !

Tanchon

tanchon commented 3 years ago

When i look into the c_document table, i can see that there was changes in some folders name of the 1st group (with issue) : the folders seem to be sorted on the 'path' field (may be it should be sorted on the 'title' field ?).

tanchon commented 3 years ago

Hi,

I reproduced the issue in the general DOCUMENTS of a course on 11.chamilo.org : see here => 11.chamilo.org : cours tanchon. This issue isn't due to the groups tool but to the document tool...

Tanchon

ywarnier commented 3 years ago

Yes, it looks like it is sorted on the path, which is a requirements (in this version) to get the concept of hierarchy. This is kind of solved by itself with the new structure in Chamilo 2.0, so I'll mark it as a goal for 2.0.

carlangas159 commented 3 years ago

Hi @tanchon

I have reviewed the course in question, in this case the ordering is done by a php function https://www.php.net/manual/en/function.natsort.php called in the file https://github.com/chamilo/chamilo-lms/blob/1.11.x/main/inc/lib/document .lib.php # L838

In question, it orders based on a natural order, however, it is case sensitive, as an example we have part of the original array:

array (
  2724 => '/ shared_folder',
  2725 => '/ chat_files',
  2727 => '/ shared_folder / sf_user_1',
  2728 => '/ audio',
  2730 => '/ flash',
  2734 => '/ Group-0011_groupdocs__0__79',
  2735 => '/ Group-0011_groupdocs__0__79 / FOLDER-1__0__79',
  2736 => '/ Group-0011_groupdocs__0__79 / FOLDER-1__0__79 / FOLDER-1_1__0__79',

After ordering, it can be seen that capital letters are taken into account:

 2865 => '/ REPERTOIRE-3',
  2872 => '/ Sous-groupe-1_groupdocs__0__77',
  2873 => '/ Sous-groupe-2_groupdocs__0__78',
  2874 => '/ Subgroup-1_groupdocs__0__67',
  2875 => '/ Subgroup-1_groupdocs__0__69',
  2876 => '/ Subgroup-2_groupdocs__0__68',
  2877 => '/ Subgroup-2_groupdocs__0__70',
  2728 => '/ audio',
  2725 => '/ chat_files',
  2730 => '/ flash',

There is the possibility to bypass the capitalization check with another native php function https://www.php.net/manual/en/function.natcasesort.php

  2771 => '/ Groupe-0003_groupdocs__0__49 / FOLD11__0__49 / FOLD112__0__49',
  2772 => '/ Groupe-0003_groupdocs__0__49 / FOLD11__0__49 / FOLD113__0__49',
  2773 => '/ Groupe-0003_groupdocs__0__49 / FOLD12__0__49',
  2776 => '/ Groupe-0003_groupdocs__0__49 / FOLD13__0__49',
  2778 => '/ Group-201901_groupdocs__0__66',
  2779 => '/ images',
  2785 => '/ learning_path',
  2786 => '/ learning_path / Essai-23-11-9h00',
  2787 => '/ learning_path / Essai-de-parcours',
  2788 => '/ REPERTOIRE-1',
  2790 => '/ REPERTOIRE-1 / REPERTOIRE-0',
  2795 => '/ REPERTOIRE-2',
tanchon commented 3 years ago

Thanks @carlangas159 for the fix and your explanations, very detailed ! I think it is more "intuitive" now, and more logical (documents are sorted in the selector as they are sorted in the document list ) : Sans titre

The only problem that remains is when we rename the documents. For example, if i modified the titles of the documents listed above (in the 2nd view, right) : after renaming

The explanation seems to be that in the selector, documents are sorted on the "path" field, as in the document list they are simply sorted on their "title". I think it is more logical to sort all the lists on the document "title", because it is what the user can see. Moreover, it is a frequent situation when users rename their documents in order to have the possibility to "sort manually" them (they often use digits or letters at the beginning of the title).

Thanks ! Tanchon.

ywarnier commented 3 years ago

Although there was some merit in @carlangas159 's fix to natsort/natcasesort, it didn't fix the reported issue of the dropdown boxes.

Commit 080c2b07cda92f8b2c58840eb5a03df1a5521d1c does fix it by reorganizing the array. It's a bit of an additional resource usage, but we cannot do it otherwise: the array with the list of folders to analyse is received based on the c_document.id and the c_document.path, so we cannot order this one by title, and then we're using this array again to loop through and generate the dropdown. With this fix, we generate a first array with titles, sort it, and then loop through that one to fill the dropdown.