Ejemplo n.º 1
0
 private function edit_note($id, $post)
 {
     $note = new Model_Note($id);
     if ($note->loaded() && Auth::instance()->logged_in()) {
         $note->text = $post['note'];
         $note->save();
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 public static function get_list($limit, $page = 1, $self_member_id = 0, $target_member_obj = null, $is_mypage = false, $is_draft = 0)
 {
     if ($target_member_obj && !$target_member_obj instanceof \Model_Member) {
         throw new InvalidArgumentException('forth parameter is invalid.');
     }
     $is_published = \Util_toolkit::reverse_bool($is_draft, true);
     $data = Model_Note::get_pager_list(array('related' => 'member', 'where' => \Site_Model::get_where_params4list($target_member_obj ? $target_member_obj->id : 0, $self_member_id ?: 0, $is_mypage, array(array('is_published', $is_published))), 'limit' => $limit, 'order_by' => array('created_at' => 'desc')), $page);
     $data['is_draft'] = $is_draft;
     $data['member'] = $target_member_obj;
     $data['is_mypage'] = $is_mypage;
     $data['liked_note_ids'] = conf('like.isEnabled') && $self_member_id ? \Site_Model::get_liked_ids('note', $self_member_id, $data['list']) : array();
     return $data;
 }
Ejemplo n.º 3
0
 public function action_create($note_id = null)
 {
     if (!$note_id || !($note = Model_Note::find($note_id))) {
         throw new \HttpNotFoundException();
     }
     $this->check_browse_authority($note->public_flag, $note->member_id);
     // Lazy validation
     if (\Input::post('body')) {
         \Util_security::check_csrf();
         // Create a new comment
         $comment = new Model_NoteComment(array('body' => \Input::post('body'), 'note_id' => $note_id, 'member_id' => $this->u->id));
         // Save the post and the comment will save too
         if ($comment->save()) {
             \Session::set_flash('message', 'コメントしました。');
         } else {
             \Session::set_flash('error', 'コメントに失敗しました。');
         }
         \Response::redirect('note/detail/' . $note_id);
     } else {
         Controller_Note::action_detail($note_id);
     }
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider update_like_provider
  */
 public function test_update_like($member_id)
 {
     $note_id = self::$note_id;
     $note_comment_id = self::$note_comment_id;
     // note_like save
     \Util_Develop::sleep();
     $is_liked = self::execute_like($note_comment_id, $member_id);
     $note = Model_Note::find($note_id);
     $note_comment = Model_NoteComment::find($note_comment_id);
     $note_comment_like = \Util_Orm::get_last_row('\\Note\\Model_NoteCommentLike', array('note_comment_id' => $note_comment_id));
     // 件数
     $like_count = \Util_Orm::get_count_all('\\Note\\Model_NoteCommentLike', array('note_comment_id' => $note_comment_id));
     $like_count_expect = $is_liked ? self::$like_count + 1 : self::$like_count - 1;
     $this->assertEquals($like_count_expect, $like_count);
     // 値
     $this->assertEquals($like_count, $note_comment->like_count);
     if (!$is_liked) {
         $this->assertNull($note_comment_like);
     }
     // timeline view cache check
     if (self::$is_check_view_cache) {
         $this->assertEquals(self::$view_cache_before, \Note\Site_Util::get_view_cache(self::$timeline_id));
     }
 }
Ejemplo n.º 5
0
 /**
  * Note publish
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_publish($id = null)
 {
     \Util_security::check_method('POST');
     \Util_security::check_csrf();
     $note = Model_Note::check_authority($id, $this->u->id);
     if ($note->is_published) {
         \Session::set_flash('error', '既に公開されています。');
         \Response::redirect('note/detail/' . $id);
     }
     try {
         \DB::start_transaction();
         list($is_changed, $is_published) = $note->save_with_relations($this->u->id, array('is_published' => 1));
         \DB::commit_transaction();
         \Session::set_flash('message', term('note') . 'を公開しました。');
     } catch (\FuelException $e) {
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         \Session::set_flash('error', $e->getMessage());
     }
     \Response::redirect('note/detail/' . $id);
 }
Ejemplo n.º 6
0
 public function test_delete_notice()
 {
     // 事前準備
     \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name(self::$type_key), 1);
     \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1);
     \Model_MemberConfig::set_value(3, \Notice\Form_MemberConfig::get_name(self::$type_key), 1);
     \Model_MemberConfig::set_value(3, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1);
     self::$member_id = 1;
     self::set_note();
     $note_id = self::$note_id;
     $foreign_id = self::$note_id;
     $notice_count_all_before = \Notice\Model_Notice::get_count();
     $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count();
     $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count();
     $member_watch_content_count_all_before = \Notice\Model_MemberWatchContent::get_count();
     // 他人がイイね
     $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2));
     $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key));
     $this->assertNotNull($notice);
     // 件数確認
     $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count());
     $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count());
     $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count());
     $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count());
     // 関連テーブルのレコードが作成されていることを確認
     $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id));
     $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2));
     $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2));
     $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)));
     // イイねを取り消し
     $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2));
     // 件数確認
     $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count());
     $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count());
     $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count());
     $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count());
     // watch は解除されない
     // 関連テーブルのレコードが削除されていることを確認
     $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id));
     $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2));
     $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2));
     // watch は解除されない
     $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)));
     // 他人のイイね+自分がコメント
     $note_like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2));
     self::save_comment(1, 'Test comment1.');
     $notice_like = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key));
     $notice_comment = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type('comment'));
     $this->assertNotNull($notice_like);
     $this->assertNotNull($notice_comment);
     // 件数確認
     $this->assertEquals($notice_count_all_before + 2, \Notice\Model_Notice::get_count());
     $this->assertEquals($notice_status_count_all_before + 2, \Notice\Model_NoticeStatus::get_count());
     $this->assertEquals($notice_member_from_count_all_before + 2, \Notice\Model_NoticeMemberFrom::get_count());
     $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count());
     // 関連テーブルのレコードが作成されていることを確認
     $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id));
     $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id));
     $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2));
     $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id));
     $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2));
     $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, self::$member_id));
     $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)));
     // イイねを取り消し
     $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2));
     // 件数確認
     $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count());
     $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count());
     $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count());
     $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count());
     // watch は解除されない
     // 関連テーブルのレコードが削除されていることを確認
     $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id));
     $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id));
     $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2));
     $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id));
     $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2));
     $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, self::$member_id));
     $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)));
     // 他人がイイね
     $note_like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 3));
     $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key));
     $this->assertNotNull($notice);
     // note 削除
     $note = Model_Note::find($note_id);
     $note->delete_with_relations();
     // 件数確認
     $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count());
     $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count());
     $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count());
     $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count());
     // 関連テーブルのレコードが削除されていることを確認
     $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id));
     $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3));
     $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 3));
     $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)));
 }
Ejemplo n.º 7
0
 /**
  * Notes action
  *
  * @return void
  */
 public function notesAction()
 {
     $notes = new Model_Note();
     $myNotes = Digitalus_Filter_Post::get('content');
     $notes->saveUsersNotes($myNotes);
     $this->_redirect('admin/index');
 }
Ejemplo n.º 8
0
 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);
         }
     }
 }