示例#1
0
 /**
  * 根据标签查找联系人
  * @param Group_Contact $group_contact
  * @return array
  */
 public function find_by_tags(Group_Contact $group_contact)
 {
     $keys = array();
     $others = array();
     //组织SQL
     foreach ($this->map as $field) {
         $name = (string) $field->name;
         $getprop = (string) $field->accessor;
         if ($getprop) {
             $value = call_user_func(array($group_contact, $getprop));
             if ($value) {
                 if (in_array($name, array('tels', 'emails', 'addresses', 'ims', 'urls', 'relations', 'events'))) {
                     if (in_array($name, array('tels', 'emails', 'ims'))) {
                         $others[$name] = $value;
                     }
                 } else {
                     $keys['gcp_contacts.' . $name] = $value;
                 }
             }
         }
     }
     if (!array_key_exists('gcp_contacts.deleted', $keys)) {
         $keys['gcp_contacts.deleted'] = 0;
     }
     if (!empty($others)) {
         $this->db->select('gcp_contacts.*')->from('gcp_contacts')->where($keys);
         $type = key($others);
         $other = $others[$type];
         $tmp = array();
         foreach ($other as $val) {
             $tmp[] = $val['value'];
         }
         $this->db->join('gcp_' . $type, 'gcp_contacts.gcid = gcp_' . $type . '.gcid', '', 'LEFT')->in('gcp_' . $type . '.value', $tmp);
         $query = $this->db->get();
     } else {
         $query = $this->db->getwhere('gcp_contacts', $keys);
     }
     $result = array();
     if ($query->count()) {
         $rows = $query->result_array(FALSE);
         foreach ($rows as $row) {
             $result[] = $row['gcid'];
         }
     }
     return $result;
 }
示例#2
0
 /**
  * 根据标签查找联系人
  * @param Contact $contact 联系人对象
  * @param bool $is_no_name
  * @return array
  */
 public function find_by_tags(Contact $contact, $is_no_name = FALSE)
 {
     //组织SQL
     $keys = array_filter($contact->get_main_info());
     if ($is_no_name === TRUE) {
         $keys['formatted_name'] = '';
     }
     $table = $this->get_table($contact->get_user_id(), 'contacts');
     $query = $this->db->getwhere($table, $keys);
     $result = array();
     if ($query->count()) {
         $rows = $query->result_array(FALSE);
         foreach ($rows as $row) {
             $result[] = (int) $row['cid'];
         }
     }
     return $result;
 }