Пример #1
0
 /**
  * Album edit images
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit_images($id = null)
 {
     $album = Model_Album::check_authority($id, $this->u->id, 'member');
     $album_images = Model_AlbumImage::find('all', array('where' => array(array('album_id' => $id)), 'order_by' => array('id' => 'asc')));
     $is_disabled_to_update_public_flag = Site_Util::check_album_disabled_to_update($album->foreign_table, true);
     $is_enabled_map = is_enabled_map('edit_images', 'album');
     $val = self::get_album_image_validation($is_disabled_to_update_public_flag);
     $shot_at = '';
     $posted_album_image_ids = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $deleted_files = array();
         $post = array();
         try {
             $is_delete = \Input::post('clicked_btn') == 'delete';
             $posted_album_image_ids = array_map('intval', \Input::post('album_image_ids', array()));
             if (empty($posted_album_image_ids)) {
                 throw new \FuelException('実施対象が選択されていません');
             }
             if (!\Util_Orm::check_ids_in_models($posted_album_image_ids, $album_images)) {
                 throw new \FuelException('実施対象が正しく選択されていません');
             }
             if (!$is_delete) {
                 if (!$val->run()) {
                     throw new \FuelException($val->show_errors());
                 }
                 $post = $val->validated();
                 if (!strlen($post['name']) && empty($post['shot_at']) && (!$is_disabled_to_update_public_flag && $post['public_flag'] == 99) && ($is_enabled_map && !strlen($post['latitude']) && !strlen($post['longitude']))) {
                     throw new \FuelException('入力してください');
                 }
             }
             \DB::start_transaction();
             if ($is_delete) {
                 $result = Model_AlbumImage::delete_multiple($posted_album_image_ids);
                 $message = $result . '件削除しました';
             } else {
                 $result = Model_AlbumImage::update_multiple_each($posted_album_image_ids, $post, $is_disabled_to_update_public_flag);
                 $message = $result . '件更新しました';
             }
             \DB::commit_transaction();
             \Session::set_flash('message', $message);
             \Response::redirect('album/edit_images/' . $id);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             $message = $e->getMessage() ?: '更新に失敗しました';
             \Session::set_flash('error', $message);
         }
     }
     $this->set_title_and_breadcrumbs(term('album_image', 'site.management'), array('/album/' . $id => $album->name), $album->member, 'album');
     $this->template->post_header = \View::forge('_parts/datetimepicker_header');
     $this->template->post_footer = \View::forge('_parts/edit_images_footer');
     $data = array('id' => $id, 'album' => $album, 'album_images' => $album_images, 'val' => $val, 'album_image_ids' => $posted_album_image_ids, 'is_disabled_to_update_public_flag' => $is_disabled_to_update_public_flag);
     $this->template->content = \View::forge('edit_images', $data);
 }