Example #1
0
 /**
  * 单例模式
  * @return Group_Contact_Model
  */
 public static function &instance()
 {
     if (!isset(self::$instance)) {
         // Create a new instance
         self::$instance = new Group_Contact_Model();
     }
     return self::$instance;
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     $this->model = new Message_Model();
     $this->message_type = null;
     $this->activityModel = Activity_Model::instance();
     $this->friendModel = Friend_Model::instance();
     $this->groupModel = Group_Model::instance();
     $this->groupContactModel = Group_Contact_Model::instance();
     $this->contactModel = Contact_Model::instance();
 }
Example #3
0
 /**
  * 过滤输入、创建联系人对象
  * @param array $data 联系人信息
  * @return Contact $contact
  */
 private function _array_to_contact($data)
 {
     $contact = new Contact();
     $bjx_arr = Kohana::config_load('bjx');
     foreach ($data as $type => $value) {
         switch ($type) {
             case 'tels':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     foreach ($value as $val) {
                         //                            if (! in_array(trim($val['value']), $tmp)) {
                         //                                $tmp[] = trim($val['value']);
                         $values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $this->model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0);
                         //                            }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'ims':
                 if (!empty($value)) {
                     $values = $tmp = $protocols = array();
                     foreach ($value as $val) {
                         //                            $keys = array_keys($tmp, trim($val['value']));
                         //                            $key = isset($keys[0]) ? $keys[0] : - 1;
                         //                            if ($key < 0 or $protocols[$key] != $val['protocol']) {
                         //                                $tmp[] = trim($val['value']);
                         //                                $protocols[] = $val['protocol'];
                         $values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']);
                         //                            }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'addresses':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     //                        $t = '';
                     foreach ($value as $val) {
                         //                            $t = trim($val['country']) . '|' .
                         //                             trim($val['region']) . '|' . trim($val['city']) .
                         //                             '|' . trim($val['street']) . '|' .
                         //                             trim($val['postal']);
                         //                            if (! in_array($t, $tmp)) {
                         $values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']);
                         //                                $tmp[] = $t;
                         //                            }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'emails':
             case 'urls':
             case 'events':
             case 'relations':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     foreach ($value as $val) {
                         //                            if (! in_array(trim($val['value']), $tmp)) {
                         $tmp[] = trim($val['value']);
                         $values[] = array('value' => trim($val['value']), 'type' => $val['type']);
                         //                            }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'contact_group_ids':
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : array());
                 break;
             case 'birthday':
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? $this->_filter_birthday($value) : '');
                 break;
             case 'recycled':
             case 'favorited':
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? (int) $value : 0);
                 break;
             default:
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : '');
                 break;
         }
     }
     $formatted_name = $this->model->name_to_formatted_name($data['family_name'], $data['given_name']);
     //拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置
     if (empty($formatted_name) and !empty($data['formatted_name'])) {
         $name = $this->model->formatted_name_to_name($data['formatted_name']);
         $contact->set_given_name($name['given_name']);
         $contact->set_family_name($name['family_name']);
     } else {
         $fn = $formatted_name;
     }
     if (!empty($fn)) {
         require_once Kohana::find_file('vendor', 'pinyin/c2p');
         $phonetic = getPinYin($fn, false, ' ');
         $tmp = explode(' ', $phonetic);
         $sort = '';
         if (is_array($tmp)) {
             foreach ($tmp as $t) {
                 $sort .= isset($t[0]) ? $t[0] : '';
             }
         }
         if (empty($sort) or !preg_match("/[a-z]/", $sort[0])) {
             $sort = '#';
         }
         $sort = substr($sort, 0, 20);
         $contact->set_formatted_name($fn);
         $contact->set_phonetic(implode('', $tmp));
         $contact->set_sort($sort);
     } else {
         $contact->set_formatted_name('');
         $contact->set_phonetic('');
         $contact->set_sort('#');
     }
     $contact->set_source('web');
     return $contact;
 }