Merge branch 'MDL-57977-34' of git://github.com/vmdef/moodle into MOODLE_34_STABLE
This commit is contained in:
@@ -319,6 +319,19 @@ abstract class base {
|
||||
*/
|
||||
abstract public function get_document($record, $options = array());
|
||||
|
||||
/**
|
||||
* Returns the document title to display.
|
||||
*
|
||||
* Allow to customize the document title string to display.
|
||||
*
|
||||
* @param \core_search\document $doc
|
||||
* @return string Document title to display in the search results page
|
||||
*/
|
||||
public function get_document_display_title(\core_search\document $doc) {
|
||||
|
||||
return $doc->get('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context info required to index files for
|
||||
* this search area.
|
||||
|
||||
@@ -579,7 +579,8 @@ class document implements \renderable, \templatable {
|
||||
public function export_for_template(\renderer_base $output) {
|
||||
list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($this->get('areaid'));
|
||||
|
||||
$title = $this->is_set('title') ? $this->format_text($this->get('title')) : '';
|
||||
$searcharea = \core_search\manager::get_search_area($this->data['areaid']);
|
||||
$title = $this->is_set('title') ? $this->format_text($searcharea->get_document_display_title($this)) : '';
|
||||
$data = [
|
||||
'componentname' => $componentname,
|
||||
'areaname' => $areaname,
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -119,7 +119,7 @@ class user_search_testcase extends advanced_testcase {
|
||||
$this->assertEquals(SITEID, $doc->get('courseid'));
|
||||
$this->assertFalse($doc->is_set('userid'));
|
||||
$this->assertEquals(\core_search\manager::NO_OWNER_ID, $doc->get('owneruserid'));
|
||||
$this->assertEquals(content_to_text(fullname($user), false), $doc->get('title'));
|
||||
$this->assertEquals(content_to_text(fullname($user), false), $searcharea->get_document_display_title($doc));
|
||||
$this->assertEquals(content_to_text($user->description, $user->descriptionformat), $doc->get('content'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user