Inheritance: extends Jenssegers\Mongodb\Model
Esempio n. 1
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => auth()->user()->is_admin ? Setting::pluck('value', 'key')->all() : [], 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'currentUser' => auth()->user(), 'useLastfm' => Lastfm::used(), 'useYouTube' => YouTube::enabled(), 'allowDownload' => config('koel.download.allow'), 'cdnUrl' => app()->staticUrl(), 'currentVersion' => Application::VERSION, 'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION]);
 }
Esempio n. 2
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => Setting::all()->lists('value', 'key'), 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'user' => auth()->user()]);
 }
Esempio n. 3
0
 /**
  * Get a set of application data.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index()
 {
     $playlists = Playlist::byCurrentUser()->orderBy('name')->with('songs')->get()->toArray();
     // We don't need full song data, just ID's
     foreach ($playlists as &$playlist) {
         $playlist['songs'] = array_pluck($playlist['songs'], 'id');
     }
     return response()->json(['artists' => Artist::orderBy('name')->with('albums', with('albums.songs'))->get(), 'settings' => Setting::lists('value', 'key')->all(), 'playlists' => $playlists, 'interactions' => Interaction::byCurrentUser()->get(), 'users' => auth()->user()->is_admin ? User::all() : [], 'currentUser' => auth()->user(), 'useLastfm' => env('LASTFM_API_KEY') && env('LASTFM_API_SECRET'), 'currentVersion' => Application::VERSION, 'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION]);
 }
Esempio n. 4
0
 /**
  * Unlike several songs at once as the currently authenticated user.
  *
  * @param BatchInteractionRequest $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function batchUnlike(BatchInteractionRequest $request)
 {
     return response()->json(Interaction::batchUnlike((array) $request->input('songs'), $request->user()));
 }
Esempio n. 5
0
File: Song.php Progetto: tamdao/koel
 /**
  * Get all songs favored by a user.
  *
  * @param User $user
  * @param bool $toArray
  *
  * @return \Illuminate\Database\Eloquent\Collection|array
  */
 public static function getFavorites(User $user, $toArray = false)
 {
     $songs = Interaction::where(['user_id' => $user->id, 'liked' => true])->with('song')->get()->pluck('song');
     return $toArray ? $songs->toArray() : $songs;
 }
Esempio n. 6
0
 public function store()
 {
     $csvPath = Input::file('file')->getRealPath();
     $collectionName = Input::file('file')->getClientOriginalName();
     $collectionName = substr($collectionName, 0, strlen($collectionName) - 4);
     $csv = new parseCSV();
     $csv->auto($csvPath);
     $data = $csv->data;
     // If collection exists, drop it
     if (Schema::hasCollection($collectionName)) {
         Schema::drop($collectionName);
     }
     switch ($collectionName) {
         case 'Species':
             Schema::create('Species', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newSpecies = new Species();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newSpecies[$key] = $row[$key];
                 }
                 $newSpecies->save();
             }
             break;
         case 'Interactions':
             Schema::create('Interactions', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newInteraction = new Interaction();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newInteraction[$key] = $row[$key];
                 }
                 $newInteraction->save();
             }
             break;
         case 'TaxaGroups':
             Schema::create('TaxaGroups', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newTaxaGroup = new TaxaGroup();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newTaxaGroup[$key] = $row[$key];
                 }
                 $newTaxaGroup->save();
             }
             break;
         case 'LitSources':
             Schema::create('LitSources', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newLitSource = new LitSource();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newLitSource[$key] = $row[$key];
                 }
                 $newLitSource->save();
             }
             break;
         case 'Images':
             Schema::create('Images', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newImage = new Image();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newImage[$key] = $row[$key];
                 }
                 $newImage->save();
             }
             break;
         case 'Synonyms':
             Schema::create('Synonyms', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newSynonym = new Synonym();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newSynonym[$key] = $row[$key];
                 }
                 $newSynonym->save();
             }
             break;
         case 'BioNotes':
             Schema::create('BioNotes', function ($collection) {
                 //                    $collection->unique('spID');
             });
             foreach ($data as $row) {
                 $keys = array_keys($row);
                 //
                 $newBioNote = new BioNote();
                 //
                 foreach ($keys as $key) {
                     if (is_numeric($row[$key])) {
                         $row[$key] = (int) $row[$key];
                     }
                     $newBioNote[$key] = $row[$key];
                 }
                 $newBioNote->save();
             }
             break;
         default:
             return "Nothing is done";
     }
     //$csv->data[4]['spID'];
     return 'success!';
 }
 public function testLoveTrack()
 {
     $this->withoutEvents();
     $this->createSampleMediaSet();
     $user = factory(User::class)->create(['preferences' => ['lastfm_session_key' => 'bar']]);
     $interaction = Interaction::create(['user_id' => $user->id, 'song_id' => Song::first()->id]);
     $lastfm = m::mock(Lastfm::class, ['enabled' => true]);
     $lastfm->shouldReceive('toggleLoveTrack')->with($interaction->song->title, $interaction->song->album->artist->name, 'bar', false);
     (new LoveTrackOnLastfm($lastfm))->handle(new SongLikeToggled($interaction, $user));
 }