示例#1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $data = Items::find($id);
     if ($data) {
         if ($request->has('name')) {
             $data->name = $request->input('name');
         }
         if ($request->has('status') && ($status = States::find($request->input('status')))) {
             $data->status = $status->id;
         }
         if ($request->has('user_id') && ($person = Persons::find($request->input('user_id')))) {
             $data->user_id = $person->id;
         }
         if ($request->has('title')) {
             $data->title = $request->input('title');
         }
         if ($request->has('description')) {
             $data->description = $request->input('description');
         }
         if ($data->save()) {
             return $this->success($data);
         } else {
             return $this->error("failed to save");
         }
     } else {
         return $this->error("No person with this id");
     }
 }
示例#2
0
 public function index()
 {
     $app = app();
     $details = $app->make('stdClass');
     // most recent purchases
     $details->most_recent = Movies::getMovieRecords('purchased', 'DESC', 10);
     // top rated movies
     $details->top_rated = Movies::getTopRated();
     foreach ($details->top_rated as $movie) {
         $movie->rating_display = $this->makeRatingStars($movie->rating);
     }
     // get most popular actors
     $details->actors = Persons::getActorCount(24);
     // get most popular directors
     $details->directors = Persons::getDirectorCount(24);
     $details->birthdays = Persons::getTodaysBirthdays();
     foreach ($details->birthdays as $birthday) {
         $birthday->age = $this->calculateAge($birthday->birthday, $birthday->deceased);
     }
     // highlight randomly selected movie
     $random_id = Movies::selectRandomFilm();
     $details->highlight = Movies::findorfail($random_id);
     $details->highlight->cast = $details->highlight->cast->take(3);
     $details->highlight->crew = Crew::where('movie_id', $random_id)->select(DB::raw('GROUP_CONCAT(CONCAT(persons.forename, " ", persons.surname) SEPARATOR ", ") as list'))->join('persons', 'persons.person_id', '=', 'crew.person_id')->groupBy('movie_id')->where('position', 'Director')->take(1)->get();
     $details->highlight->cover_count = strlen($details->highlight->cover);
     $details->highlight->rating_display = $this->makeRatingStars($details->highlight->rating);
     $details->decades = $this->makeDecades();
     $user = $this->isAdmin;
     return view('welcome', compact('details', 'user'));
 }
示例#3
0
 public static function newId()
 {
     $newId = "";
     for ($i = 0; $i < 500; $i++) {
         $newId = "X";
         $characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         $charactersLength = strlen($characters);
         for ($s = 0; $s < 2; $s++) {
             $newId .= $characters[rand(0, $charactersLength - 1)];
         }
         if (!Persons::find($newId)) {
             return $newId;
         }
     }
 }
示例#4
0
 public function filterMovies()
 {
     if (Request::ajax()) {
         $data = Request::all();
         $type = $data['type'];
         $search_string = trim($data['val']);
         if ($search_string != "") {
             $query = Movies::select('movies.*');
             switch ($type) {
                 case "all":
                     $query->where('name', 'LIKE', '%' . $search_string . '%');
                     break;
                 case "studio":
                     $query->where('studios.name', 'LIKE', '%' . $search_string . '%')->join('studios', 'movies.studio_id', '=', 'studios.studio_id');
                     break;
                 case "format":
                     $query->where('formats.type', 'LIKE', '%' . $search_string . '%')->join('formats', 'movies.format_id', '=', 'formats.format_id');
                     break;
                 case "certificate":
                     $query->where('certificate_id', $search_string);
                     break;
                 case "year":
                     $query->where('released', $search_string);
                     break;
                 case "rating":
                     $query->where('rating', $search_string);
                     break;
                 case "tag":
                     $query->where('keywords.word', 'LIKE', '%' . $search_string . '%')->join('tags', 'movies.movie_id', '=', 'tags.movie_id')->join('keywords', 'keywords.keyword_id', '=', 'tags.keyword_id');
                     break;
             }
             $query->orderBy('sort_name');
             $movies = $query->get();
             if ($type == "all") {
                 $people = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), 'LIKE', '%' . $search_string . '%')->orderBy('forename')->get();
             } else {
                 $people = [];
             }
             $user = $this->isAdmin;
             $quote = count($movies) ? "" : $this->getRandomQuote();
             return (string) view('ajax.movie_filter', compact('movies', 'people', 'quote', 'user'));
         } else {
             return "blank";
         }
     }
 }
示例#5
0
 public function index()
 {
     if (!$this->isAdmin) {
         return redirect()->action('WelcomeController@index');
     }
     $app = app();
     $data = $app->make('stdClass');
     $data->movie_total = Movies::all()->count();
     $data->person_total = Persons::all()->count();
     $data->running_total = Movies::all()->sum('running_time');
     $total_days = floor($data->running_total / 1440) == 1 ? floor($data->running_total / 1440) . " day, " : floor($data->running_total / 1440) . " days, ";
     $total_hours = floor($data->running_total % 1440 / 60) == 1 ? floor($data->running_total % 1440 / 60) . " hour and " : floor($data->running_total % 1440 / 60) . " hours and ";
     $total_minutes = $data->running_total % 1440 % 60 == 1 ? $data->running_total % 1440 % 60 . " minute" : $data->running_total % 1440 % 60 . " minutes";
     $data->watching_time = $total_days . $total_hours . $total_minutes;
     $user = $this->isAdmin;
     return view('admin.index', compact('data', 'user'));
 }
示例#6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     if (States::isProtected($id)) {
         return $this->error("This item is protected");
     }
     if (sizeof(States::all()) <= 2) {
         return $this->error("Do you really want to delete all States? In which state are you?!");
     }
     if (Items::hasStatus($id) || Persons::hasStatus($id)) {
         return $this->error("Do you really want to delete all States? In which state are you?!");
     }
     $data = States::find($id);
     if ($data) {
         $data->delete();
         return $this->success($data);
     } else {
         return $this->error("Item doesn't exist");
     }
 }
示例#7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $data = Persons::find($id);
     if ($data) {
         if (Items::hasUser($data->id)->first()) {
             return $this->error("there is still an item allocated to his person");
         } else {
             $data->delete();
             return $this->success($data);
         }
     } else {
         return $this->error("No item with this id");
     }
 }
示例#8
0
 /**
  *
  * Check the person does not already exist in the database
  * @param string $forename
  * @param string $surname
  * @return Response
  *
  */
 private function checkExistingPeople($forename, $surname)
 {
     $query = Persons::where('forename', $forename);
     if ($surname != "") {
         $query->where('surname', $surname);
     }
     $existing = $query->first();
     if (count($existing) == 0) {
         return false;
     } else {
         return $existing->person_id;
     }
 }
示例#9
0
 public function getAvailableCrew()
 {
     if (Request::ajax()) {
         $data = Request::all();
         $movie_id = $data['movie'];
         $actors = Persons::select(DB::raw("CONCAT(forename, ' ', surname) AS full_name"), 'person_id')->whereNotIn('person_id', function ($query) use($movie_id) {
             $query->select('person_id')->from('crew')->where('movie_id', $movie_id);
         })->orderBy('forename')->get()->toJson();
         return $actors;
     }
 }
 public function update_Address()
 {
     try {
         $personId = Input::get('pk');
         $newValue = Input::get('value');
         $personData = Persons::wherepersonId($personId)->first();
         $personData->person_road = $newValue['street'];
         $personData->person_soi = $newValue['soi'];
         $personData->person_mooh_num = $newValue['mooh'];
         $personData->person_house_num = $newValue['house_number'];
         $personData->person_tumbon = $newValue['tumbon'];
         $personData->person_amphur = $newValue['amphur'];
         $personData->person_province = $newValue['province'];
         $personData->person_post_code = $newValue['post_code'];
         if ($personData->save()) {
             return response()->json(array('status' => "Complete "));
         } else {
             return response()->json(array('status' => 'Error'));
         }
     } catch (Exception $e) {
         DB::rollback();
         $result['status'] = "Error";
         $result['message'] = $e->getMessage();
         return response()->json($result, 200);
     }
 }
示例#11
0
 public function filterMovies($request)
 {
     $data = $request->all();
     $search_string = trim($data['val']);
     if ($search_string != "") {
         $movies = Movies::select('movies.*')->where('name', 'LIKE', '%' . $search_string . '%')->orderBy('sort_name')->get();
         $people = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), 'LIKE', '%' . $search_string . '%')->orderBy('forename')->get();
         $user = $this->isAdmin;
         $quote = count($movies) ? "" : $this->getRandomQuote();
         return view('ajax.movie_filter', compact('movies', 'people', 'quote', 'user'));
     }
 }
示例#12
0
 public function getDirectors()
 {
     echo "Started " . date("H:i:s") . "...... <br/><br/>";
     $movie_count = Movies::all()->count();
     echo $movie_count . " movies<br/>";
     flush();
     ob_flush();
     for ($x = $this->counter; $x < 1000; $x += 10) {
         $movies = Movies::take(10)->offset($x)->get();
         foreach ($movies as $movie) {
             if ($movie->imdb_id) {
                 $hasDirector = false;
                 foreach ($movie->crew as $person) {
                     if ($person->pivot->position == "Director") {
                         $hasDirector = true;
                     }
                 }
                 if (!$hasDirector) {
                     $client = new \GuzzleHttp\Client();
                     $my_token = env('IMDB_KEY');
                     $url = 'http://api.myapifilms.com/imdb/idIMDB?idIMDB=' . $movie->imdb_id . '&token=' . $my_token . '&format=json&language=en-us';
                     $imdb_response = $client->get($url);
                     $imdb_body = $imdb_response->getBody();
                     $imdb_api = json_decode($imdb_body);
                     if (count($imdb_api->data->movies)) {
                         $imdb = $imdb_api->data->movies[0];
                         if ($imdb->directors) {
                             $director_name = $imdb->directors[0]->name;
                             $imdb_id = $imdb->directors[0]->nameId;
                             $person = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), htmlentities($director_name, ENT_QUOTES))->first();
                             if (!$person) {
                                 $client = new \GuzzleHttp\Client();
                                 $url = 'http://api.myapifilms.com/imdb/idIMDB?idName=' . $imdb_id . '&token=' . $my_token . '&format=json&language=en-us&bornDied=1';
                                 $imdb_response = $client->get($url);
                                 $imdb_body = $imdb_response->getBody();
                                 $imdb_api = json_decode($imdb_body);
                                 if (count($imdb_api->data->names)) {
                                     $data = [];
                                     $imdb = $imdb_api->data->names[0];
                                     $names = array_values(array_filter(explode(' ', $imdb->name)));
                                     $data['surname'] = count($names) ? $this->formatName(array_pop($names)) : "";
                                     $data['forename'] = count($names) ? $this->formatName(implode(" ", $names)) : "";
                                     $deceased = isset($imdb->died) ? $imdb->died . "<br/><br/>" : "";
                                     $data['bio'] = isset($imdb->bio) ? strlen($imdb->bio) > 1000 ? $deceased . substr($imdb->bio, 0, 1000) . " ...." : $deceased . $imdb->bio : "";
                                     $content = file_get_contents($imdb->urlPhoto);
                                     $image_name = $this->createImageName($data['forename'] . " " . $data['surname']);
                                     $fp = fopen('images/people/' . $image_name, "w");
                                     fwrite($fp, $content);
                                     fclose($fp);
                                     $img = Image::make('images/people/' . $image_name);
                                     $img->resize(300, 450);
                                     $img->save('images/people/' . $image_name);
                                     $data['image'] = $image_name;
                                     if (isset($imdb->dateOfBirth)) {
                                         $born = new DateTime(preg_replace("/[^a-zA-Z0-9]/", ' ', $imdb->dateOfBirth));
                                         $data['birthday'] = $born->format('Y-m-d');
                                     }
                                     $update = Persons::create($data);
                                     $inserted_id = $update->person_id;
                                     $movie->crew()->attach($inserted_id, array('position' => 'Director'));
                                     echo "NEW (" . $movie->movie_id . ") " . $movie->name . " : " . $director_name . " added<br/>";
                                 }
                             } else {
                                 $movie->crew()->attach($person->person_id, array('position' => 'Director'));
                                 echo "ADD (" . $movie->movie_id . ") " . $movie->name . " : " . $director_name . " added to movie<br/>";
                             }
                         } else {
                             echo "N/A (" . $movie->movie_id . ") " . $movie->name . " : no directors found<br/>";
                         }
                     } else {
                         echo "N/A (" . $movie->movie_id . ") " . $movie->name . " : no data found<br/>";
                     }
                 } else {
                     echo "EXT (" . $movie->movie_id . ") " . $movie->name . " : director exists<br/>";
                 }
             } else {
                 echo "nID (" . $movie->movie_id . ") " . $movie->name . " : no imdb id<br/>";
             }
             flush();
             ob_flush();
         }
     }
     echo "<br/><br/>Finished " . date("H:i:s");
 }
示例#13
0
 /**
  *
  * Show all persons whose birthday is today
  * @return Response
  *
  */
 public static function getTodaysBirthdays()
 {
     return Persons::select('persons.person_id', 'birthday', 'deceased', DB::raw('CONCAT(forename, " ", surname) as name'), 'image')->where(DB::raw('DATE_FORMAT(birthday,"%m-%d")'), DB::raw('DATE_FORMAT(NOW(),"%m-%d")'))->orderBy('forename', 'asc')->orderBy('surname', 'asc')->get();
 }