예제 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // Check to see if anime exists, if not then create new anime record
     $series = Anime::where('url', $request->input('anime_url'))->first();
     if ($series === null) {
         $series = new Anime();
         $series->name = $request->input('anime_name');
         $series->user_id = Auth::user()->id;
         $series->image = $request->input('anime_image');
         $series->synopsis = $request->input('anime_synopsis');
         $series->url = $request->input('anime_url');
         $series->save();
     }
     $mp3 = $request->file('track');
     $track = new Track();
     $track->name = $request->input('name');
     $track->user_id = Auth::user()->id;
     $track->anime_id = $series->id;
     $track->track = $mp3->getClientOriginalExtension();
     $track->save();
     if (!$request->hasFile('track')) {
         return "no file uploaded";
     }
     //Use some method to generate your filename here. Here we are just using the ID of the image
     $filename = $track->id . "." . $track->track;
     //Push file to S3
     Storage::disk('s3')->put($filename, file_get_contents($mp3));
     return redirect()->route('home')->with('status', 'Track Added!');
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     // always returns $user whether logged in or not, null if not
     view()->composer(['layouts._rightnav', 'layouts.loginForm', 'tracks.index', 'skills.create', 'level.index', 'tracks.editForm', 'levels.editForm', 'difficulties.editForm'], function ($view) {
         $view->with('user', Auth::check() ? Auth::user()->firstname : null);
     });
     view()->composer(['questions._questionform', 'skills.newform', 'skills._rowform'], function ($view) {
         $view->with(['tracks' => Track::lists('track', 'id'), 'levels' => Level::lists('description', 'id'), 'difficulties' => Difficulty::lists('difficulty', 'id'), 'skills' => Skill::lists('short_description', 'id'), 'user' => Auth::user()]);
     });
 }
 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;
 }
예제 #4
0
 public function run()
 {
     $track = Track::create(['track' => 'Whole Numbers', 'description' => 'Whole Numbers', 'user_id' => 1]);
     $track->levels()->sync([1, 2, 3, 4, 5, 6, 7]);
     Track::create(['track' => 'Units of Measurement', 'description' => 'Units of Measurement', 'user_id' => 2])->levels()->sync([1, 2, 3, 4, 5, 6, 7]);
     Track::create(['track' => 'Data Analysis', 'description' => 'Data Analysis', 'user_id' => 3])->levels()->sync([5, 6, 7]);
     Track::create(['track' => 'Geometry', 'description' => 'Geometry', 'user_id' => 1])->levels()->sync([4, 5, 6, 7]);
     Track::create(['track' => 'Ratio and Percentage', 'description' => 'Ratio and Percentage', 'user_id' => 1])->levels()->sync([5, 6, 7]);
     Track::create(['track' => 'Speed', 'description' => 'Speed', 'user_id' => 2])->levels()->sync([6, 7]);
     Track::create(['track' => 'Algebra', 'description' => 'Algebra', 'user_id' => 1])->levels()->sync([7]);
     Track::create(['track' => 'Graphs', 'description' => 'Graphs', 'user_id' => 4])->levels()->sync([5, 6, 7]);
     Track::create(['track' => 'Uncategorized', 'description' => 'Uncategorized', 'user_id' => 1]);
 }
예제 #5
0
 public function postAddPart(Request $request)
 {
     if (!$request->ajax()) {
         return response('Bad request', 400);
     }
     $track = Track::findOrFail($request->id);
     $user = User::where('name', '=', $request->name)->first();
     if (!$user) {
         return response()->json(['status' => false, 'msg' => trans('track.no_user')]);
     }
     $track->participants()->attach($user->id, ['type_id' => $request->part]);
     $part_id = DB::table('track_participants')->where('user_id', $user->id)->where('track_id', $track->id)->where('type_id', $request->part)->first()->id;
     return response()->json(['status' => true, 'user_id' => $user->id, 'part_id' => $part_id, 'text' => [trans('track.features'), trans('track.productions'), trans('track.remixes')]]);
 }
예제 #6
0
 /**
  * Checks to see if there are any dowloads let on a specific track. If not it send said track to a Job to be deleted.
  *
  * @var \Request, \Track
  * @return json
  */
 public function checkDownload(Request $request, Track $track)
 {
     $app = app();
     $message_return = $app->make('stdClass');
     if ($track->max_downloads > $track->current_downloads) {
         $track->current_downloads += 1;
         $track->save();
         $message_return->message = "success";
         return response()->json(['message_return' => $message_return], 200);
     } else {
         $message_return->message = "failure";
         $job = new DeleteTracks($track);
         $this->dispatch($job);
         return response()->json(['message_return' => $message_return], 200);
     }
 }
 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'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Track::destroy($id);
 }
예제 #9
0
 public function getRemove($id)
 {
     $track = Track::findOrFail($id);
     if (Auth::user()->id == $track->creator->id || Auth::user()->staff) {
         $track->delete();
         return redirect('/');
     }
     return redirect('/');
 }
예제 #10
0
 public function add_queue($id)
 {
     $track = Track::find($id);
     $dir_track = $track->dir_track;
     $this->queue($dir_track);
     return Redirect::to('tracks');
 }
예제 #11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\AddSongRequest $request)
 {
     /*
         cases:
         add track
             walang artist, walang album /
             may artist, walang album
             add lang talaga
     */
     //Start of Inserting a music
     //Start here.
     //dd($request->get('name'));
     //else{
     //dd(\Auth::user()->id);
     $track = new Track(array('name' => $request->get('name'), 'creator_id' => \Auth::user()->id));
     $track->save();
     flash()->overlay('Track uploaded.', 'Success!');
     //https://www.codetutorial.io/laravel-5-file-upload-storage-download/
     $fileName = $track->id . '.' . $request->file('image')->getClientOriginalExtension();
     $path = base_path() . '/public/tracks/' . $fileName;
     $request->file('image')->move(base_path() . '/public/tracks/', $fileName);
     //dd($path);
     $path = '/public/tracks/' . explode("/", $path)[sizeof(explode("/", $path)) - 1];
     //get value at last element
     //dd($path);
     DB::table('tracks')->where('id', $track->id)->update(['path' => $path]);
     //song is now uploaded and has filePath
     //dd($request->get('artist_name'));
     //getting an artist
     $artist = DB::table('artists')->where('name', $request->get('artist_name'))->first();
     //dd($artist);
     //}
     if ($artist) {
         //artist exists
         $artistHasSong = new ArtistHasSong(array('artist_id' => $artist->id, 'track_id' => $track->id));
         $artistHasSong->save();
         $album = DB::table('albums')->join('albums_has_artist', 'albums_has_artist.album_id', '=', 'albums.id')->select('albums_has_artist.*')->where('albums_has_artist.artist_id', '=', $artist->id)->where('albums.name', '=', $request->get('album_name'))->first();
         /*
             select * from albums_has_artist a 
             inner join 
                 albums b on a.albumId = b.albumId 
             where 
                 a.artist_id = $artist->id and 
                 b.name= $request->get('album_name')
         */
         //dd($album);
         if ($album) {
             //track and album exist and artist exist
             $albumHasSong = new AlbumHasSong(array('album_id' => $album->id, 'track_id' => $track->id));
             $albumHasSong->save();
             return redirect()->back();
             // return view('track.create',
             //             ['message'=>'Track Created']);
         } else {
             //album does not exist but artist and track exists
             // return redirect('/album/create')
             //         ->with(['track_id' => $track->id, 'artist_name' => NULL,
             //              'artist_id' => $artist->id, 'album_name' => $request->get('album_name')]);
             return view('album.create', ['track_id' => $track->id, 'artist_name' => NULL, 'artist_id' => $artist->id, 'album_name' => $request->get('album_name')]);
         }
     } else {
         //track exist now(); artist does not exist
         //to do on artist store artists has song:
         //to do on album store album has artist and album has song
         //dd($request->get('artist_name'));
         if ($request->get('artist_name') != NULL) {
             // return redirect('/artist/create')
             //         ->with(['artist_name' => $request->get('artist_name'), 'track_id' => $track->id,
             //          'track_name' => $track->name, 'album_name' => $request->get('album_name')]);
             return view('artist.create', ['artist_name' => $request->get('artist_name'), 'track_id' => $track->id, 'track_name' => $track->name, 'album_name' => $request->get('album_name')]);
         } else {
             // return redirect('/album/create')
             //         ->with(['artist_name' => $request->get('artist_name'), 'artist_id' => NULL,
             //          'track_id' => $track->id, 'album_name' => $request->get('album_name')]);
             return view('album.create', ['artist_name' => $request->get('artist_name'), 'artist_id' => NULL, 'track_id' => $track->id, 'album_name' => $request->get('album_name')]);
         }
     }
 }
예제 #12
0
 /**
  * Receive answer from test and format next question and test
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $user = Auth::user();
     $question = Question::with('skill')->with('difficulty')->with('skill.level')->with('skill.track')->find($request->question_id);
     // log
     $question->tests()->updateExistingPivot($request->test_id, ['answered' => TRUE], false);
     $user->tested_questions()->attach($request->question_id, ['correct' => $correct = $question->correct_answer == $request->answer]);
     // initialize
     $error_limit = Config::get('mathtest.error_test');
     $success_limit = Config::get('mathtest.success_test');
     $difficulty = $question->difficulty_id;
     $skill = $question->skill;
     $level = $skill->level;
     $track = $skill->track;
     $test = Test::find($request->test_id);
     $maxile = 0;
     // track if user has done questions of the same skill and difficulty
     $test_record = $test->questions()->selectRaw('question_test.question_id as id')->lists('id');
     $total_correct = $user->numberCorrect()->where('questions.difficulty_id', '=', $difficulty)->where('questions.skill_id', '=', $skill->id)->take(max($error_limit, $success_limit))->first()->total_correct;
     //        dd($total_correct);
     //       dd($question->correct_answer == $request->answer);
     $new_question = new Question();
     //        return $track->users()->get();
     if ($correct) {
         //if answer is correct
         //         dd($correct);
         if ($total_correct < $success_limit - 1) {
             //cleared this difficulty
             if ($new_question = Question::similar($difficulty, $skill->id)->whereNotIn('id', $test_record)->first()) {
                 //                    dd($correct);
             }
         } else {
             $user->track_results()->attach($question->track, ['difficulty_id' => $question->difficulty_id, 'skill_id' => $question->skill_id, 'level_id' => $question->skill->level->id, 'track_id' => $question->skill->track->id, 'maxile' => intval($question->skill->level->starting_maxile_level + 100 * ($difficulty / Difficulty::max('difficulty')) * ($skill->skill / Skill::whereLevelId($level->id)->max('skill')))]);
             if ($difficulty < Difficulty::max('difficulty')) {
                 $new_question = Question::harder($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
             } elseif ($skill->skill < Skill::whereTrackId($track->id)->whereLevelId($level->id)->max('skill')) {
                 $new_question = Question::whereNotIn('id', $test_record)->upskill($skill, $track->id, $level->id)->first();
             } elseif ($level->level < Level::max('level')) {
                 $new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'asc')->first()->id)->first();
             } else {
                 return ['msg' => 'You have reached the maximum level and difficulty for all skills in this track.'];
             }
         }
         // if answer is wrong
     } elseif ($difficulty > Difficulty::min('difficulty')) {
         $new_question = Question::easier($difficulty, $skill->id)->whereNotIn('id', $test_record)->first();
     } elseif ($skill->skill > Skill::whereTrackId($track->id)->whereLevelId($level->id)->min('skill')) {
         $new_question = Question::whereNotIn('id', $test_record)->downskill($skill, $track->id, $level->id)->first();
     } elseif ($level->level > Level::min('level')) {
         $new_question = Question::whereNotIn('id', $test_record)->whereSkillId(Skill::orderBy('skill', 'desc')->first()->id)->first();
     } else {
         return ['msg' => 'You have reached the minimum level and difficulty for all skills in this track.'];
     }
     //        dd($new_question);
     if (isset($new_question) and $new_question->id != null) {
         $new_question->tests()->attach($request->test_id, ['answered' => FALSE]);
         return $this->formatQuiz($new_question, $request->test_id);
     } else {
         return ['result' => Track::join('track_user', 'id', '=', 'track_id')->where('track_user.user_id', '=', $user->id)->select('tracks.track')->selectRaw('max(track_user.maxile) as max')->groupBy('tracks.track')->get()];
     }
 }
예제 #13
0
Route::get('password/reset/{token}', 'Auth\\PasswordController@getReset');
Route::post('password/reset', 'Auth\\PasswordController@postReset');
Route::get('/notices', function () {
    return view('pages.notices');
});
Route::resource('questions', 'QuestionController');
Route::post('questions/{id}', 'QuestionController@update');
Route::resource('skills', 'SkillController', ['except' => ['update', 'edit', 'show']]);
Route::post('skills/{id}', 'SkillController@update');
Route::resource('difficulties', 'DifficultyController', ['except' => ['update', 'edit', 'show']]);
Route::post('difficulties/{id}', 'DifficultyController@update');
Route::resource('levels', 'LevelController', ['except' => ['update', 'edit', 'show']]);
Route::post('levels/{id}', 'LevelController@update');
Route::resource('tracks', 'TrackController', ['except' => ['update', 'edit', 'show']]);
Route::post('tracks/{id}', 'TrackController@update');
Route::resource('images', 'ImageController', ['only' => ['store']]);
Route::get('getTracks', function () {
    return \App\Track::lists('description', 'id');
});
Route::get('/learn', function () {
    return view('learn.index');
});
Route::get('/quiz', function () {
    return view('quiz.index');
});
Route::post('/quiz/{id}', 'QuizController@update');
Route::get('/quizdata', 'QuizController@index');
// load database
Route::get('/loadall', 'LoadController@loadall');
// learn data
Route::get('/learndata', 'LearnController@index');
예제 #14
0
 public function getIndex()
 {
     $tracks = Track::with('anime')->limit(10)->get();
     return view('home', ['tracks' => $tracks]);
 }
예제 #15
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Track $track)
 {
     if (Request::ajax()) {
         return Track::findOrFail($track->id) ? Track::destroy($track->id) : null;
     } else {
     }
     Track::findOrFail($track->id) ? Track::destroy($track->id) : null;
     flash('Track is deleted');
     return redirect('tracks');
 }
예제 #16
0
 public function getIndex()
 {
     $tracks = Track::orderBy('created_at', 'desc')->take(8)->where('private', '!=', '1')->get();
     return view('propagate', ['tracks' => $tracks]);
 }
예제 #17
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (Gate::denies('admin')) {
         abort(403);
     }
     // TODO "Add Image" button
     $out = ['form_route' => ['route' => ['image.update', $id], 'method' => 'PUT', 'class' => 'form-horizontal', 'files' => true]];
     if (count(Request::old())) {
         $rq = Request::old();
         $out['image'] = new Image($rq);
         if (isset($rq['artist_id']) && is_array($rq['artist_id'])) {
             $out['image']->artists = Artist::whereIn('id', $rq['artist_id'])->get();
         }
         if (isset($rq['release_id']) && is_array($rq['release_id'])) {
             $out['image']->releases = Release::whereIn('id', $rq['release_id'])->get();
         }
         if (isset($rq['track_id']) && is_array($rq['track_id'])) {
             $out['image']->tracks = Track::whereIn('id', $rq['track_id'])->get();
         }
     } else {
         $out['image'] = Image::findOrNew($id);
     }
     return view('images.form', $out);
 }
예제 #18
0
 public function search($str)
 {
     $out = Track::where('name', 'LIKE', $str . '%')->get(['id', 'name', 'release_id']);
     foreach ($out as &$row) {
         $release = $row->release()->first();
         $row->release = $release->name;
         $row->artist = $release->credit()->first()->name;
     }
     return $out;
 }