Beispiel #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     Model::unguard();
     $NUMBER_USERS = 5;
     $latitude = [-5.811914, -5.821626, -5.83913, -5.84212, -5.80114, -5.81143, -5.828402, -5.811301, -5.840302, -5.81241];
     $longitude = [-35.212368, -35.221813, -35.235454, -35.242454, -35.204454, -35.220054, -35.241451, -35.215454, -35.232054, -35.213442];
     for ($i = 0; $i < $NUMBER_USERS; $i++) {
         $user = new User(['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt('secret')]);
         $user->save();
         for ($j = 0; $j < $NUMBER_USERS; $j++) {
             $film = new Film(['omdb' => 'tt' . $faker->randomNumber(7), 'user_id' => $user->id, 'watched' => $faker->boolean()]);
             $film->save();
             if ($j < $NUMBER_USERS - 1) {
                 $lat = $faker->randomElement($latitude);
                 $geo = $faker->randomElement($longitude);
             } else {
                 $lat = $latitude[0];
                 $geo = $longitude[0];
             }
             $geo = new Geo(['lat' => $lat, 'lng' => $geo, 'film_id' => $film->id]);
             $geo->save();
         }
     }
     Model::reguard();
 }
Beispiel #2
0
 public function getTrace()
 {
     $urls = App\Film::where('check', '0')->take(1000)->orderBy('id', 'desc')->get();
     foreach ($urls as $url) {
         $href = $url->url;
         if (substr(parse_url($href)['path'], 1, 3) == 'tag') {
             $url->check = 1;
             $url->save();
         }
     }
     dd("it is OK");
 }
Beispiel #3
0
 /**
  * Auxiliar function to manage the notification event.
  *
  * Everytime a film is stored, it's checked whether there
  * are any other films by a 1km-radius. 
  *
  * If any films are found, an Event is triggered and a 
  * notification is sent to those users.
  * 
  * @param  $geo coordinates 
  * @param  $user user who saved the film 
  * @param  $film film being stored 
  */
 public function sendNotification($geo, $user, $film)
 {
     // Get users' id that marked a film nearby
     // 1km radius
     $users = Film::near(1, $geo->lat, $geo->lng)->get()->unique('user_id')->pluck('user_id')->all();
     // Remove authenticated user from the search
     if (($key = array_search($user->id, $users)) !== false) {
         unset($users[$key]);
     }
     // If there were any films nearby, send the notific
     if (!empty($users)) {
         Event::fire(new FilmWasStored($users, $user->id, $film));
     }
 }
Beispiel #4
0
 /**
  * Finds the nearest films. 
  * Using the Haversine formula.
  * Raw Query:.
  *
  * @param int $id
  *
  * @return Response
  */
 public function nearFilms($radius, $lat, $lng)
 {
     $films = Film::near($radius, $lat, $lng)->get();
     return json_encode($films);
 }
Beispiel #5
0
 public function rate($id)
 {
     if (Request::ajax()) {
         $rate = Input::get('rate');
         $film = Film::findById($id);
         $user_id = Auth::user()->id;
         $film->rating()->attach($user_id, array('rate' => $rate));
         return true;
     }
     return false;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Film::destroy($id);
     return redirect()->route('films.index')->with('flash_message', 'Film Deleted');
 }
Beispiel #7
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'));
});
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Film::truncate();
     factory(App\Film::class, 50)->create();
 }