Пример #1
0
 /**
  * 更新联系人所在分组
  * @param int $id
  * @param string $type
  */
 private function _contact_to_group($id, $type = 'add')
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
     }
     $id = (int) $id;
     if ($type == 'add' and empty($id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
     }
     if (!empty($id) and !$this->model->get_category_name($this->user_id, $id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_not_exist'));
     }
     $data = $this->get_data();
     $ids = !empty($data['ids']) ? explode(',', $data['ids']) : array();
     if (empty($ids)) {
         $this->send_response(400, NULL, Kohana::lang('contact.contact_ids_empty'));
     }
     $result = array();
     $update_ids = $this->model->move_contact_category($this->user_id, $id, $ids, $type);
     if ($update_ids) {
         $now = api::get_now_time();
         foreach ($update_ids as $id) {
             $result[] = array('id' => (int) $id, 'modified_at' => $now);
         }
     }
     $this->send_response(200, $result, '', FALSE);
 }