コード例 #1
0
ファイル: album.php プロジェクト: uzura8/flockbird
 /**
  * @dataProvider update_provider
  */
 public function test_update($self_member_id, $values, $album_image_public_flag_expected, $timeline_public_flag_expected)
 {
     $album = $this->get_album();
     $before = array('name' => $album->name, 'body' => $album->body, 'public_flag' => $album->public_flag);
     // timeline view cache 作成
     if (self::$is_check_timeline_view_cache) {
         $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album'));
     }
     // album update
     list($album, $moved_files, $is_changed) = Model_Album::save_with_relations($values, $self_member_id, $album);
     self::$album = $album;
     // 返り値の確認
     $this->assertNotEmpty($album);
     // 件数(増えていないことを確認)
     $this->assertEquals(self::$album_count, \Util_Orm::get_count_all('\\Album\\Model_Album'));
     // album_image の値を変更した場合の public_flag の確認
     $album_images = Model_AlbumImage::get4album_id($album->id);
     $album_image = array_shift($album_images);
     if (!empty($values['is_update_children_public_flag'])) {
         $this->assertEquals($album_image_public_flag_expected, $album_image->public_flag);
     }
     // timeline 関連
     if (is_enabled('timeline')) {
         // 件数(増えていないことを確認)
         $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline'));
         $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache'));
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', $album->id, \Config::get('timeline.types.album'));
         $this->assertCount(1, $timelines);
         $timeline = array_shift($timelines);
         $this->assertEquals($album->member_id, $timeline->member_id);
         $this->assertEquals($timeline_public_flag_expected, $timeline->public_flag);
         $this->assertContains($timeline->created_at, \Util_Date::get_datetime_list($album->created_at));
         if ($is_changed) {
             if (self::check_sort_datetime_change(self::$album, $before)) {
                 $this->assertEquals($album->updated_at, $timeline->sort_datetime);
             }
             $this->assertContains($timeline->updated_at, \Util_Date::get_datetime_list($album->updated_at));
         }
         // timeline view cache check
         if (self::$is_check_timeline_view_cache) {
             $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id));
         }
     }
 }
コード例 #2
0
ファイル: album.php プロジェクト: uzura8/flockbird
 /**
  * Album edit
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit($id = null)
 {
     $album = Model_Album::check_authority($id, $this->u->id, 'member');
     if (Site_Util::check_album_disabled_to_update($album->foreign_table, true)) {
         throw new \HttpForbiddenException();
     }
     $val = $this->get_validation($album, true);
     if (\Input::method() == 'POST') {
         try {
             \Util_security::check_csrf();
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             \DB::start_transaction();
             list($album, $moved_files) = Model_Album::save_with_relations($post, $this->u->id, $album);
             \DB::commit_transaction();
             \Session::set_flash('message', term('album') . 'を編集をしました。');
             \Response::redirect('album/' . $album->id);
         } catch (Exception $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('album'), term('form.do_edit')), array('/album/' . $id => $album->name), $album->member, 'album');
     $this->template->content = \View::forge('_parts/form', array('val' => $val, 'album' => $album, 'is_edit' => true));
 }