Example #1
0
 /**
  * 单例模式
  * @return Contact_Mapper 返回实例对象
  */
 public static function &instance()
 {
     if (!isset(Contact_Mapper::$instance)) {
         // Create a new instance
         Contact_Mapper::$instance = new Contact_Mapper();
     }
     return Contact_Mapper::$instance;
 }
Example #2
0
 /**
  * 是否有同步记录
  * @param int $user_id 用户ID
  * @param int $app_id 应用ID
  * @param string $device_id 设备ID
  * @return bool
  */
 public function has_history($user_id, $app_id, $device_id = '')
 {
     $key = $this->cache_pre . 'has_history_' . $user_id . '_' . $app_id . '_' . $device_id;
     $result = $this->cache->get($key);
     if (!$result) {
         $result = $this->contact_mapper->has_history($user_id, $app_id, $device_id);
         $this->cache->set($key, $result, NULL, 0);
     }
     return (bool) $result;
 }
Example #3
0
 /**
  * 批量分组
  * @param int $user_id 用户ID
  * @param array $category_ids 分组名
  * @param array $ids 联系人ID
  * @return array
  */
 public function set_contact_category($user_id, $category_ids, $ids)
 {
     $category_list = $this->contact_mapper->get_contact_category_list($user_id);
     $add_ids = $delete_ids = array();
     foreach ($ids as $id) {
         $category_list[$id] = isset($category_list[$id]) ? $category_list[$id] : array();
         if ($add = array_diff($category_ids, $category_list[$id])) {
             $add_ids[$id] = $add;
         }
         if ($delete = array_diff($category_list[$id], $category_ids)) {
             $delete_ids[$id] = $delete;
         }
     }
     $ids = array_unique(array_merge(array_keys($add_ids), array_keys($delete_ids)));
     if ($ids and $this->contact_model->save_snapshot($user_id)) {
         $this->contact_mapper->set_contact_category($user_id, $add_ids, $delete_ids);
         if ($this->contact_model->update_contact_modified($user_id, $ids)) {
             return $ids;
         }
     }
     return array();
 }
Example #4
0
 /**
  * 修改联系人
  * @param Contact $contact
  * @param string $mode
  */
 public function edit($gid, Contact $contact, $mode = 'default')
 {
     return $this->group_contact_mapper->update($gid, $contact, $mode);
 }
Example #5
0
 /**
  * 根据手机号码获取用户联系人的姓名
  * @param $user_id 用户ID
  * @param $mobile 手机号码
  * @param string $zone_code 国家码
  * @return array
  */
 public function get_contact_formatted_name($user_id, $mobile, $zone_code = '86')
 {
     $result = array();
     if ($mobile) {
         $zone_code = $zone_code ? $zone_code : '86';
         $search = '+' . $zone_code . $mobile;
         $ids = Contact_Mapper::instance()->get_id_by_tel($user_id, $search);
         $contact_model = Contact_Model::instance();
         foreach ($ids as $id) {
             $contact = $contact_model->get($user_id, $id);
             $result[] = $contact->get_formatted_name();
         }
     }
     return $result;
 }