Esempio n. 1
0
 /**
  * 根据群联系人对象创建群联系人
  * @param Group_Contact $group_contact 群联系人对象
  * @throws Exception
  */
 public function insert($group_contact)
 {
     $query = $this->db->query("INSERT INTO `gcp_contacts` (`gid`,`uid`, `formatted_name`," . " `phonetic`, `given_name`, `middle_name`, `family_name`," . " `prefix`, `suffix`, `organization`, `department`, `note`," . " `birthday`, `title`, `nickname`, `sort`," . "`created`, `modified`, `fid`) VALUES (? , ?, " . " ? , ?, ? , ? , ? , ? , ? , ? , ?, ? , ? , ? , ? , ? , ? , ? , ? )", array($group_contact->get_group_id(), $group_contact->get_user_id(), $group_contact->get_formatted_name(), $group_contact->get_phonetic(), $group_contact->get_given_name(), $group_contact->get_middle_name(), $group_contact->get_family_name(), $group_contact->get_prefix(), $group_contact->get_suffix(), $group_contact->get_organization(), $group_contact->get_department(), $group_contact->get_note(), $group_contact->get_birthday(), $group_contact->get_title(), $group_contact->get_nickname(), $group_contact->get_sort(), $group_contact->get_modified_at(), $group_contact->get_modified_at(), $group_contact->get_momo_user_id()));
     $id = $query->insert_id();
     if ($id) {
         $sqls = array_merge($this->_edit_avatar($group_contact->get_group_id(), $id, $group_contact->get_avatar()));
         foreach (array('emails', 'tels', 'addresses', 'ims', 'urls', 'events', 'relations') as $type) {
             $sqls = array_merge($sqls, $this->_add_info($group_contact->get_group_id(), $id, $type, call_user_func(array($group_contact, 'get_' . $type))));
         }
         foreach ($sqls as $sql) {
             $this->db->query($sql);
         }
         $inserted = $this->find_by_id($group_contact->get_group_id(), $id);
         // clean up database related fields in parameter instance
         if (method_exists($inserted, 'set_id')) {
             $group_contact->set_id($inserted->get_id());
             $group_contact->set_created_at($inserted->get_created_at());
             $group_contact->set_modified_at($inserted->get_modified_at());
         }
     } else {
         throw new Exception('DB Error: Add Group_Contact Fail');
     }
 }