public function save_with_relations($member_id, $values, $file_tmps = null, $album_images = array(), $files = array()) { if (!empty($this->member_id) && $this->member_id != $member_id) { throw new \InvalidArgumentException('Parameter member_id is invalid.'); } $is_new = $this->_is_new; $this->member_id = $member_id; if (isset($values['title'])) { $this->title = $values['title']; } if (isset($values['body'])) { $this->body = $values['body']; } if (isset($values['public_flag'])) { $this->public_flag = $values['public_flag']; } $is_changed_public_flag = $this->is_changed('public_flag'); if (!$this->is_published) { if (!empty($values['is_published'])) { $this->is_published = 1; } elseif (empty($values['is_draft'])) { $this->is_published = 1; } } $is_published = $this->is_changed('is_published') && $this->is_published; if (!empty($values['published_at_time'])) { if (!\Util_Date::check_is_same_minute($values['published_at_time'], $this->published_at)) { $this->published_at = $values['published_at_time'] . ':00'; } } elseif (!$this->published_at && $is_published) { $this->published_at = \Date::time()->format('mysql'); } $is_changed = $this->is_changed(); if ($is_changed) { $this->save(); } $moved_files = array(); if (is_enabled('album')) { $image_public_flag = $this->is_published ? $this->public_flag : FBD_PUBLIC_FLAG_PRIVATE; if ($file_tmps) { $album_id = \Album\Model_Album::get_id_for_foreign_table($member_id, 'note'); list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $image_public_flag); \Note\Model_NoteAlbumImage::save_multiple($this->id, $album_image_ids); } // フォーム編集時 if ($album_images && $files) { \Site_Upload::update_image_objs4file_objects($album_images, $files, $image_public_flag); } elseif ($is_published && ($saved_album_images = Model_NoteAlbumImage::get_album_image4note_id($this->id))) { foreach ($saved_album_images as $saved_album_image) { $saved_album_image->update_public_flag($this->public_flag, true); } } } if (is_enabled('timeline')) { if ($is_published) { // timeline 投稿 \Timeline\Site_Model::save_timeline($member_id, $this->public_flag, 'note', $this->id, $this->updated_at); } elseif (!$is_new && $is_changed_public_flag) { // timeline の public_flag の更新 \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($this->public_flag, 'note', $this->id, \Config::get('timeline.types.note')); } } return array($is_changed, $is_published, $moved_files); }
public static function get_timeline_images($type, $foreign_id, $timeline_id = null, $access_from = null, $is_detail = false) { // defaults $images = array(); $images['file_cate'] = 'ai'; $images['size'] = 'N_M'; $images['column_count'] = 3; switch ($type) { case \Config::get('timeline.types.album_image_profile'): $images['list'] = array(); if ($list = \Album\Model_AlbumImage::check_authority($foreign_id)) { $images['list'][] = $list; $images['column_count'] = 2; } break; case \Config::get('timeline.types.profile_image'): $images['list'] = array(); if ($list = \Model_File::find($foreign_id)) { $images['list'][] = $list; $images['file_cate'] = 'm'; $images['size'] = 'LL'; $images['column_count'] = 2; } break; case \Config::get('timeline.types.note'): list($images['list'], $images['count_all']) = \Note\Model_NoteAlbumImage::get_album_image4note_id($foreign_id, $is_detail ? 0 : \Config::get('timeline.articles.thumbnail.limit.default'), array('id' => 'asc'), true); $images['parent_page_uri'] = 'note/' . $foreign_id; break; case \Config::get('timeline.types.thread'): list($images['list'], $images['count_all']) = \Thread\Model_ThreadImage::get4thread_id($foreign_id, 3, true); $images['file_cate'] = 't'; $images['size'] = 'M'; $images['column_count'] = 3; $images['parent_page_uri'] = 'thread/' . $foreign_id; break; case \Config::get('timeline.types.album'): case \Config::get('timeline.types.album_image'): $images['list'] = array(); $images['count'] = 0; if ($album_image_ids = Model_TimelineChildData::get_foreign_ids4timeline_id($timeline_id)) { list($images['list'], $images['count']) = \Album\Model_AlbumImage::get_list_and_count(array('where' => \Site_Model::get_where_public_flag4access_from($access_from, array(array('id', 'in', $album_image_ids))), $is_detail ? 0 : 'limit' => \Config::get('timeline.articles.thumbnail.limit.default'), 'order_by' => array('created_at' => 'asc'))); } $images['count_all'] = \Album\Model_AlbumImage::get_list_count(array('where' => \Site_Model::get_where_public_flag4access_from($access_from, array(array('album_id', $foreign_id))))); $images['parent_page_uri'] = 'album/' . $foreign_id; break; case \Config::get('timeline.types.album_image_timeline'): list($images['list'], $images['count']) = \Album\Model_AlbumImage::get_list_and_count(array('where' => \Site_Model::get_where_public_flag4access_from($access_from, array(array('id', 'in', Model_TimelineChildData::get_foreign_ids4timeline_id($timeline_id)))), $is_detail ? 0 : 'limit' => \Config::get('timeline.articles.thumbnail.limit.album_image_timeline'), 'order_by' => array('created_at' => 'asc'))); $images['count_all'] = $images['count']; $images['parent_page_uri'] = 'timeline/' . $timeline_id; break; default: break; } return $images; }
public function test_delete_with_relations() { $note = $this->get_last_row(); $is_draft = !$note->is_published; $note_id = $note->id; $note->delete_with_relations(); // 件数 // note $this->assertEquals(self::$note_count - 1, Model_Note::get_count()); // note_album_image $note_album_images = \Note\Model_NoteAlbumImage::query()->where('note_id', $note_id)->get(); $this->assertEmpty($note_album_images); // timeline if (is_enabled('timeline')) { if ($is_draft) { $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')); } else { $this->assertEquals(self::$timeline_count - 1, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count - 2, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note->id, \Config::get('timeline.types.note')); $this->assertEmpty($timelines); } } }
public static function delete_note_view_cache4album_image_id($album_image_id) { if (!($note_id = \Note\Model_NoteAlbumImage::get_note_id4album_image_id($album_image_id))) { return; } if (!($timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note_id))) { return; } $timeline = array_shift($timelines); \Timeline\Site_Util::delete_cache($timeline->id, $timeline->type); }
<?php echo render('_parts/member_contents_box', array('member' => $note->member, 'model' => 'note', 'id' => $id, 'size' => 'M', 'public_flag' => $note->public_flag, 'date' => array('datetime' => $note->published_at ? $note->published_at : $note->updated_at))); $dropdown_btn_group_attr = array('id' => 'btn_dropdown_' . $id, 'class' => array('dropdown', 'boxBtn')); $dropdown_btn_attr = array('class' => 'js-dropdown_content_menu', 'data-uri' => sprintf('note/api/menu/%d.html', $id), 'data-member_id' => $note->member_id, 'data-menu' => '#menu_' . $note->id, 'data-loaded' => 0); $menus = array(array('icon_term' => 'site.show_detail', 'href' => 'note/' . $id)); echo btn_dropdown('noterm.dropdown', $menus, false, 'xs', null, true, $dropdown_btn_group_attr, $dropdown_btn_attr, false); ?> </div><!-- list_subtitle --> </div><!-- header --> <div class="body"> <?php echo convert_body($note->body, array('truncate_line' => conf('view_params_default.list.truncate_lines.body'), 'read_more_uri' => 'note/' . $id)); ?> </div> <?php if (Module::loaded('album') && ($images = \Note\Model_NoteAlbumImage::get_album_image4note_id($id, 4, array('id' => 'desc')))) { echo render('_parts/thumbnails', array('images' => array('list' => $images, 'additional_table' => 'note', 'size' => 'N_M', 'column_count' => 4), 'is_modal_link' => conf('site.common.thumbnailModalLink.isEnabled', 'page'))); } ?> <?php if ($note->is_published) { // note_comment list($comments, $comment_next_id, $all_comment_count) = \Note\Model_NoteComment::get_list(array('note_id' => $id), conf('view_params_default.list.comment.limit'), true, false, 0, 0, null, false, true); ?> <div class="comment_info"> <?php // comment_count_and_link $link_comment_attr = array('id' => 'link_show_comment_form_' . $id, 'class' => 'js-display_parts link_show_comment_' . $id, 'data-target_id' => 'commentPostBox_' . $id, 'data-hide_selector' => '.link_show_comment_' . $id, 'data-focus_selector' => '#textarea_comment_' . $id); echo render('_parts/comment/count_and_link_display', array('id' => $id, 'count' => $all_comment_count, 'link_attr' => $link_comment_attr));