Skip to content

Commit

Permalink
MDL-58410 user: add support for alternative name search
Browse files Browse the repository at this point in the history
The solution about searching all external names fields (middlename etc) from course enrolment page (enrolled and enrolling pages)
  • Loading branch information
tigusigalpa authored and mdjnelson committed Jan 24, 2018
1 parent f68150a commit 358b10a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions enrol/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ protected function get_basic_search_conditions($search, $searchanywhere) {
$params = array('guestid' => $CFG->siteguest);
if (!empty($search)) {
$conditions = get_extra_user_fields($this->get_context());
$conditions[] = 'u.firstname';
$conditions[] = 'u.lastname';
foreach (get_all_user_name_fields() as $field) {
$conditions[] = 'u.'.$field;
}
$conditions[] = $DB->sql_fullname('u.firstname', 'u.lastname');
if ($searchanywhere) {
$searchparam = '%' . $search . '%';
Expand Down
24 changes: 24 additions & 0 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,10 @@ function user_get_participants_sql($courseid, $groupid = 0, $accesssince = 0, $r
$searchkey1 = 'search' . $index . '1';
$searchkey2 = 'search' . $index . '2';
$searchkey3 = 'search' . $index . '3';
$searchkey4 = 'search' . $index . '4';
$searchkey5 = 'search' . $index . '5';
$searchkey6 = 'search' . $index . '6';
$searchkey7 = 'search' . $index . '7';

$conditions = array();
// Search by fullname.
Expand Down Expand Up @@ -1356,10 +1360,30 @@ function user_get_participants_sql($courseid, $groupid = 0, $accesssince = 0, $r
}
$conditions[] = $idnumber;

// Search by middlename.
$middlename = $DB->sql_like('middlename', ':' . $searchkey4, false, false);
$conditions[] = $middlename;

// Search by alternatename.
$alternatename = $DB->sql_like('alternatename', ':' . $searchkey5, false, false);
$conditions[] = $alternatename;

// Search by firstnamephonetic.
$firstnamephonetic = $DB->sql_like('firstnamephonetic', ':' . $searchkey6, false, false);
$conditions[] = $firstnamephonetic;

// Search by lastnamephonetic.
$lastnamephonetic = $DB->sql_like('lastnamephonetic', ':' . $searchkey7, false, false);
$conditions[] = $lastnamephonetic;

$wheres[] = "(". implode(" OR ", $conditions) .") ";
$params[$searchkey1] = "%$keyword%";
$params[$searchkey2] = "%$keyword%";
$params[$searchkey3] = "%$keyword%";
$params[$searchkey4] = "%$keyword%";
$params[$searchkey5] = "%$keyword%";
$params[$searchkey6] = "%$keyword%";
$params[$searchkey7] = "%$keyword%";
}
}

Expand Down

0 comments on commit 358b10a

Please sign in to comment.