Merge branch 'MDL-62899-search-icons-master' of https://github.com/dmitriim/moodle
[moodle.git] / user / classes / search / user.php
index b0f4525..479b4e0 100644 (file)
@@ -92,8 +92,14 @@ class user extends \core_search\base {
 
         // Prepare associative array with data from DB.
         $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
+        // Include all alternate names in title.
+        $array = [];
+        foreach (get_all_user_name_fields(false, null, null, null, true) as $field) {
+            $array[$field] = $record->$field;
+        }
+        $fullusername = join(' ', $array);
         // Assigning properties to our document.
-        $doc->set('title', content_to_text(fullname($record), false));
+        $doc->set('title', content_to_text($fullusername, false));
         $doc->set('contextid', $context->id);
         $doc->set('courseid', SITEID);
         $doc->set('itemid', $record->id);
@@ -110,6 +116,18 @@ class user extends \core_search\base {
         return $doc;
     }
 
+    /**
+     * Returns the user fullname to display as document title
+     *
+     * @param \core_search\document $doc
+     * @return string User fullname
+     */
+    public function get_document_display_title(\core_search\document $doc) {
+
+        $user = \core_user::get_user($doc->get('itemid'));
+        return fullname($user);
+    }
+
     /**
      * Checking whether I can access a document
      *