SQL coding - Multilang filter parsing category concept - Help!

SQL coding - Multilang filter parsing category concept - Help!

by Sebastien M. -
Number of replies: 5
Hello all-

As I'm trying to build a multilang glossay, I've inserted the concepts like this:

<span lang="fr_ca" class="multilang">french concept</span><span lang="en" class="multilang">english concept</span>

With a bit of coding the autolink is working fine.  The problem is with sorting and searching the concepts (all my entries start with "<" (special character). 

So I need well thought SQL coding to extract the proper strings from the concept field. After trying every possible combinations of String Fonctions for many hours (see (http://dev.mysql.com/doc/mysql/en/String_functions.html) I didn't find the solution to strip those tags when performing the sql query (in glossary/sql.php)

Is there a MySQL expert out there that can help me figure this out?

I thought I was close with this query (to display french-R concepts):

SELECT ge.*, ge.concept pivotFROM mdl_glossary_entries geWHERE (ge.glossaryid = '1' or ge.sourceglossaryid = '1') AND (ge.approved != 0 OR ge.userid = 3) AND left(ucase(trim(LEADING '<lang lang="fr_ca">' FROM concept)),1) = 'R'ORDER BY ge.concept LIMIT 0, 10

Many thanks !




Average of ratings: -
In reply to Sebastien M.

Re: SQL coding - Multilang filter parsing category concept - Help!

by Sebastien M. -
When removing the unwanted spaces in the above quey I get (exemple to list french-R entries):

SELECT ge.*, ge.concept pivot FROM mdl_glossary_entries ge WHERE (ge.glossaryid = '1' or ge.sourceglossaryid = '1') AND (ge.approved != 0 ) AND left(ucase(trim(LEADING '<lang lang="fr_ca">' FROM ge.concept)),1) = 'R' ORDER BY ge.concept LIMIT 0, 10


This query works fine when used in phpMySQL but doesn't do the job when used in moodle... What did I missed?

seb
In reply to Sebastien M.

Re: SQL coding - Multilang filter parsing category concept - Help!

by Sebastien M. -
I found my way around and thought I should share this... The two following steps did the job:

Anywhere at the beginning of the glossary/sql.php file, add:

if (current_language() == 'fr_ca') { $delimiter = 'SUBSTRING_INDEX(ge.concept, '>', -4)'; }
elseif (current_language() == 'en') { $delimiter = 'SUBSTRING_INDEX(ge.concept, '>', -2)'; }

Later in the file (around line 215), replace the $WHERE as follow:

        case 'letter':
            if ($hook != 'ALL' and $hook != 'SPECIAL') {
                switch ($CFG->dbtype) {
                case 'postgres7':
                    $where = 'AND substr(upper(concept),1,' .  strlen($hook) . ') = '' . strtoupper($hook) . ''';
                break;
                case 'mysql':
//$where = 'AND left(ucase(concept),' .  strlen($hook) . ") = '" . strtoupper($hook) . "'"; //ORIGINAL CODE
                $where = 'AND left(ucase('.$delimiter.'),' .  strlen($hook) . ") = '" . strtoupper($hook) . "' "; // MERIDIUM -> for multilang glossary !!!
                break;
                }

LATER IN THIS FILE replace the $sqlorderby BY:

        case GLOSSARY_STANDARD_VIEW:
            //$sqlorderby = "ORDER BY ge.concept";// ORIGINAL
      $sqlorderby = "ORDER BY ".$delimiter;//Meridium


As the glossary->concepts will always begin with a '<', you will have to play around this in the view.php  in order to get a representative Pivot.

In glossary/view.php(around line 320):

After:  foreach ($allentries as $entry)

            REPLACE $pivot = $entry->pivot; //ORIGINAL
            BY: $pivot = multilang_filter($courseid, $entry->pivot); //Meridium -> Multilang filter

I did not use the format_text() function as this was adding autolinks in the pivots... (the glossary filter is active) Filters are tricky.

Additionnally, you may need to edit the table structure to allow for longer concepts...

Remember that the above changes are quite intuitive as I'm not an advanced programmer.

Cheers.  SEB

In reply to Sebastien M.

Re: SQL coding - Multilang filter parsing category concept - Help!

by Sebastien M. -
Hello all-

I am so glad that I have answered myself and posted this quick multilang/glossary fix more than 2 years ago (Moodle 1.4.3) because it is working on with Moodle 1.8.2+ as well (only with minor adjustments).

Cheers,

S

In reply to Sebastien M.

Re: SQL coding - Multilang filter parsing category concept - Help!

by Sebastien M. -
I implemented about the same changes in distro 2.3 back in 2012 and I am still facing the same issue in 2.9.

Why is the glossary not supporting the multilang filter?

Anyone has a more elegant solution to this?

Kind Regards,

Sebby

Also on this topic:

https://moodle.org/mod/forum/discuss.php?d=161774

https://moodle.org/mod/forum/discuss.php?d=51603