Skip to content

Commit

Permalink
Simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed May 31, 2016
1 parent 7864a98 commit f466899
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions program/lib/Roundcube/rcube_contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function list_records($cols = null, $subset = 0, $nocount = false)
" WHERE c.`del` <> 1" .
" AND c.`user_id` = ?" .
($this->group_id ? " AND m.`contactgroup_id` = ?" : "").
($this->filter ? " AND (".$this->filter.")" : "") .
($this->filter ? " AND ".$this->filter : "") .
" ORDER BY ". $this->db->concat($order_cols) .
" " . $this->sort_order,
$start_row,
Expand Down Expand Up @@ -314,25 +314,13 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r
foreach ((array)$fields as $idx => $col) {
$val = $value[$idx];

if (!strlen($val))
if (!strlen($val)) {
continue;
}

// table column
if (in_array($col, $this->table_cols)) {
switch ($mode) {
case 1: // strict
$where[] = '(' . $this->db->quote_identifier($col) . ' = ' . $this->db->quote($val)
. ' OR ' . $this->db->ilike($col, $val . $AS . '%')
. ' OR ' . $this->db->ilike($col, '%' . $AS . $val . $AS . '%')
. ' OR ' . $this->db->ilike($col, '%' . $AS . $val) . ')';
break;
case 2: // prefix
$where[] = '(' . $this->db->ilike($col, $val . '%')
. ' OR ' . $this->db->ilike($col, $AS . $val . '%') . ')';
break;
default: // partial
$where[] = $this->db->ilike($col, '%' . $val . '%');
}
$where[] = $this->fulltext_sql_where($val, $mode, $col);
}
// vCard field
else {
Expand Down Expand Up @@ -360,7 +348,7 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r
}

foreach (array_intersect($required, $this->table_cols) as $col) {
$and_where[] = $this->db->quote_identifier($col).' <> '.$this->db->quote('');
$where[] = $this->db->quote_identifier($col).' <> '.$this->db->quote('');
}
$required = array_diff($required, $this->table_cols);

Expand All @@ -369,9 +357,6 @@ function search($fields, $value, $mode = 0, $select = true, $nocount = false, $r
$where = join(" AND ", $where);
}

if (!empty($and_where))
$where = ($where ? "($where) AND " : '') . join(' AND ', $and_where);

// Post-searching in vCard data fields
// we will search in all records and then build a where clause for their IDs
if (!empty($post_search) || !empty($required)) {
Expand Down

0 comments on commit f466899

Please sign in to comment.