Skip to content

Commit

Permalink
MDL-24079 converted sql_ilike() to new sql_like in user selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 4, 2010
1 parent 086339d commit f63ac65
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
9 changes: 5 additions & 4 deletions lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,27 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp
$search='', $firstinitial='', $lastinitial='', $extraselect='', array $extraparams=null) {
global $DB;

$LIKE = $DB->sql_ilike();
$fullname = $DB->sql_fullname();

$select = "deleted <> 1";
$params = array();

if (!empty($search)) {
$search = trim($search);
$select .= " AND ($fullname $LIKE :search1 OR email $LIKE :search2 OR username = :search3)";
$select .= " AND (". $DB->sql_like($fullname, ':search1', false, false).
" OR ". $DB->sql_like('email', ':search2', false, false).
" OR username = :search3)";
$params['search1'] = "%$search%";
$params['search2'] = "%$search%";
$params['search3'] = "$search";
}

if ($firstinitial) {
$select .= " AND firstname $LIKE :fni";
$select .= " AND ". $DB->sql_like('firstname', ':fni', false, false);
$params['fni'] = "$firstinitial%";
}
if ($lastinitial) {
$select .= " AND lastname $LIKE :lni";
$select .= " AND ". $DB->sql_like('lastname', ':lni', false, false);
$params['lni'] = "$lastinitial%";
}

Expand Down
16 changes: 9 additions & 7 deletions user/filters/courserole.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,27 @@ function get_sql_filter($data) {
$name = 'ex_courserole'.$counter++;

$value = $data['value'];
$roleid = (int)$data['roleid'];
$categoryid = (int)$data['categoryid'];
$roleid = $data['roleid'];
$categoryid = $data['categoryid'];

$params = array();

if (empty($value) and empty($roleid) and empty($categoryid)) {
return array('', $params);
}

$timenow = round(time(), 100); // rounding - enable sql caching
$where = "b.contextlevel=50 AND a.timestart<$timenow AND (a.timeend=0 OR a.timeend>$timenow)";
$where = "b.contextlevel=50";
if ($roleid) {
$where .= " AND a.roleid=$roleid";
$where .= " AND a.roleid = :roleid";
$params['roleid'] = $roleid;

}
if ($categoryid) {
$where .= " AND c.category=$categoryid";
$where .= " AND c.category = :categoryid";
$params['categoryid'] = $categoryid;
}
if ($value) {
$where .= " AND c.shortname ".$DB->sql_ilike()." :$name";
$where .= " AND c.shortname = :$name";
$params[$name] = $value;
}
return array("id IN (SELECT userid
Expand Down
13 changes: 6 additions & 7 deletions user/filters/profilefield.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,34 @@ function get_sql_filter($data) {

$where = "";
$op = " IN ";
$ilike = $DB->sql_ilike();

if ($operator < 5 and $value === '') {
return '';
}

switch($operator) {
case 0: // contains
$where = "data $ilike :$name";
$where = $DB->sql_like('data', ":$name", false, false);
$params[$name] = "%$value%";
break;
case 1: // does not contain
$where = "data NOT $ilike :$name";
$where = "data NOT LIKE :$name"; //TODO: MDL-24080
$params[$name] = "%$value%";
break;
case 2: // equal to
$where = "data $ilike :$name";
$where = $DB->sql_like('data', ":$name", false, false);
$params[$name] = "$value";
break;
case 3: // starts with
$where = "data $ilike :$name";
$where = $DB->sql_like('data', ":$name", false, false);
$params[$name] = "$value%";
break;
case 4: // ends with
$where = "data $ilike :$name";
$where = $DB->sql_like('data', ":$name", false, false);
$params[$name] = "%$value";
break;
case 5: // empty
$where = "data=:$name";
$where = "data = :$name";
$params[$name] = "";
break;
case 6: // is not defined
Expand Down
18 changes: 8 additions & 10 deletions user/filters/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,35 @@ function get_sql_filter($data) {
return '';
}

$ilike = $DB->sql_ilike();

switch($operator) {
case 0: // contains
$res = "$ilike :$name";
$res = $DB->sql_like($field, ":$name", false, false);
$params[$name] = "%$value%";
break;
case 1: // does not contain
$res = "NOT $ilike :$name";
$res = "$field NOT LIKE :$name"; //TODO: MDL-24080
$params[$name] = "%$value%";
break;
case 2: // equal to
$res = "$ilike :$name";
$res = $DB->sql_like($field, ":$name", false, false);
$params[$name] = "$value";
break;
case 3: // starts with
$res = "$ilike :$name";
$res = $DB->sql_like($field, ":$name", false, false);
$params[$name] = "$value%";
break;
case 4: // ends with
$res = "$ilike :$name";
$res = $DB->sql_like($field, ":$name", false, false);
$params[$name] = "%$value";
break;
case 5: // empty
$res = "=:$name";
$params[$name] = "";
$res = "$field = :$name";
$params[$name] = $DB->sql_empty();
break;
default:
return '';
}
return array($field.' '.$res, $params);
return array($res, $params);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@
$totalcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params);

if (!empty($search)) {
$LIKE = $DB->sql_ilike();
$fullname = $DB->sql_fullname('u.firstname','u.lastname');
$wheres[] = "($fullname $LIKE :search1 OR email $LIKE :search2 OR idnumber $LIKE :search3) ";
$wheres[] = "(". $DB->sql_like($fullname, ':search1', false, false) .
" OR ". $DB->sql_like('email', ':search2', false, false) .
" OR ". $DB->sql_like('idnumber', ':search3', false, false) .") ";
$params['search1'] = "%$search%";
$params['search2'] = "%$search%";
$params['search3'] = "%$search%";
Expand Down
5 changes: 2 additions & 3 deletions user/selector/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,14 @@ protected function search_sql($search, $u) {
foreach ($this->extrafields as $field) {
$conditions[] = $u . $field;
}
$ilike = ' ' . $DB->sql_ilike();
if ($this->searchanywhere) {
$searchparam = '%' . $search . '%';
} else {
$searchparam = $search . '%';
}
$i = 0;
foreach ($conditions as &$condition) {
$condition .= "$ilike :con{$i}00";
foreach ($conditions as $key=>$condition) {
$conditions[$key] = $DB->sql_like($condition, ":con{$i}00", false, false);
$params["con{$i}00"] = $searchparam;
$i++;
}
Expand Down

0 comments on commit f63ac65

Please sign in to comment.