/** * Save location data. * * @access public * @param int $id album_image_id * @return Response (json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_save_location($id = null) { $this->controller_common_api(function () use($id) { $this->response_body['errors']['message_default'] = sprintf('%sの%sに失敗しました。', term('site.location'), term('form.save')); $id = intval(\Input::post('id') ?: $id); $album_image = Model_AlbumImage::check_authority($id, $this->u->id, 'album_image_location'); $album_image_location = $album_image->album_image_location ?: Model_AlbumImageLocation::forge(); $val = \Validation::forge(); $val->add_model($album_image_location); $val->fieldset()->field('album_image_id')->delete_rule('required'); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); $album_image_location->album_image_id = $id; $album_image_location->latitude = $post['latitude']; $album_image_location->longitude = $post['longitude']; \DB::start_transaction(); $status = (bool) $album_image_location->save(); \DB::commit_transaction(); $data = array('status' => $status, 'album_image_location' => $album_image_location->to_array(), 'message' => sprintf('%sを%sしました。', term('site.location'), term('form.save'))); $this->set_response_body_api($data); }); }