| | |
| | | private $result = null; |
| | | private $search_fields; |
| | | private $search_string; |
| | | private $cache; |
| | | private $table_cols = array('name', 'email', 'firstname', 'surname', 'vcard'); |
| | | |
| | | /** public properties */ |
| | |
| | | function set_search_set($filter) |
| | | { |
| | | $this->filter = $filter; |
| | | $this->cache = null; |
| | | } |
| | | |
| | | |
| | |
| | | function set_group($gid) |
| | | { |
| | | $this->group_id = $gid; |
| | | $this->cache = null; |
| | | } |
| | | |
| | | |
| | |
| | | $this->filter = null; |
| | | $this->search_fields = null; |
| | | $this->search_string = null; |
| | | $this->cache = null; |
| | | } |
| | | |
| | | |
| | |
| | | if (!$this->groups) |
| | | return $results; |
| | | |
| | | $sql_filter = $search ? "AND " . $this->db->ilike('name', '%'.$search.'%') : ''; |
| | | $sql_filter = $search ? " AND " . $this->db->ilike('name', '%'.$search.'%') : ''; |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT * FROM ".get_table_name('contactgroups'). |
| | |
| | | $length = $subset != 0 ? abs($subset) : $this->page_size; |
| | | |
| | | if ($this->group_id) |
| | | $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". |
| | | $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". |
| | | " ON (m.contact_id = c.".$this->primary_key.")"; |
| | | |
| | | $sql_result = $this->db->limitquery( |
| | | "SELECT * FROM ".$this->db_name." AS c ".$join . |
| | | "SELECT * FROM ".$this->db_name." AS c" . |
| | | $join . |
| | | " WHERE c.del<>1" . |
| | | " AND c.user_id=?" . |
| | | ($this->group_id ? " AND m.contactgroup_id=?" : ""). |
| | | ($this->filter ? " AND (".$this->filter.")" : "") . |
| | | " AND c.user_id=?" . |
| | | ($this->group_id ? " AND m.contactgroup_id=?" : ""). |
| | | ($this->filter ? " AND (".$this->filter.")" : "") . |
| | | " ORDER BY c.name", |
| | | $start_row, |
| | | $length, |
| | |
| | | else if ($this->list_page <= 1) { |
| | | if ($cnt < $this->page_size && $subset == 0) |
| | | $this->result->count = $cnt; |
| | | else if (isset($this->cache['count'])) |
| | | $this->result->count = $this->cache['count']; |
| | | else |
| | | $this->result->count = $this->_count(); |
| | | } |
| | |
| | | { |
| | | if (!is_array($fields)) |
| | | $fields = array($fields); |
| | | |
| | | |
| | | $add_where = array(); |
| | | foreach ($fields as $col) { |
| | | if ($col == 'ID' || $col == $this->primary_key) { |
| | | $ids = !is_array($value) ? explode(',', $value) : $value; |
| | | $add_where[] = 'c.' . $this->primary_key.' IN ('.join(',', $ids).')'; |
| | | $ids = join(',', array_map(array($this->db, 'quote'), $ids)); |
| | | $add_where[] = 'c.' . $this->primary_key.' IN ('.$ids.')'; |
| | | } |
| | | else if ($strict) |
| | | $add_where[] = $this->db->quoteIdentifier($col).'='.$this->db->quote($value); |
| | |
| | | */ |
| | | function count() |
| | | { |
| | | return new rcube_result_set($this->_count(), ($this->list_page-1) * $this->page_size); |
| | | $count = isset($this->cache['count']) ? $this->cache['count'] : $this->_count(); |
| | | |
| | | return new rcube_result_set($count, ($this->list_page-1) * $this->page_size); |
| | | } |
| | | |
| | | |
| | |
| | | private function _count() |
| | | { |
| | | if ($this->group_id) |
| | | $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". |
| | | $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". |
| | | " ON (m.contact_id=c.".$this->primary_key.")"; |
| | | |
| | | // count contacts for this user |
| | | $sql_result = $this->db->query( |
| | | "SELECT COUNT(c.contact_id) AS rows". |
| | | " FROM ".$this->db_name." AS c ".$join. |
| | | " WHERE c.del<>1". |
| | | " FROM ".$this->db_name." AS c". |
| | | $join. |
| | | " WHERE c.del<>1". |
| | | " AND c.user_id=?". |
| | | ($this->group_id ? " AND m.contactgroup_id=?" : ""). |
| | | ($this->filter ? " AND (".$this->filter.")" : ""), |
| | |
| | | ); |
| | | |
| | | $sql_arr = $this->db->fetch_assoc($sql_result); |
| | | return (int) $sql_arr['rows']; |
| | | |
| | | $this->cache['count'] = (int) $sql_arr['rows']; |
| | | |
| | | return $this->cache['count']; |
| | | } |
| | | |
| | | |
| | |
| | | if ($insert_id && $this->group_id) |
| | | $this->add_to_group($this->group_id, $insert_id); |
| | | |
| | | $this->cache = null; |
| | | |
| | | return $insert_id; |
| | | } |
| | | |
| | |
| | | */ |
| | | function delete($ids) |
| | | { |
| | | if (is_array($ids)) |
| | | $ids = join(',', $ids); |
| | | if (!is_array($ids)) |
| | | $ids = explode(',', $ids); |
| | | |
| | | $ids = join(',', array_map(array($this->db, 'quote'), $ids)); |
| | | |
| | |
| | | $this->user_id |
| | | ); |
| | | |
| | | $this->cache = null; |
| | | |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |
| | |
| | | function delete_all() |
| | | { |
| | | $this->db->query("DELETE FROM {$this->db_name} WHERE user_id=?", $this->user_id); |
| | | $this->cache = null; |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |
| | |
| | | $gid |
| | | ); |
| | | |
| | | $this->cache = null; |
| | | |
| | | return $this->db->affected_rows(); |
| | | } |
| | | |