public function test_check_type_album_image_timeline() { if (!($list = Model_Timeline::get4type_key('album_image_timeline'))) { $this->markTestSkipped('No record for test.'); } \Util_Develop::output_test_info(__FILE__, __LINE__); foreach ($list as $obj) { // check for reference data. $this->assertEquals('album', $obj->foreign_table); $album = \Album\Model_Album::check_authority($obj->foreign_id); $this->assertNotEmpty($album); // check for member $member = \Model_Member::check_authority($obj->member_id); $this->assertNotEmpty($member); // check for member_id $this->assertEquals($album->member_id, $obj->member_id); // check for timeline_child_data $timeline_child_datas = Model_TimelineChildData::get4timeline_id($obj->id); $this->assertNotEmpty($timeline_child_datas); $public_flag_max_range = null; if ($timeline_child_datas) { foreach ($timeline_child_datas as $timeline_child_data) { // check for reference data. $this->assertEquals('album_image', $timeline_child_data->foreign_table); // check for album_image $album_image = \Album\Model_AlbumImage::check_authority($timeline_child_data->foreign_id); $this->assertNotEmpty($album_image); // check for album_id $this->assertEquals($album->id, $album_image->album_id); // check for public_flag. $this->assertEquals($album_image->public_flag, $obj->public_flag); } } } }
/** * Create timeline * * @access public * @param int $parent_id target parent id * @return Response(json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_create() { $this->controller_common_api(function () { $this->response_body['errors']['message_default'] = term('timeline') . 'の' . term('form.post') . 'に失敗しました。'; $moved_files = array(); $album_image_ids = array(); $timeline = Model_Timeline::forge(); $val = \Validation::forge(); $val->add_model($timeline); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!strlen($post['body']) && !$file_tmps) { throw new \ValidationFailedException('Data is empty.'); } $type_key = 'normal'; $album_id = (int) \Input::post('album_id', 0); if ($file_tmps && $album_id) { $album = \Album\Model_Album::check_authority($album_id, $this->u->id); if (\Album\Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \ValidationFailedException('Album id is invalid.'); } $type_key = 'album_image'; } try { \DB::start_transaction(); if ($file_tmps) { if (!$album_id) { $type_key = 'album_image_timeline'; $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'timeline'); } list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $post['public_flag']); } else { $album_id = null; } $timeline = \Timeline\Site_Model::save_timeline($this->u->id, $post['public_flag'], $type_key, $album_id, null, $post['body'], $timeline, $album_image_ids); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files); } catch (\Exception $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } throw $e; } $data = array('id' => $timeline->id, 'message' => term('timeline') . 'を' . term('form.post') . 'しました。'); if (conf('service.facebook.shareDialog.myhome.autoPopupAfterCreated')) { $link = \Uri::create(Site_Util::get_detail_uri($timeline->id, $timeline->type)); $data['shareFacebook'] = array('obj' => array('link' => $link)); if ($album_image_ids && ($album_image = \Album\Model_AlbumImage::find($album_image_ids[0]))) { $data['shareFacebook']['obj']['picture'] = \Site_Util::get_media_uri(img_uri($album_image->file_name, 'thumbnail'), true); } } $this->set_response_body_api($data); }); }
public function delete_with_album_image($member_id) { $album_image_ids = array(); $deleted_files = null; if (Site_Util::check_type($this->type, 'album_image_timeline')) { try { $album = \Album\Model_Album::check_authority($this->foreign_id, $member_id); } catch (\FuelException $e) { $album = null; } $album_image_ids = $album ? Model_TimelineChildData::get_foreign_ids4timeline_id($this->id) : null; } if ($album_image_ids) { \Album\Model_AlbumImage::delete_multiple($album_image_ids); } $this->delete(); }