Beispiel #1
0
 public function create(Request $request)
 {
     $playlist = new Playlist();
     $playlist->user_id = Auth::id();
     $playlist->episode_id = $request->input('episode');
     $playlist->save();
     return redirect()->back();
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $u = User::create(['first_name' => 'test', 'last_name' => 'test', 'email' => '*****@*****.**', 'level' => 1]);
     $u2 = User::create(['first_name' => 'test2', 'last_name' => 'test2', 'email' => '*****@*****.**', 'level' => 1]);
     $u3 = User::create(['first_name' => 'test3', 'last_name' => 'test3', 'email' => '*****@*****.**', 'level' => 2]);
     $e1 = Event::create(['name' => 'test event', 'user_id' => 3, 'slug' => 'test-event-1', 'date' => '2016-10-17', 'start' => '18:00:00', 'end' => '5:00:00']);
     $e2 = Event::create(['name' => 'test event', 'user_id' => 1, 'slug' => 'test-event-2', 'date' => '2016-08-22', 'start' => '19:00:00', 'end' => '5:00:00']);
     Event::create(['name' => 'test event', 'user_id' => 2, 'slug' => 'test-event-3', 'date' => '2017-01-07', 'start' => '18:00:00', 'end' => '5:00:00']);
     $p1 = Playlist::create(['name' => 'Playlist principale !']);
     $p2 = Playlist::create(['name' => 'The Playlist !']);
     $p3 = Playlist::create(['name' => 'Playlist secondaire']);
     Playlist::create(['name' => 'The Playlist !']);
     $p1->styles()->sync([1, 2, 3]);
     $p2->styles()->sync([1, 4]);
     $p3->styles()->sync([1, 3, 5, 7]);
     $e1->playlists()->sync([1, 3]);
     $e2->playlists()->sync([2]);
     Comment::create(['event_id' => 2, 'user_id' => 2, 'content' => 'Sooo goooood']);
     Comment::create(['event_id' => 3, 'user_id' => 2, 'content' => 'Sooo goooood :D']);
     Comment::create(['event_id' => 2, 'user_id' => 3, 'content' => 'Sooo goooood !!!']);
     Video::create(['url' => '7l48bfQuJeE', 'artist' => 'Chill Bump', 'name' => 'Lost In The Sound', 'tags' => 'chill bump lost in the sound']);
     Video::create(['url' => 'XxdPJvhQaMU', 'artist' => 'Chill Bump', 'name' => 'Water boycotter', 'tags' => 'chill bump water boycotter']);
     Video::create(['url' => 'kWXAYDQ_K7k', 'artist' => 'Chill Bump', 'name' => 'The Memo', 'tags' => 'chill bump the memo']);
     $pivot1 = $p1->videos()->sync([1, 3]);
     $pivot2 = $p2->videos()->sync([2]);
     $pivot3 = $p3->videos()->sync([1, 2, 3]);
     News::create(['title' => 'news test', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 2, 'slug' => 'text-news-1']);
     News::create(['title' => 'news test 2', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 3, 'slug' => 'text-news-2']);
     Article::create(['title' => 'Article test 1', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 2, 'slug' => 'text-article-1']);
     Article::create(['title' => 'Article test 2', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 3, 'slug' => 'text-article-2', 'event_id' => 2]);
 }
Beispiel #3
0
 /**
  * Delete playlists
  */
 public static function deletePlaylist($playlist_names, $service_id)
 {
     $playlists = Playlist::whereNotIn('name', $playlist_names)->where('service_id', $service_id)->get();
     foreach ($playlists as $playlist) {
         $playlist->delete();
     }
 }
 public function run()
 {
     DB::table('playlists')->delete();
     \App\Playlist::create(['id' => 1, 'name' => 'test']);
     \App\Playlist::create(['id' => 2, 'name' => 'test2']);
     \App\Playlist::create(['id' => 3, 'name' => 'test3']);
 }
 public function run()
 {
     DB::table('playlist_user')->delete();
     $user = \App\User::find(1);
     $user->playlists()->attach(\App\Playlist::find(1));
     $user->playlists()->attach(\App\Playlist::find(2));
     $user->playlists()->attach(\App\Playlist::find(3));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = Session::get('user');
     $allowed_departments = Session::get('allowed_departments');
     $match_departments = Session::get('match_departments');
     $playlists = Playlist::whereIn('department_id', $match_departments)->get();
     // Return all locations or only the ones th user is assigned to
     if ($user->is_super_user) {
         $locations = Location::all();
     } else {
         $locations = Location::whereIn('department_id', $match_departments)->get();
     }
     $data = array('locations' => $locations, 'allowed_departments' => $allowed_departments, 'user' => $user, 'playlists' => $playlists);
     return view('pages/locations', $data);
 }
 public function getNonEager()
 {
     // load all playlists
     $playlists = \App\Playlist::all();
     // array to hold the data
     $allCards = [];
     // loop through and grab each card from all playlists
     foreach ($playlists as $playlist) {
         $allCards[] = [];
         foreach ($playlist->cards as $card) {
             // load into $allCards
             $allCards[][] = $card;
         }
     }
     dd($allCards);
     // return all cards in all playlists
     return json_encode($allCards);
 }
 public function run()
 {
     DB::table('card_playlist')->delete();
     $playlist = \App\Playlist::find(1);
     $playlist->cards()->attach(\App\Card::find(1));
     $playlist->cards()->attach(\App\Card::find(2));
     $playlist->cards()->attach(\App\Card::find(3));
     $playlist->cards()->attach(\App\Card::find(4));
     $playlist->cards()->attach(\App\Card::find(5));
     $playlist = \App\Playlist::find(2);
     $playlist->cards()->attach(\App\Card::find(2));
     $playlist->cards()->attach(\App\Card::find(3));
     $playlist->cards()->attach(\App\Card::find(5));
     $playlist = \App\Playlist::find(3);
     $playlist->cards()->attach(\App\Card::find(1));
     $playlist->cards()->attach(\App\Card::find(2));
     $playlist->cards()->attach(\App\Card::find(4));
 }
 /**
  * Filter screens by criteria
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function filter(Request $request)
 {
     $match_departments = Session::get('match_departments');
     $allowed_departments = Session::get('allowed_departments');
     $user = Session::get('user');
     // Get inputs from POST
     $btnFindScreen = $request->input('btnFindScreen');
     $btnFindAll = $request->input('btnFindAll');
     $locationID = $request->input('drpLocations');
     //$playlistID = $request->input('drpPlaylists');
     $screenID = $request->input('txtScreenID');
     // Check which action to perform
     if (isset($btnFindScreen)) {
         // Filter by id
         $screens = $this->getAllowedScreens($user, $allowed_departments);
         $filtered = $screens->filter(function ($item) use($screenID) {
             if ($item->id == $screenID) {
                 return true;
             }
         });
         // Filter by location
         if ($filtered->count() == 0) {
             $filtered = $screens->filter(function ($item) use($locationID) {
                 if ($item->location_id == $locationID) {
                     return true;
                 }
             });
         }
         $screens = $filtered;
     } else {
         if (isset($btnFindAll)) {
             $screenID = null;
             $screens = $this->getAllowedScreens($user, $allowed_departments);
         } else {
             abort(401);
         }
     }
     $playlists = Playlist::whereIn('department_id', $match_departments)->get();
     // Pass back so we can re-populate the locations list
     //$locations = Location::whereIn('department_id', $match_departments)->get();
     $data = array('screens' => $screens, 'screenID' => $screenID, 'playlists' => $playlists, 'user' => $user);
     return view('pages/screens', $data);
 }
 public function editPlaylist($id, Request $request)
 {
     $playlist = Playlist::find($id);
     $pName = $playlist->playlist_name;
     $userID = Auth::user()['id'];
     $playlistTrackIDs = DB::select('SELECT track_id FROM playlist_songs where playlist_id = ?', [$id]);
     $userTracks = DB::select('SELECT * FROM music where band_id = ?', [$userID]);
     $tracksData = array();
     foreach ($userTracks as $track) {
         $inArray = false;
         foreach ($playlistTrackIDs as $trackID) {
             if ($track->id == $trackID->track_id) {
                 $inArray = true;
             }
         }
         if ($inArray) {
             $tracksData[$track->id . "_on"] = $track;
         } else {
             $tracksData[$track->id . "_off"] = $track;
         }
     }
     $tracksData = $tracksData;
     return view('editplaylist', ['playlistName' => $pName, 'playlistID' => $id, 'data' => $tracksData, 'page_name' => 'editplaylist']);
 }
 /**
  * Gets the global playlist and loads all realtions
  * @return EloquentCollection
  */
 public function getGlobal()
 {
     return Playlist::where('isGlobal', true)->with('adverts')->with('adverts.background')->with(array('adverts.pages' => function ($query) {
         $query->where('deleted', 0);
         $query->with('pageData');
         $query->with('template');
     }))->first();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\AddPlaylistRequest $request)
 {
     //dd(\Auth::user()->id);
     $playlist = new Playlist(array('name' => $request->get('name'), 'creator_id' => \Auth::user()->id));
     $playlist->save();
     flash()->overlay('Playlist added!', 'Success!');
     $playlists = DB::table('playlists')->where('creator_id', \Auth::user()->id)->get();
     return redirect('/playlist/view')->with(['playlists' => $playlists]);
     // return view('playlist.index',
     //             ['playlists' => $playlists]);
 }
Beispiel #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // TODO check ownership
     $playlist = Playlist::with('items')->find($id);
     if (!$playlist or !empty($result->items)) {
         return response()->json(['success' => false, 'error' => 'Playlist invalid or not empty']);
     }
     $result = $playlist->delete();
     return response()->json(['success' => $result]);
 }
 /**
  * Gets an array of all the allowed playlists the specified user is able
  * to access and modify because they're admin
  * @param User $user
  * @param array $allowed_departments
  * @return EloquentCollection
  */
 public function getAllowedPlaylists($user, $allowed_departments)
 {
     // Check if super or admin
     if ($user->is_super_user) {
         return Playlist::all();
         // Return all adverts
     } else {
         $playlists = collect([]);
         // Get every user assigned to every department
         // this admin is responsible for
         foreach ($allowed_departments as $department) {
             $departmentPlaylists = $department->Playlists()->get();
             if ($departmentPlaylists->count() > 0) {
                 $playlists = $playlists->merge($departmentPlaylists);
             }
         }
     }
     // Only return unqiue users
     return $playlists->unique('id');
 }
Beispiel #15
0
 public function sync_user_playlists()
 {
     $api_playlists = $this->api->getMyPlaylists();
     $db_playlists = [];
     $user_id = $this->user('id');
     // This will only sync the 10 first playlists.
     // TODO: Handle API's pagination to sync everything
     foreach ($api_playlists->items as $api_playlist) {
         $db_playlist = \App\Playlist::where('id', $api_playlist->id)->where('user_id', $user_id)->first();
         if (!$db_playlist) {
             $db_playlist = new \App\Playlist();
         }
         $db_playlist->id = $api_playlist->id;
         $db_playlist->name = $api_playlist->name;
         $db_playlist->user_id = $user_id;
         $db_playlist->save();
         $db_playlists[] = $db_playlist;
     }
     return $db_playlists;
 }
Beispiel #16
0
 public function exportForm($playlist_id, $orderBy = 'videos.artist', $order = 'asc')
 {
     $playlist = Playlist::find($playlist_id);
     $videos = PlaylistVideo::where('playlist_id', $playlist->id)->with('likes', 'video')->where('validation', '1');
     if ($orderBy == 'score') {
         $order = $order == 'asc' ? 'desc' : 'asc';
     } else {
         $videos = $videos->select('playlist_video.*');
         $videos = $videos->join('videos', 'playlist_video.video_id', '=', 'videos.id');
     }
     $videos = $videos->orderBy($orderBy, $order)->paginate(25);
     return view('playlists.export', compact('playlist', 'videos'));
 }
 public function getList($id)
 {
     $playlist = \App\Playlist::find($id);
     $cards = $playlist->cards;
     return json_encode($cards);
 }
Beispiel #18
0
 /**
  * Save new tracks to db.
  */
 private function syncUpdate($request, $service, $all_music)
 {
     foreach ($all_music as $playlist_name => $tracks) {
         // Get playlist.
         $playlist = Playlist::getPlaylist($playlist_name, ucfirst($service->name));
         // If playlist not in DB - add.
         if (empty($playlist)) {
             $playlist = Auth::user()->playlists()->create(['name' => $playlist_name, 'service_id' => $service->id]);
         }
         // Get list of existing songs in db.
         $song_identifier_in_db = $this->extractPlaylistSongIds($playlist);
         foreach ($tracks as $track) {
             // If song already in db, skip and remove from array of existing ids.
             if (isset($song_identifier_in_db[$track->id])) {
                 unset($song_identifier_in_db[$track->id]);
                 continue;
             }
             // Create new song.
             $playlist->songs()->firstOrCreate(['title' => $track->title, 'song_identifier' => $track->id, 'image' => $track->artwork_url, 'url' => $track->permalink_url, 'song_created' => $track->created_at, 'service_id' => $service->id]);
         }
         // Check if any songs left in songs list from db. If so, remove thos songs from db.
         if (!empty($song_identifier_in_db)) {
             $song_identifier_in_db = collect($song_identifier_in_db);
             $ids = $song_identifier_in_db->keyBy('id')->keys();
             Song::destroy($ids);
         }
     }
     // Delete deleted playlists including songs.
     Playlist::deletePlaylist(array_keys($all_music), $service->id);
 }