Example #1
0
 public static function setUpBeforeClass()
 {
     $query = Model_TimelineCache::query();
     self::$total_count = $query->count();
     $total_list = $query->get();
     $total_first_obj = \Util_Array::get_first($total_list);
     self::$total_first_id = $total_first_obj->id;
     $total_last_obj = \Util_Array::get_last($total_list);
     self::$total_last_id = $total_last_obj->id;
 }
Example #2
0
 public function test_timeline_exists()
 {
     if (!($list = Model_TimelineCache::find('all'))) {
         \Util_Develop::output_test_info(__FILE__, __LINE__);
         $this->markTestSkipped('No record for test.');
     }
     foreach ($list as $obj) {
         // test for cache exists.
         $timelines = Model_Timeline::check_authority($obj->timeline_id);
         $this->assertNotEmpty($timelines);
     }
 }
Example #3
0
 public static function get_list($self_member_id = 0, $target_member_id = 0, $is_mytimeline = false, $viewType = null, $max_id = 0, $limit = 0, $is_latest = true, $is_desc = true, $since_id = 0)
 {
     $follow_member_ids = null;
     $friend_member_ids = null;
     if (!$self_member_id || $target_member_id) {
         $is_mytimeline = false;
     }
     if ($is_mytimeline) {
         list($follow_member_ids, $friend_member_ids) = Site_Util::get_member_relation_member_ids($self_member_id, $viewType);
     }
     if (!$limit) {
         $limit = (int) \Config::get('timeline.articles.limit');
     }
     if ($limit > \Config::get('timeline.articles.limit_max')) {
         $limit = \Config::get('timeline.articles.limit_max');
     }
     $sort = array('id' => $is_desc ? 'desc' : 'asc');
     $query = Model_TimelineCache::query()->select('id', 'member_id', 'timeline_id', 'type', 'comment_count', 'like_count');
     if ($max_id || $since_id) {
         $query->and_where_open();
     }
     if ($is_mytimeline) {
         if ($follow_timeline_ids = Model_MemberFollowTimeline::get_cols('timeline_id', array('member_id' => $self_member_id))) {
             $query->or_where_open();
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('timeline_id', 'in', $follow_timeline_ids);
             $query->where('is_follow', 1);
             $query->or_where_close();
             $query->or_where_open();
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('timeline_id', 'not in', $follow_timeline_ids);
             $query->where('is_follow', 0);
             $query->or_where_close();
         } else {
             $query->and_where_open();
             self::set_mytimeline_cond($query, $self_member_id, $follow_member_ids);
             $query->and_where_close();
             $query->where('is_follow', 0);
         }
     } else {
         $is_mypage = $self_member_id && $target_member_id && $target_member_id == $self_member_id;
         $basic_cond = \Site_Model::get_where_params4list($target_member_id, $self_member_id, $is_mypage);
         $query->where($basic_cond);
         $query->where('is_follow', 0);
     }
     if ($max_id || $since_id) {
         $query->and_where_close();
     }
     $is_reverse = false;
     if ($limit && $is_latest && !$is_desc) {
         $is_desc = true;
         $is_reverse = true;
     }
     if ($since_id) {
         $query->where('id', '>', $since_id);
     }
     if ($max_id) {
         $query->where('id', '<=', $max_id);
     }
     $query->order_by($sort);
     if ($limit) {
         $rows_limit = $limit + 1;
         $query->rows_limit($rows_limit);
     }
     $list = $query->get();
     $next_id = 0;
     if ($limit && count($list) > $limit) {
         $next_obj = array_pop($list);
         $next_id = $next_obj->id;
     }
     return array($list, $next_id);
 }
Example #4
0
 public function test_timeline_cache()
 {
     if (!($list = Model_Timeline::find('all'))) {
         $this->markTestSkipped('No record for test.');
     }
     \Util_Develop::output_test_info(__FILE__, __LINE__);
     foreach ($list as $obj) {
         // test for cache exists.
         $caches = Model_TimelineCache::get4timeline_id($obj->id);
         $this->assertNotEmpty($caches);
         // test for cache count.
         $this->assertCount(2, $caches);
         foreach ($caches as $cache) {
             // test for same values.
             $this->assertEquals($obj->member_id, $cache->member_id);
             $this->assertEquals($obj->member_id_to, $cache->member_id_to);
             $this->assertEquals($obj->group_id, $cache->group_id);
             $this->assertEquals($obj->page_id, $cache->page_id);
             $this->assertEquals($obj->public_flag, $cache->public_flag);
             $this->assertEquals($obj->type, $cache->type);
             $this->assertEquals($obj->comment_count, $cache->comment_count);
             // test for is_follow.
             $this->assertContains($cache->is_follow, array(0, 1));
         }
     }
 }