public function index($request)
 {
     $data = [];
     $counts = [];
     $counts['videos'] = Video::count();
     $counts['users'] = User::count();
     $counts['channels'] = UserChannel::count();
     $counts['comments'] = Comment::count();
     $counts['total_views'] = Video::sumViews();
     $counts['channel_user_ratio'] = round($counts['channels'] / $counts['users'], 2);
     $counts['videos_that_has_comments'] = Statistic::countVideosHavingComments();
     $counts['channels_having_videos'] = Video::find_by_sql('SELECT count(DISTINCT poster_id) as count from `videos`')[0]->count;
     $counts['part_of_commented_videos'] = round($counts['videos_that_has_comments'] / $counts['videos'] * 100, 2);
     $counts['part_of_channels_having_videos'] = round($counts['channels_having_videos'] / $counts['channels'] * 100, 2);
     $counts['user_1_channel'] = Statistic::countUserHavingChannels('= 1');
     $counts['user_2_channel'] = Statistic::countUserHavingChannels('= 2');
     $counts['user_3_channel'] = Statistic::countUserHavingChannels('= 3');
     $counts['user_more3_channel'] = Statistic::countUserHavingChannels('> 3');
     $counts['user_1_channel_part'] = round($counts['user_1_channel'] / $counts['users'] * 100, 2);
     $counts['user_2_channel_part'] = round($counts['user_2_channel'] / $counts['users'] * 100, 2);
     $counts['user_3_channel_part'] = round($counts['user_3_channel'] / $counts['users'] * 100, 2);
     $counts['user_more3_channel_part'] = round($counts['user_more3_channel'] / $counts['users'] * 100, 2);
     $data['counts'] = $counts;
     return new ViewResponse('admin/statistic/index', $data);
 }
Example #2
0
 public function getSubscriptionsVideosFromChannel($channelId, $amount = 'nope')
 {
     $videos = [];
     if ($amount != 'nope') {
         $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE poster_id=? ORDER BY timestamp DESC LIMIT " . $amount, array($channelId));
     } else {
         $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE poster_id=? ORDER BY timestamp DESC", array($channelId));
     }
     return $vidsToAdd;
 }
Example #3
0
 public static function getSubscriptionsVideos($userId, $amount = 'nope')
 {
     $videos = [];
     $user = User::find_by_id($userId);
     $sub_array = $user->getSubscribedChannelsAsList();
     if (empty($sub_array)) {
         return [];
         //No sub
     }
     $sub_array = array_map(function ($v) {
         return "'{$v}'";
     }, $sub_array);
     $subs = '(' . implode(', ', $sub_array) . ')';
     if ($amount != 'nope') {
         $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE visibility=2 AND poster_id IN " . $subs . " ORDER BY timestamp DESC LIMIT " . $amount);
     } else {
         $vidsToAdd = Video::find_by_sql("SELECT * FROM videos WHERE visibility=2 AND poster_id IN " . $subs . " ORDER BY timestamp DESC");
     }
     return $vidsToAdd;
 }