Ignore:
Timestamp:
Mar 31, 2010 11:23:22 AM (3 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
64d855c
Parents:
3baa72a
Message:

Asynchronously expand contact groups + skip count queries in autocompletion mode + check for the existance of contactgroups table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_contacts.php

    r3baa72a rc0297f4  
    4040  var $primary_key = 'contact_id'; 
    4141  var $readonly = false; 
    42   var $groups = true; 
     42  var $groups = false; 
    4343  var $list_page = 1; 
    4444  var $page_size = 10; 
     
    5959    $this->user_id = $user; 
    6060    $this->ready = $this->db && !$this->db->is_error(); 
     61     
     62    if (in_array('contactgroups', $this->db->list_tables())) 
     63      $this->groups = true; 
    6164  } 
    6265 
     
    114117  { 
    115118    $results = array(); 
     119     
     120    if (!$this->groups) 
     121      return $results; 
     122       
    116123    $sql_filter = $search ? "AND " . $this->db->ilike('name', '%'.$search.'%') : ''; 
    117124 
     
    135142   * List the current set of contact records 
    136143   * 
    137    * @param  array  List of cols to show 
    138    * @param  int    Only return this number of records, use negative values for tail 
     144   * @param  array   List of cols to show 
     145   * @param  int     Only return this number of records, use negative values for tail 
     146   * @param  boolean True to skip the count query (select only) 
    139147   * @return array  Indexed list of contact records, each a hash array 
    140148   */ 
    141   function list_records($cols=null, $subset=0) 
     149  function list_records($cols=null, $subset=0, $nocount=false) 
    142150  { 
    143151    // count contacts for this user 
    144     $this->result = $this->count(); 
     152    $this->result = $nocount ? new rcube_result_set(1) : $this->count(); 
    145153    $sql_result = NULL; 
    146154 
     
    149157    { 
    150158      if ($this->group_id) 
    151         $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS rcmgrouplinks". 
    152           " ON (rcmgrouplinks.contact_id=rcmcontacts.".$this->primary_key.")"; 
     159        $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 
     160          " ON (m.contact_id=c.".$this->primary_key.")"; 
    153161       
    154162      $start_row = $subset < 0 ? $this->result->first + $this->page_size + $subset : $this->result->first; 
     
    156164       
    157165      $sql_result = $this->db->limitquery( 
    158         "SELECT * FROM ".$this->db_name." AS rcmcontacts ".$join." 
    159          WHERE  rcmcontacts.del<>1 
    160          AND    rcmcontacts.user_id=?" . 
    161         ($this->group_id ? " AND rcmgrouplinks.contactgroup_id=?" : ""). 
     166        "SELECT * FROM ".$this->db_name." AS c ".$join." 
     167         WHERE  c.del<>1 
     168         AND    c.user_id=?" . 
     169        ($this->group_id ? " AND m.contactgroup_id=?" : ""). 
    162170        ($this->filter ? " AND (".$this->filter.")" : "") . 
    163         " ORDER BY rcmcontacts.name", 
     171        " ORDER BY c.name", 
    164172        $start_row, 
    165173        $length, 
     
    177185    } 
    178186     
     187    if ($nocount) 
     188      $this->result->count = count($this->result->records); 
     189     
    179190    return $this->result; 
    180191  } 
     
    188199   * @param boolean True for strict (=), False for partial (LIKE) matching 
    189200   * @param boolean True if results are requested, False if count only 
     201   * @param boolean True to skip the count query (select only) 
    190202   * @return Indexed list of contact records and 'count' value 
    191203   */ 
    192   function search($fields, $value, $strict=false, $select=true) 
     204  function search($fields, $value, $strict=false, $select=true, $nocount=false) 
    193205  { 
    194206    if (!is_array($fields)) 
     
    213225      $this->set_search_set(join(' OR ', $add_where)); 
    214226      if ($select) 
    215         $this->list_records(); 
     227        $this->list_records(null, 0, $nocount); 
    216228      else 
    217229        $this->result = $this->count(); 
     
    230242  { 
    231243    if ($this->group_id) 
    232       $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS rcmgrouplinks". 
    233         " ON (rcmgrouplinks.contact_id=rcmcontacts.".$this->primary_key.")"; 
     244      $join = "LEFT JOIN ".get_table_name('contactgroupmembers')." AS m". 
     245        " ON (m.contact_id=c.".$this->primary_key.")"; 
    234246       
    235247    // count contacts for this user 
    236248    $sql_result = $this->db->query( 
    237       "SELECT COUNT(rcmcontacts.contact_id) AS rows 
    238        FROM ".$this->db_name." AS rcmcontacts ".$join." 
    239        WHERE  rcmcontacts.del<>1 
    240        AND    rcmcontacts.user_id=?". 
    241        ($this->group_id ? " AND rcmgrouplinks.contactgroup_id=?" : ""). 
     249      "SELECT COUNT(c.contact_id) AS rows 
     250       FROM ".$this->db_name." AS c ".$join." 
     251       WHERE  c.del<>1 
     252       AND    c.user_id=?". 
     253       ($this->group_id ? " AND m.contactgroup_id=?" : ""). 
    242254       ($this->filter ? " AND (".$this->filter.")" : ""), 
    243255      $this->user_id, 
Note: See TracChangeset for help on using the changeset viewer.