Пример #1
0
 private function explore()
 {
     // Get some tags to show as options
     $tags = Tag::select('name')->limit(30)->findArray();
     View::set('tags', $tags);
     // No tags selected
     if (empty($_GET['t']) || !Validate::tags($_GET['t'])) {
         $rows = Playlist::join('user', 'user_id = u.id', 'u')->selectMany('playlist.*', 'username')->where('published', 1)->paginate();
         Base::eagerLoadingPlaylistTags($rows);
         View::set('playlists', $rows);
         View::show('explore');
     }
     // Separate tags by spaces
     $tags = trim($_GET['t']);
     $tags = explode('/', $tags, 4);
     $tags = array_slice($tags, 0, 3);
     // Url for selected tags
     $selectedTagsUrl = implode('/', $tags);
     // Beautifys the title Tags
     $selectedTags = array();
     foreach ($tags as $key => $item) {
         // Removes empty tags
         if (empty($item)) {
             unset($tags[$key]);
             continue;
         }
         $aux = array();
         $aux['name'] = $item;
         // When one clicked will remove that tag from the query
         unset($tags[$key]);
         $aux['href'] = '/' . implode('/', $tags);
         $tags[$key] = $item;
         $selectedTags[] = $aux;
     }
     $playlists = Playlist::filter('byTags', $tags)->join('user', 'p.user_id = u.id', 'u')->selectMany('p.*', 'username');
     $count = $playlists->countDistinct('p.id');
     $playlists = $playlists->groupBy('p.id')->paginate($count);
     Base::eagerLoadingPlaylistTags($playlists);
     // View preparations
     View::set('playlists', $playlists);
     View::set('selectedTags', $selectedTags);
     View::set('selectedTagsUrl', $selectedTagsUrl);
     View::show('explore');
 }
Пример #2
0
 private function home()
 {
     $this->welcome();
     // Staff picks
     $staffPicks = Playlist::filter('byTags', 'staff')->select('p.*');
     $count = $staffPicks->countDistinct('p.id');
     $staffPicks = $staffPicks->groupBy('p.id')->orderByDesc('p.id')->paginate($count);
     Base::eagerLoadingPlaylistTags($staffPicks);
     View::set('staff_picks', $staffPicks);
     // Home tags
     $tags = Base::$g['home_tags'];
     if (!empty($tags)) {
         $tags = explode(', ', $tags);
         foreach ($tags as $key => $tag) {
             $playlists = Playlist::filter('byTags', $tag)->select('p.*');
             $count = $playlists->countDistinct('p.id');
             if (!$count) {
                 unset($tags[$key]);
                 continue;
             }
             $playlists = $playlists->groupBy('p.id')->orderByDesc('p.id')->paginate($count);
             Base::eagerLoadingPlaylistTags($playlists);
             $tags[$key] = $playlists;
             $tags[$key]['title'] = $tag;
         }
         View::set('home_tags_playlists', $tags);
     }
     // New playlists
     $newPlaylists = Playlist::orderByDesc('id')->where('published', 1)->paginate();
     Base::eagerLoadingPlaylistTags($newPlaylists);
     View::set('new_playlists', $newPlaylists);
     if (LOGGED) {
         $user = Base::$g['logged'];
         // Liked playlists
         $likedPlaylists = $user->likedPlaylists();
         Base::eagerLoadingPlaylistTags($likedPlaylists);
         View::set('liked_playlists', $likedPlaylists);
         // Stream
         $feedPlaylists = $user->feedPlaylists();
         Base::eagerLoadingPlaylistTags($feedPlaylists);
         View::set('feed_playlists', $feedPlaylists);
     }
     View::show('home');
 }
Пример #3
0
 private function playlist()
 {
     // Playlist Author
     $author = $this->playlist->user();
     $author->playlists = $author->playlists();
     View::set('author', $author->asArray());
     // Tags
     $tags = $this->playlist->tags();
     View::set('tags', $tags);
     // Similar playlists
     if ($tags) {
         $similarPlaylists = Playlist::filter('byTags', $tags)->select('p.*')->whereNotEqual('p.id', $this->playlist->id);
         $count = $similarPlaylists->countDistinct('p.id');
         $similarPlaylists = $similarPlaylists->groupBy('p.id')->paginate($count);
         // View all link
         if ($similarPlaylists) {
             $similarPlaylists['href'] = implode('/', $tags);
         }
         View::set('similar_playlists', $similarPlaylists);
     }
     // Liked
     if (LOGGED) {
         $likeActive = PlaylistLike::filter('isActive', $this->playlist->id, LOGGED);
         View::set('like_active', $likeActive);
         $followDisplay = $this->playlist->user_id !== LOGGED;
         View::set('follow_display', $followDisplay);
         if ($followDisplay) {
             $followActive = UserRelation::filter('isActive', $this->playlist->user_id, LOGGED);
             View::set('follow_active', $followActive);
         }
         $reportActive = Report::filter('isActive', $this->playlist->id, 'playlist', LOGGED);
         View::set('report_active', $reportActive);
     }
     $edit = ADMIN || LOGGED === $this->playlist->user_id;
     View::set('edit', $edit);
     // View
     View::set('playlist', $this->playlist->asArray());
     View::set('tracks', $this->playlist->tracks());
     View::set('comments', $this->playlist->comments());
     View::show('playlist/playlist');
 }
Пример #4
0
 private function playlists()
 {
     $playlists = Playlist::filter('bySearchQuery', $this->query)->selectMany('p.*', 'username')->paginate(-1, 6);
     Base::eagerLoadingPlaylistTags($playlists);
     View::set('playlists', $playlists);
 }