Пример #1
0
 /**
  * 更新联系人分组名
  * @param int $id 分组ID
  */
 public function update($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, Kohana::lang('contact.method_not_exist'));
     }
     $data = $this->get_data();
     $name = isset($data['name']) ? $data['name'] : '';
     $id = (int) $id;
     if (empty($id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_id_empty'));
     } elseif (empty($name)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_empty'));
     } elseif (mb_strlen($name, 'utf8') > 32) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_too_long'));
     } elseif ($this->model->check_name($this->user_id, $name, $id)) {
         $this->send_response(400, NULL, Kohana::lang('contact.group_name_exist'));
     } else {
         $status = $this->model->edit($this->user_id, $name, $id);
         if ($status == FALSE) {
             $this->send_response(404, NULL, Kohana::lang('contact.group_not_exist'));
         } else {
             $this->send_response(200, array('id' => (int) $id, 'name' => $name), '', FALSE);
         }
     }
 }