× 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 Topics Plugin - Doesn't Search Name

4 months 4 days ago 4 months 4 days ago by ncy.
ncy
Posts: 18
More
Topic Author
Search Topics Plugin - Doesn't Search Name #1
Maybe I'm missing the reasoning, but why does Search Topics only search the summary text? Shouldn't it also search the name? To be more clear, I mean adding these lines in /auth/joomdle/auth.php for the search_topics() function:
@@ -3563,6 +3563,9 @@
                 $text           = '%'.$text.'%';
 
                 $likes = array ();
+                $like = $DB->sql_like('cs.name', '?', false);
+                $likes[] = $like;
+                $params[] = $text;
                 $like = $DB->sql_like('cs.summary', '?', false);
                 $likes[] = $like;
                 $params[] = $text;
@@ -3580,6 +3583,9 @@
 
                     $likes = array ();
 
+                    $like = $DB->sql_like('cs.name', '?', false);
+                    $likes[] = $like;
+                    $params[] = $word;
                     $like = $DB->sql_like('cs.summary', '?', false);
                     $likes[] = $like;
                     $params[] = $word;
@@ -3614,6 +3620,7 @@
         $query = "SELECT cs.id,
             co.id          AS remoteid,
             co.fullname,
+            cs.name AS sec_name,
             cs.course,
             cs.section,
             cs.summary,
@@ -3640,6 +3647,15 @@
             $c['fullname'] = format_string($c['fullname']);
             $c['summary'] = format_text($c['summary'], FORMAT_MOODLE, $options);
             $c['cat_name'] = format_string($c['cat_name']);
+
+            // Use Course Name if course topic title is blank
+            if (empty($c['sec_name'])) {
+                $c['sec_name'] = format_string($c['fullname']);
+            }
+            else {
+                $c['sec_name'] = format_string($c['sec_name']);
+            }
+
             $data[] = $c;
         }

Would then need to add to /auth/joomdle/helpers/externallib.php:
public static function search_topics_returns() {
    return new external_multiple_structure(
        new external_single_structure(
            array(
                'remoteid' => new external_value(PARAM_INT, 'course id'),
                'fullname' => new external_value(PARAM_TEXT, 'course name'),
                'course' => new external_value(PARAM_TEXT, 'course name'),
                'section' => new external_value(PARAM_TEXT, 'course name'),
                'summary' => new external_value(PARAM_RAW, 'summary'),
                'cat_id' => new external_value(PARAM_INT, 'category id'),
                'cat_name' => new external_value(PARAM_TEXT, 'category name'),
+              'sec_name' => new external_value(PARAM_TEXT, 'section name'),
               )
            )
        );
    }

And replace 'summary' with 'sec_name' in /plugins/search/coursetopics/coursetopics.php:
-            $rows_result[$i]->title= substr (strip_tags ($row['summary']), 0, 50);
+           $rows_result[$i]->title= $row['sec_name'];
4 months 4 days ago
Antonio Durán
Posts: 6975
More
Search Topics Plugin - Doesn't Search Name #2
Hi.

Thanks for the suggestion and the code, I will check it and see if we can add your mods to Joomdle.

> Maybe I'm missing the reasoning, but why does Search Topics only search the summary text? Shouldn't it also search the name?

Yes. I checked, and the reason for this is that in Moodle 1.9 (when Joomdle started) there was no name field in couse_sections table. We didn't notice the new field, and nobody asked about it until you did :)