| | |
| | | * @param boolean True for strict (=), False for partial (LIKE) matching |
| | | * @param boolean True if results are requested, False if count only |
| | | * @param boolean True to skip the count query (select only) |
| | | * @param array List of fields that cannot be empty |
| | | * @return Indexed list of contact records and 'count' value |
| | | */ |
| | | function search($fields, $value, $strict=false, $select=true, $nocount=false) |
| | | function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array()) |
| | | { |
| | | if (!is_array($fields)) |
| | | $fields = array($fields); |
| | | if (!is_array($required) && !empty($required)) |
| | | $required = array($required); |
| | | |
| | | $add_where = array(); |
| | | $where = $and_where = array(); |
| | | |
| | | foreach ($fields as $col) { |
| | | if ($col == 'ID' || $col == $this->primary_key) { |
| | | $ids = !is_array($value) ? explode(',', $value) : $value; |
| | | $ids = $this->db->array2list($ids, 'integer'); |
| | | $add_where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; |
| | | $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; |
| | | } |
| | | else if ($strict) |
| | | $add_where[] = $this->db->quoteIdentifier($col).'='.$this->db->quote($value); |
| | | $where[] = $this->db->quoteIdentifier($col).' = '.$this->db->quote($value); |
| | | else |
| | | $add_where[] = $this->db->ilike($col, '%'.$value.'%'); |
| | | $where[] = $this->db->ilike($col, '%'.$value.'%'); |
| | | } |
| | | |
| | | if (!empty($add_where)) { |
| | | $this->set_search_set(join(' OR ', $add_where)); |
| | | foreach ($required as $col) { |
| | | $and_where[] = $this->db->quoteIdentifier($col).' <> '.$this->db->quote(''); |
| | | } |
| | | |
| | | if (!empty($where)) |
| | | $where = join(' OR ', $where); |
| | | |
| | | if (!empty($and_where)) |
| | | $where = ($where ? "($where) AND " : '') . join(' AND ', $and_where); |
| | | |
| | | if (!empty($where)) { |
| | | $this->set_search_set($where); |
| | | if ($select) |
| | | $this->list_records(null, 0, $nocount); |
| | | else |