Example #1
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Genre::create(['type' => $faker->locale]);
     }
 }
Example #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $book = Book::find($id);
     $authors = Author::lists('name', 'author_id');
     $genres = Genre::lists('name', 'genre_id');
     return view('books/book-edit', ['id' => $id, 'authors' => $authors, 'genres' => $genres]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->ajax()) {
         Genre::create($request->all());
         return response()->json(["mensaje" => "creado"]);
     }
 }
Example #4
0
 public static function editBook($data, $id)
 {
     $book = Book::find($id);
     if ($data['title'] != '') {
         $book->title = $data['title'];
     }
     if ($data['isbn10'] != '') {
         $book->isbn10 = $data['isbn10'];
     }
     $author = new Author();
     $genre = new Genre();
     $author->name = $data['author'];
     $genre->name = $data['genre'];
     $authorToRemove = Author::find($data['authors']);
     $genreToRemove = Genre::find($data['genres']);
     $exisitngAuthor = Author::find($data['existing-author']);
     $exisitngGenre = Genre::find($data['existing-genre']);
     $book->authors()->detach($authorToRemove['author_id']);
     $book->genres()->detach($genreToRemove['genre_id']);
     $book->authors()->attach($exisitngAuthor['author_id']);
     $book->genres()->attach($exisitngGenre['genre_id']);
     if ($data['author'] != '') {
         $book->authors()->save($author);
         var_dump($data['author']);
     }
     if ($data['genre'] != '') {
         $book->genres()->save($genre);
     }
     $book->save();
 }
Example #5
0
 public function show($id)
 {
     $genre = Genre::find($id);
     $books = Book::where('genre_id', '=', $id)->get();
     $data = array('genre' => $genre, 'books' => $books);
     return view('pages.genre')->with('data', $data);
 }
Example #6
0
 public function actionDelete($id)
 {
     $user = Auth::user();
     $genre = Genre::where('user_id', '=', $user->id)->findOrFail($id);
     $genre->delete($genre);
     \Session::flash('flash_message', 'You have successfully deleted a genre.');
     return redirect('genres');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     $movies = Movie::lists('id')->all();
     $genres = Genre::lists('id')->all();
     $limit = 20;
     for ($i = 0; $i < $limit; $i++) {
         DB::table('movie_genre')->insert(['movie_id' => $faker->randomElement($movies), 'genre_id' => $faker->randomElement($genres)]);
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     if ($movie = Movie::find($id)) {
         $genres = Genre::get()->toArray();
         return view('movies.edit')->with('movie', $movie)->with('genres', $genres);
     }
     // User doesn't exist for this account
     $this->setMessage('Movie not found!', 'error');
     return redirect('/movies');
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $film = Film::with('genres')->where(['id' => $id])->first();
     $genres = Genre::all();
     // genre ids that film has been assigned
     $genreIds = [];
     foreach ($film->genres as $genre) {
         $genreIds[] = $genre->id;
     }
     return view('films.edit', compact('film', 'genres', 'genreIds'));
 }
Example #10
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $url = "http://omdbapi.com/?i=";
     // get all the videos with an IMDB ID
     $videos = Video::whereNotNull('imdb')->get();
     echo "\nUpdating....\n\n";
     // loop through all the videos
     foreach ($videos as $video) {
         // get JSON data
         $json = file_get_contents($url . $video->imdb);
         $obj = json_decode($json);
         // update fields of the video with JSON data
         $video->product->name = $obj->Title;
         $video->poster = '/img/posters/' . $video->imdb . '.jpg';
         $video->release_year = $obj->Year;
         if ($obj->Released !== 'N/A') {
             $video->release_date = new \DateTime($obj->Released);
         }
         // download the poster
         if (!file_exists('/img/posters/' . $video->imdb . '.jpg') && filter_var($obj->Poster, FILTER_VALIDATE_URL) !== false) {
             $buffer = file_get_contents($obj->Poster);
             $file = fopen(public_path() . '/img/posters/' . $video->imdb . '.jpg', 'w+');
             fwrite($file, $buffer);
             fclose($file);
         }
         // save the video
         $video->save();
         // delete the products gnere
         DB::table('genre_product')->where('product_id', $video->product_id)->delete();
         // get the genres
         $genres = explode(',', $obj->Genre);
         foreach ($genres as $key => $genre) {
             $genres[$key] = trim($genre);
         }
         // add the genres
         foreach ($genres as $genre) {
             // if genre does not exist create it
             $record = Genre::where('name', $genre)->first();
             if ($record === null) {
                 $record = Genre::create(['name' => $genre]);
             }
             // attatch genre to video
             $video->product->genres()->attach([$record->id]);
         }
         // log to screen
         echo $video->product_id . ". \t" . $video->product->name . " updated successfully.\n";
     }
 }
Example #11
0
 public function StoreGame(Request $request, $info)
 {
     // get the genres
     $genres = str_getcsv($request->genre);
     foreach ($genres as $key => $genre) {
         $genres[$key] = trim($genre);
     }
     // create product record
     $product = new Product($request->all());
     // use database transaction to save the records
     DB::transaction(function () use($product, $info, $genres) {
         // save the product record
         $product->save();
         // set the product id of the details record
         $info->product_id = $product->id;
         if (filter_var($info->poster, FILTER_VALIDATE_URL) !== false) {
             // download the poster
             if (!file_exists('/img/games/' . $info->product_id . '.jpg')) {
                 $buffer = file_get_contents($info->poster);
                 $file = fopen(public_path() . '/img/games/' . $info->product_id . '.jpg', 'w');
                 fwrite($file, $buffer);
                 fclose($file);
             }
             // set the poster url
             $info->poster = '/img/games/' . $info->product_id . '.jpg';
         }
         // save the details record
         $info->save();
         // add the genres
         foreach ($genres as $genre) {
             // if genre does not exist create it
             $record = Genre::where('name', $genre)->first();
             if ($record === null) {
                 $record = Genre::create(['name' => $genre]);
                 $product->genres()->attach([$record->id]);
             } else {
                 $product->genres()->attach([$record->id]);
             }
         }
     });
 }
 public function exportQuiz($id)
 {
     $quiz = Quiz::find($id);
     header('Content-Type: text/csv; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $quiz->name . '.csv"');
     $genresCollection = Genre::all();
     $genres = array();
     foreach ($genresCollection as $key => $value) {
         $genres[$value->id] = $value->name;
     }
     $questionsCollection = Question::where('quiz', $id)->get();
     $questions = array();
     foreach ($questionsCollection as $key => $value) {
         $questions[$value->level][$value->genre][$value->tableid] = $value;
     }
     $output = 'Pergunta;Resposta;NĂ­vel;Cascata;Equipa;Tema' . "\n";
     // CSV HEADER
     for ($questionid = 1; $questionid <= 192; $questionid++) {
         if ($questionid <= 16 * 6) {
             $questionLevel = 1;
         } elseif ($questionid <= 16 * 6 + 10 * 6) {
             $questionLevel = 2;
         } else {
             $questionLevel = 3;
         }
         switch ($questionLevel) {
             case '1':
                 $previousLevelsQuestions = 0;
                 $questionTeam = $questionid % 16 ? $questionid % 16 : 16;
                 $round = ceil(($questionid - $previousLevelsQuestions) / 16);
                 break;
             case '2':
                 $previousLevelsQuestions = 16 * 6;
                 $questionTeam = ($questionid - $previousLevelsQuestions) % 10 ? ($questionid - $previousLevelsQuestions) % 10 : 10;
                 $round = ceil(($questionid - $previousLevelsQuestions) / 10);
                 break;
             case '3':
                 $previousLevelsQuestions = 16 * 6 + 10 * 6;
                 $questionTeam = ($questionid - $previousLevelsQuestions) % 6 ? ($questionid - $previousLevelsQuestions) % 6 : 6;
                 $round = ceil(($questionid - $previousLevelsQuestions) / 6);
                 break;
         }
         $questionGenre = ($round - 1 + $questionTeam - 1) % 6 + 1;
         $question = $questions[$questionLevel][$questionGenre][$questionTeam];
         if ($questionLevel > 1) {
             $questionTeam = '';
         }
         $output .= $question->text . ';' . $question->answer . ';' . $question->level . ';' . $round . ';' . $questionTeam . ';' . $genres[$question->genre] . "\n";
     }
     $output .= ';;;;' . "\n";
     $questionLevel = 1;
     $questionGenre = 1;
     $questionTeam = -1;
     for ($questionid = 1; $questionid <= 36; $questionid++) {
         $question = $questions[$questionLevel][$questionGenre][$questionTeam];
         $output .= $question->text . ';' . $question->answer . ';' . $question->level . ';;;' . $genres[$question->genre] . "\n";
         $questionTeam--;
         if ($questionTeam < -2) {
             $questionTeam = -1;
             $questionGenre++;
         }
         if ($questionGenre > 6) {
             $questionGenre = 1;
         }
         if ($questionid % 12 == 0) {
             $questionLevel++;
         }
     }
     echo utf8_decode($output);
 }
Example #13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Genre $genre)
 {
     $genre->delete();
     Session::flash('message', 'Genre deleted');
     return redirect('/genre');
 }
 public function viewTodayQuiz()
 {
     $user_id = Auth::user()->id;
     $year = date('Y');
     $month = date('n');
     $day = date('j');
     $firstMonday = date("j", strtotime('first monday of ' . $year . '-' . $month));
     $leagueYear = $year;
     if ($firstMonday > $day) {
         $leagueMonth = $month - 1;
         if (!$leagueMonth) {
             $leagueMonth = 12;
             $leagueYear--;
         }
     } else {
         $leagueMonth = $month;
     }
     $dayOffset = 0;
     $round = 0;
     for ($i = 0; $i < 20; $i++) {
         $round++;
         if (date("d-m-Y") == date("d-m-Y", strtotime('first monday of ' . $leagueYear . '-' . $leagueMonth) + 86400 * $dayOffset)) {
             break;
         }
         if (($i + 1) % 5 == 0) {
             $dayOffset = $dayOffset + 3;
         } else {
             $dayOffset++;
         }
     }
     if ($round % 10 == 0) {
         $solo = true;
     } else {
         $solo = false;
     }
     $leagues = League::where('year', $year)->where('month', $leagueMonth)->get();
     $league_id = 0;
     foreach ($leagues as $key => $league) {
         $players = json_decode($league->users);
         if (in_array($user_id, $players)) {
             $league_id = $league->id;
         }
     }
     $opponent = 0;
     $roundGame = Game::where('user_1_id', $user_id)->where('round', $round)->where('league_id', $league_id)->first();
     if (!count($roundGame)) {
         $roundGame = Game::where('user_2_id', $user_id)->where('round', $round)->where('league_id', $league_id)->first();
         if (count($roundGame)) {
             $opponent = $roundGame->user_1_id;
         }
     } else {
         $opponent = $roundGame->user_2_id;
     }
     if ($opponent) {
         $start = (new Carbon('now'))->hour(0)->minute(0)->second(0);
         $end = (new Carbon('now'))->hour(23)->minute(59)->second(59);
         $answers = Answer::where('submitted', 1)->where('user_id', $opponent)->whereNotBetween('updated_at', [$start, $end])->get();
         $genresCollection = Genre::all();
         $subgenresCollection = Subgenre::all();
         $genres = array();
         foreach ($genresCollection as $key => $genre) {
             $genres[$genre->id] = array();
             $genres[$genre->id]['info'] = $genre;
             $genres[$genre->id]['corrects'] = 0;
             $genres[$genre->id]['total'] = 0;
             $genres[$genre->id]['percentage'] = 0;
         }
         $subgenres = array();
         foreach ($subgenresCollection as $key => $subgenre) {
             $subgenres[$subgenre->id] = array();
             $subgenres[$subgenre->id]['info'] = $subgenre;
             $subgenres[$subgenre->id]['corrects'] = 0;
             $subgenres[$subgenre->id]['total'] = 0;
             $subgenres[$subgenre->id]['percentage'] = 0;
         }
         foreach ($answers as $key => $answer) {
             $answerQuestion = $answer->question()[0];
             $answerGenre = $answerQuestion->genre_id;
             $answerSubgenre = $answerQuestion->subgenre_id;
             if ($answer->correct) {
                 $genres[$answerGenre]['corrects']++;
                 $subgenres[$answerSubgenre]['corrects']++;
             }
             $genres[$answerGenre]['total']++;
             $subgenres[$answerSubgenre]['total']++;
         }
         foreach ($genres as $key => $genre) {
             if ($genres[$key]['total']) {
                 $genres[$key]['percentage'] = round($genre['corrects'] / $genre['total'] * 100, 2);
             }
         }
         $percentage = array();
         foreach ($subgenres as $key => $subgenre) {
             if ($subgenres[$key]['total']) {
                 $subgenres[$key]['percentage'] = round($subgenre['corrects'] / $subgenre['total'] * 100, 2);
                 $percentage[$key] = $subgenres[$key]['percentage'];
             } else {
                 $subgenres[$key]['percentage'] = 0;
                 $percentage[$key] = 0;
             }
         }
         if ($percentage) {
             array_multisort($percentage, SORT_DESC, $subgenres);
         }
         $opponent = User::find($opponent);
     } else {
         $genres = [];
         $subgenres = [];
     }
     $questions = Question::where('year', $year)->where('month', $month)->where('day', $day)->get();
     $filetype = [];
     $answers = [];
     foreach ($questions as $key => $question) {
         $filetype[$question->genre_id] = pathinfo($question->filename, PATHINFO_EXTENSION);
         $answers[$question->genre_id] = '';
     }
     $submitted = false;
     foreach ($questions as $key => $question) {
         $answer = Answer::where('question_id', $question['id'])->where('user_id', $user_id)->orderBy('id', 'desc')->first();
         $answers[$question->genre_id] = $answer;
         if ($answer) {
             if ($answer->submitted) {
                 $submitted = true;
             }
         }
     }
     if ($submitted) {
         return view('quiz_answered')->with(['questions' => $questions, 'answers' => $answers, 'filetype' => $filetype, 'year' => $year, 'month' => $month, 'day' => $day, 'solo' => $solo]);
     } else {
         return view('quiz')->with(['questions' => $questions, 'filetype' => $filetype, 'answers' => $answers, 'solo' => $solo, 'genres' => $genres, 'subgenres' => $subgenres, 'opponent' => $opponent]);
     }
 }
Example #15
0
 public function show($genre_id, $id)
 {
     $book = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'description_short', 'book.description', 'price', 'sale', 'quantity')->findOrFail($id);
     if ($genre_id != 'genre') {
         $genre = Genre::find($genre_id);
         if ($genre->count() > 0) {
             return view('pages.book')->with('book', $book)->with('genre', $genre);
         } else {
             return view('errors.404');
         }
     } else {
         return view('pages.book')->with('book', $book);
     }
 }
Example #16
0
<?php

use App\Film;
use App\Genre;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
// Authentication routes...
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Route::post('auth/login', 'Auth\\AuthController@postLogin');
Route::get('auth/logout', 'Auth\\AuthController@getLogout');
Route::resource('films', 'FilmsController');
Route::get('/', function () {
    $films = Film::orderBy('title', 'asc')->with('genres')->get();
    $genres = Genre::orderBy('name', 'asc')->get();
    return view('list', compact('films', 'genres'));
});
Example #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);
     }
     $out = ['form_route' => ['route' => ['track.update', $id], 'method' => 'PUT', 'class' => 'form-horizontal'], 'artist_credit' => []];
     $out['track'] = Track::findOrNew((int) $id);
     $out['genre'] = Genre::orderBy('id')->lists('name', 'id');
     if (count(Request::old())) {
         $old = Request::old();
         $out['release'] = Release::find($old['release_id']);
         if (isset($old['artist_credit']['id'])) {
             foreach ($old['artist_credit']['id'] as $n => $ac_id) {
                 $artist = Artist::where('id', $ac_id)->firstOrFail();
                 if (count($artist)) {
                     $out['artist_credit'][$n]['name'] = $artist->name;
                     $out['artist_credit'][$n]['work_type_id'] = $old['artist_credit']['work'][$n];
                     $out['artist_credit'][$n]['join_phrase'] = $old['artist_credit']['join'][$n];
                     $out['artist_credit'][$n]['artist_id'] = $old['artist_credit']['id'][$n];
                 }
             }
         }
     } else {
         $out['release'] = $out['track']->release;
         $out['artist_credit'] = $out['track']->credit->credit_name;
     }
     $out['work_type'] = WorkType::all();
     $out['genres_selected'] = [];
     foreach ($out['track']->genres as $row) {
         $out['genres_selected'][] = $row->id;
     }
     return view('tracks.form', $out);
 }
Example #18
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $genre = Genre::find($id);
     $genre->delete();
     return Redirect('/genres');
 }
Example #19
0
 public static function editGenre($data, $id)
 {
     $genre = Genre::find($id);
     $genre->name = $data['title'];
     $genre->save();
 }
Example #20
0
 /**
  * @param Broadcast $broadcast
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function edit(Broadcast $broadcast)
 {
     $genres = Genre::lists('name', 'id');
     return view('broadcasts.edit', compact('broadcast', 'genres'));
 }
Example #21
0
 public function getSelectList()
 {
     return Genre::lists('name', 'id');
 }
Example #22
0
 private function checkGenres($genres)
 {
     $user = Auth::user();
     $currentGenres = array_filter($genres, 'is_numeric');
     $newGenres = array_diff($genres, $currentGenres);
     foreach ($newGenres as $newGenre) {
         $genre = Genre::create(['name' => $newGenre]);
         $user->genres()->save($genre);
         $currentGenres[] = $genre->id;
     }
     return $currentGenres;
 }
Example #23
0
 private function getGenres($genres, &$show)
 {
     $showGenres = [];
     foreach ($genres as $genre) {
         $tmpGenre = Genre::firstOrNew(['genre' => $genre]);
         $tmpGenre->genre = $genre;
         $tmpGenre->save();
         array_push($showGenres, $tmpGenre->id);
     }
     $show->genres()->sync($showGenres);
 }
Example #24
0
 /**
  * @param $genre_id
  * @return mixed
  */
 public function destroy($genre_id)
 {
     return Genre::destroy($genre_id);
 }
 public function createQuestions()
 {
     $genres = Genre::all();
     return view('admin/createQuestions')->with(['genres' => $genres]);
 }