public function loadAudio($id)
 {
     $userID = Auth::user()['id'];
     $track = Track::find($id);
     $path = $track->file_path;
     $testpath = basename($path);
     if (Storage::exists("audio/" . $userID . "/" . $testpath)) {
         return response()->download($path);
     }
     return;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $validator = Validator::make($request->all(), ['date' => 'required|date', 'distance' => 'required|numeric', 'time' => 'required', 'type_id' => 'required|numeric']);
     if ($validator->fails()) {
         return response()->json(['error' => 'invalid_data'], 422);
     }
     $track = Track::find($id);
     $track->date = $request->input('date');
     $track->distance = $request->input('distance');
     $track->time = $request->input('time');
     $track->type_id = $request->input('type_id');
     $track->save();
     return $track;
 }
 public function savePlaylist(Request $request, $id = null)
 {
     $this->validate($request, ['playlistName' => 'required|string|max:20']);
     $userID = Auth::user()['id'];
     if ($id != null) {
         $playlist = Playlist::find($id);
         if ($playlist == null) {
             //create new
             $playlist = new Playlist();
         }
     } else {
         //create new
         $playlist = new Playlist();
     }
     //fill in fields
     $playlist->user_id = $userID;
     $playlist->playlist_name = RequestF::input('playlistName');
     //create playlist
     $playlist->save();
     $insertedID = $playlist->id;
     //for each checkbox checked add song in playlist songs table
     $data = RequestF::all();
     foreach ($data as $name => $val) {
         if ($val == "on") {
             //find corresponding model
             $track = Track::find($name);
             //delete the model
             if ($track != null) {
                 DB::insert('INSERT INTO playlist_songs (playlist_id, track_id) values (?, ?)', [$insertedID, $name]);
             }
         }
     }
     return new RedirectResponse(url('/playlists'));
 }
예제 #4
0
 public function add_queue($id)
 {
     $track = Track::find($id);
     $dir_track = $track->dir_track;
     $this->queue($dir_track);
     return Redirect::to('tracks');
 }
예제 #5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(TrackRequest $request, $id)
 {
     if (Gate::denies('admin')) {
         abort(403);
     }
     $track = Track::find($id);
     // Old track data
     $req = $request->all();
     // Request data
     $genre = [];
     // genre list
     $genre_old = [];
     // genre list
     foreach ($req['genre'] as $n => $genre_id) {
         $genre[$n] = GenreTrack::where('track_id', $id)->where('genre_id', $genre_id)->first();
         if ($genre[$n] == null) {
             $genre_new = ['genre_id' => $genre_id, 'track_id' => $id];
             $genre[$n] = new GenreTrack($genre_new);
             $genre[$n]->save();
         }
         $genre_old[] = $genre[$n]->id;
     }
     GenreTrack::where('track_id', $id)->whereNotIn('id', $genre_old)->delete();
     $ac = [];
     // list of ArtistCreditNames
     $ac_old = [];
     // List of artist credit names that already exist
     $artists = [];
     // List of artists, just for counting
     foreach ($req['artist_credit']['work'] as $n => $work_id) {
         $artist_id = $req['artist_credit']['id'][$n];
         $join_phrase = $req['artist_credit']['join'][$n];
         $artists[$artist_id] = $join_phrase . ' ' . Artist::find($artist_id)->name;
         // artiat counter
         // Checking if ArtistCreditName already exists
         $ac[$artist_id . '_' . $work_id . '_' . $join_phrase] = ArtistCreditName::where('work_type_id', (int) $work_id)->where('artist_id', $artist_id)->where('join_phrase', $join_phrase)->where('artist_credit_id', $track->credit->id)->first();
         if ($ac[$artist_id . '_' . $work_id . '_' . $join_phrase] == null) {
             // Creating new ArtistCreditName
             $ac_new = ['artist_credit_id' => $track->credit->id, 'artist_id' => $artist_id, 'work_type_id' => $work_id, 'position' => '', 'name' => Artist::find($artist_id)->name, 'join_phrase' => $join_phrase];
             $ac[$artist_id . '_' . $work_id . '_' . $join_phrase] = new ArtistCreditName($ac_new);
         }
         // Sets position. Not important for now there is no ordering in form
         // TODO make ordering in form
         $ac[$artist_id . '_' . $work_id . '_' . $join_phrase]->position = $n;
         // Saving ArtistCreditNames
         $ac[$artist_id . '_' . $work_id . '_' . $join_phrase]->save();
         // preventing deleting of used ArtistCreditNAmes
         $ac_old[] = $ac[$artist_id . '_' . $work_id . '_' . $join_phrase]->id;
     }
     // Delete not used ArtistCreditNames
     ArtistCreditName::where('artist_credit_id', $track->credit->id)->whereNotIn('id', $ac_old)->delete();
     $track->credit->artist_count = count($artists);
     $track->credit->ref_count = count($ac);
     $track->credit->name = trim(implode(' ', $artists), ' &');
     $track->credit->save();
     // Saving track data
     $track->update($req);
     // Redirect back to Show with message
     return redirect()->route('track.show', ['track' => $id])->with('alert-success', [trans('htmusic.saved')]);
 }