× Feature Requests

Please do NOT use this section of the forum to request help if Joomdle does not work for you in some particular way. Your post will be deleted.

Search Returns Hidden Courses/Categories/Topics

4 months 3 days ago 1 week 2 days ago by ncy. Reason: sql fix
ncy
Posts: 18
More
Topic Author
Search Returns Hidden Courses/Categories/Topics #1
When courses/categories/topics are hidden in Moodle, they should not come up in Joomdle search results. Currently, this is what shows when they shouldn't:
  1. Courses (Search types: any, exact)
  2. Categories (Search types: all, any, exact)
  3. Topics, when they are unhidden but their parent Course/Category is hidden (Search types: all, any, exact)
Some adjustments are needed in /auth/joomdle/auth.php.

Search courses:
public function search_courses ($text, $phrase, $ordering, $limit) {
    ...
    default:
         ...
        break;
    }
+   $where = '(' . $where . ') AND ca.visible = 1 AND co.visible = 1'; // The check for co.visible is also in the SQL query, so either here or there. Main change is adding parentheses.

Search categories:
public function search_categories ($text, $phrase, $ordering, $limit) {
    ...
    default:
         ...
        break;
    }
+   $where = '(' . $where . ') AND ca.visible = 1'; // The check for ca.visible is not in SQL query

Search topics:
public function search_topics ($text, $phrase, $ordering, $limit = 50) {
    ...
    default:
         ...
         break;
    }
-    $where .= " and cs.visible = 1";
+    $where = '(' . $where . ') AND cs.visible = 1 AND co.visible = 1'; // Need parentheses, and the check for cs.visible and co.visible is not in SQL query

Side note, while testing I discovered that searching for the word "topic" will ignore course sections that do not have a custom title set, even though they are automatically labeled as "Topic X" by Moodle. I guess that's because technically those titles are blank.
4 months 5 hours ago
Antonio Durán
Posts: 6975
More
Search Returns Hidden Courses/Categories/Topics #2
Thanks for the info. We'll look into adding the changes for next release.
3 months 1 week ago
Antonio Durán
Posts: 6975
More
Search Returns Hidden Courses/Categories/Topics #3
Hi.

Just wanted to tell you that I incorporated your changes for next release.

As for searching for "topic X", I don't think it is worth it to return results for that, as it would be a kludge.
3 months 1 week ago
ncy
Posts: 18
More
Topic Author
Search Returns Hidden Courses/Categories/Topics #4
Cool, glad that I could help.

Yea, I was looking at the "topic X" thing too and decided I would just point it out and let you decide :)
1 week 2 days ago 1 week 2 days ago by ncy.
ncy
Posts: 18
More
Topic Author
Search Returns Hidden Courses/Categories/Topics #5
I'm testing v1.2.6 and still running into these cases:
  1. Search for topics still shows results for topics of hidden courses.
  2. Search for topics still shows results for topics of visible courses in hidden categories.
  3. Search for courses still shows results for hidden courses.
  4. Search for courses still shows results for courses in hidden categories.
The changes to fix are still what I described above (noted again below, with some other code fixes I noticed).

auth.php:
    public function search_courses ( ... ) {
        ...
        $where = '(' . $where . ') AND ca.visible = 1 AND co.visible = 1'; // ***Add parens and ANDs***

        switch ( $ordering ) {
        ...
    }

    public function search_topics ( ... ) {
        ...
                    $params[] = $word; // ***This should be $word, not $text since it's not an Exact Phrase search***

                    $where2 = '(' . implode(  ') OR (', $likes ) . ')';
                    $wheres2[] = $where2;
                }
                $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres2 ) . ')';
                break;
        }
        $where = '(' . $where . ') AND cs.visible = 1 AND co.visible = 1'; // ***Add parens and ANDs***
        ...
        $query = "SELECT cs.id, cs.name as sec_name,  // ***Add "as sec_name" otherwise section name doesn't show***
            co.id          AS remoteid,
            co.fullname,
            cs.course,
            //cs.section, // ***Remove duplicate cs.section***
            cs.summary,
            ca.id as cat_id,
            ca.name as cat_name,
            cs.section
         ...

            if ($c['sec_name'])
                // ***Use "sec_name" instead of "name" otherwise section name doesn't show***
                $c['sec_name'] = format_string($c['sec_name']);
    }

1 week 1 day ago
Antonio Durán
Posts: 6975
More
Search Returns Hidden Courses/Categories/Topics #6
Thank you for the detailed report. I will check it and make the changes.