/**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     foreach ($this->_playlist->pins as $pin) {
         $pin->delete();
     }
     $this->_playlist->delete();
     return CommandResponse::succeed();
 }
 /**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     $songIndex = $this->_playlist->tracks()->count() + 1;
     $this->_playlist->tracks()->attach($this->_track, ['position' => $songIndex]);
     Playlist::whereId($this->_playlist->id)->update(['track_count' => DB::raw('(SELECT COUNT(id) FROM playlist_track WHERE playlist_id = ' . $this->_playlist->id . ')')]);
     return CommandResponse::succeed(['message' => 'Track added!']);
 }
 /**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     $rules = ['title' => 'required|min:3|max:50', 'is_public' => 'required', 'is_pinned' => 'required'];
     $validator = Validator::make($this->_input, $rules);
     if ($validator->fails()) {
         return CommandResponse::fail($validator);
     }
     $playlist = new Playlist();
     $playlist->user_id = Auth::user()->id;
     $playlist->title = $this->_input['title'];
     $playlist->description = $this->_input['description'];
     $playlist->is_public = $this->_input['is_public'] == 'true';
     $playlist->save();
     if ($this->_input['is_pinned'] == 'true') {
         $playlist->pin(Auth::user()->id);
     }
     return CommandResponse::succeed(['id' => $playlist->id, 'title' => $playlist->title, 'slug' => $playlist->slug, 'created_at' => $playlist->created_at, 'description' => $playlist->description, 'url' => $playlist->url, 'is_pinned' => $this->_input['is_pinned'] == 'true', 'is_public' => $this->_input['is_public'] == 'true']);
 }
 public function getPlaylists()
 {
     $query = Favourite::whereUserId(Auth::user()->id)->whereNotNull('playlist_id')->with(['playlist' => function ($query) {
         $query->userDetails();
     }, 'playlist.user', 'playlist.user.avatar', 'playlist.tracks', 'playlist.tracks.cover']);
     $playlists = [];
     foreach ($query->get() as $fav) {
         if ($fav->playlist == null) {
             continue;
         }
         $playlists[] = Playlist::mapPublicPlaylistSummary($fav->playlist);
     }
     return Response::json(["playlists" => $playlists], 200);
 }
 public function getDownload($id, $extension)
 {
     $playlist = Playlist::with('tracks', 'user', 'tracks.album')->find($id);
     if (!$playlist || !$playlist->is_public && !Auth::check() || !$playlist->is_public && $playlist->user_id !== Auth::user()->id) {
         App::abort(404);
     }
     $format = null;
     $formatName = null;
     foreach (Track::$Formats as $name => $item) {
         if ($item['extension'] == $extension) {
             $format = $item;
             $formatName = $name;
             break;
         }
     }
     if ($format == null) {
         App::abort(404);
     }
     ResourceLogItem::logItem('playlist', $id, ResourceLogItem::DOWNLOAD, $format['index']);
     $downloader = new PlaylistDownloader($playlist, $formatName);
     $downloader->download();
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get list of affected users
     $usernames = DB::table('users')->select(['username', DB::raw('COUNT(*) as count')])->whereNull('disabled_at')->whereNotNull('username')->groupBy(DB::raw('LOWER(username)'))->having('count', '>=', 2)->lists('username');
     foreach ($usernames as $username) {
         // Find the relevant accounts
         // ==========================
         /** @var Collection $accounts */
         $accounts = User::where('username', $username)->orderBy('created_at', 'ASC')->get();
         $firstAccount = $accounts[0];
         $accounts->forget(0);
         $accountIds = $accounts->pluck('id');
         // Reassign content
         // ================
         // This is done with the less-efficient-than-raw-SQL Eloquent
         // methods to generate appropriate revision logs.
         $this->info('Merging duplicates for: ' . $firstAccount->username);
         DB::transaction(function () use($accounts, $accountIds, $firstAccount) {
             foreach (Album::whereIn('user_id', $accountIds)->get() as $album) {
                 $album->user_id = $firstAccount->id;
                 $album->save();
             }
             foreach (Comment::whereIn('user_id', $accountIds)->get() as $comment) {
                 $comment->user_id = $firstAccount->id;
                 $comment->save();
             }
             foreach (Favourite::whereIn('user_id', $accountIds)->get() as $favourite) {
                 $favourite->user_id = $firstAccount->id;
                 $favourite->save();
             }
             foreach (Follower::whereIn('artist_id', $accountIds)->get() as $follow) {
                 $follow->artist_id = $firstAccount->id;
                 $follow->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             DB::table('oauth2_tokens')->whereIn('user_id', $accountIds)->update(['user_id' => $firstAccount->id]);
             foreach (PinnedPlaylist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (Playlist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (ResourceLogItem::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (ResourceUser::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (Track::whereIn('user_id', $accountIds)->get() as $track) {
                 $track->user_id = $firstAccount->id;
                 $track->save();
             }
             foreach ($accounts as $account) {
                 $account->disabled_at = Carbon::now();
                 $account->save();
             }
         });
     }
 }
 /**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     $rules = ['content' => 'required', 'track_id' => 'exists:tracks,id', 'albums_id' => 'exists:albums,id', 'playlist_id' => 'exists:playlists,id', 'profile_id' => 'exists:users,id'];
     $validator = Validator::make($this->_input, $rules);
     if ($validator->fails()) {
         return CommandResponse::fail($validator);
     }
     $comment = new Comment();
     $comment->user_id = Auth::user()->id;
     $comment->content = $this->_input['content'];
     if ($this->_type == 'track') {
         $column = 'track_id';
     } else {
         if ($this->_type == 'user') {
             $column = 'profile_id';
         } else {
             if ($this->_type == 'album') {
                 $column = 'album_id';
             } else {
                 if ($this->_type == 'playlist') {
                     $column = 'playlist_id';
                 } else {
                     App::abort(500);
                 }
             }
         }
     }
     $comment->{$column} = $this->_id;
     $comment->save();
     // Recount the track's comments, if this is a track comment
     if ($this->_type === 'track') {
         $entity = Track::find($this->_id);
     } elseif ($this->_type === 'album') {
         $entity = Album::find($this->_id);
     } elseif ($this->_type === 'playlist') {
         $entity = Playlist::find($this->_id);
     } elseif ($this->_type === 'user') {
         $entity = User::find($this->_id);
     } else {
         App::abort(400, 'This comment is being added to an invalid entity!');
     }
     $entity->comment_count = Comment::where($column, $this->_id)->count();
     $entity->save();
     return CommandResponse::succeed(Comment::mapPublic($comment));
 }
 function __construct($playlistId, $input)
 {
     $this->_input = $input;
     $this->_playlistId = $playlistId;
     $this->_playlist = Playlist::find($playlistId);
 }
Exemple #9
0
 public static function mapPublicPlaylistSummary(Playlist $playlist)
 {
     $userData = ['stats' => ['views' => 0, 'downloads' => 0], 'is_favourited' => false];
     if (Auth::check() && $playlist->users->count()) {
         $userRow = $playlist->users[0];
         $userData = ['stats' => ['views' => (int) $userRow->view_count, 'downloads' => (int) $userRow->download_count], 'is_favourited' => (bool) $userRow->is_favourited];
     }
     return ['id' => (int) $playlist->id, 'track_count' => $playlist->track_count, 'title' => $playlist->title, 'slug' => $playlist->slug, 'created_at' => $playlist->created_at->format('c'), 'is_public' => (bool) $playlist->is_public, 'stats' => ['views' => (int) $playlist->view_count, 'downloads' => (int) $playlist->download_count, 'comments' => (int) $playlist->comment_count, 'favourites' => (int) $playlist->favourite_count], 'covers' => ['small' => $playlist->getCoverUrl(Image::SMALL), 'normal' => $playlist->getCoverUrl(Image::NORMAL), 'original' => $playlist->getCoverUrl(Image::ORIGINAL)], 'url' => $playlist->url, 'user' => ['id' => (int) $playlist->user->id, 'name' => $playlist->user->display_name, 'url' => $playlist->user->url], 'user_data' => $userData, 'permissions' => ['delete' => Auth::check() && Auth::user()->id == $playlist->user_id, 'edit' => Auth::check() && Auth::user()->id == $playlist->user_id]];
 }
 public function getOwned()
 {
     $query = Playlist::summary()->with('pins', 'tracks', 'tracks.cover')->where('user_id', \Auth::user()->id)->orderBy('title', 'asc')->get();
     $playlists = [];
     foreach ($query as $playlist) {
         $playlists[] = ['id' => $playlist->id, 'title' => $playlist->title, 'slug' => $playlist->slug, 'created_at' => $playlist->created_at, 'description' => $playlist->description, 'url' => $playlist->url, 'covers' => ['small' => $playlist->getCoverUrl(Image::SMALL), 'normal' => $playlist->getCoverUrl(Image::NORMAL)], 'is_pinned' => $playlist->hasPinFor(Auth::user()->id), 'is_public' => $playlist->is_public == 1];
     }
     return Response::json($playlists, 200);
 }