/** * Thread create * * @access public * @return Response */ public function action_create() { $thread = Model_Thread::forge(); $val = self::get_validation_object($thread); $images = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $image_tmps = array(); $moved_images = array(); $thread_image_ids = array(); $error_message = ''; try { $image_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); $is_changed = $thread->save_with_relations($this->u->id, $post, $image_tmps); list($moved_images, $thread_image_ids) = \Site_FileTmp::save_images($image_tmps, $thread->id, 'thread_id', 'thread_image'); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_images); $message = sprintf('%sを%sしました。', term('thread'), term('form.create_simple')); \Session::set_flash('message', $message); \Response::redirect('thread/detail/' . $thread->id); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_images) { \Site_FileTmp::move_files_to_tmp_dir($moved_images); } $images = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id); \Session::set_flash('error', $error_message); } } $this->set_title_and_breadcrumbs(term('thread') . 'を書く', array('thread' => term('thread', 'site.list')), null, 'thread'); $this->template->post_header = \View::forge('_parts/form_header'); $this->template->post_footer = \View::forge('_parts/form_footer'); $this->template->content = \View::forge('_parts/form', array('val' => $val, 'images' => $images)); }