Пример #1
0
 public function getMovies(Request $request)
 {
     date_default_timezone_set('Europe/Moscow');
     if ($request->input('city_id') == null) {
         $city = $request->user()->city_id;
     } else {
         $city = $request->input('city_id');
     }
     $cities = Cities::orderBy('city')->get();
     $cityList = [];
     foreach ($cities as $key => $value) {
         $cityList[$value->id] = $value->city;
     }
     $cinemas = Cinemas::where("city_id", $city)->orderBy("title")->get();
     $cinemasIds = array_pluck($cinemas, "id");
     $seances = \App\Seances::whereIn("cinema_id", $cinemasIds)->where("start_time", '>', date("Y-m-d H:i:s"))->groupBy("movie_id")->with('getMovie')->get();
     $movies = [];
     foreach ($seances as $item) {
         $movie = $item->getMovie->getAttributes();
         $poster = json_decode($item->getMovie->poster)->name;
         $movie['poster'] = $poster;
         //Helper::getPosterLink($poster);
         $movies[] = $movie;
     }
     return view()->make('search.movies_filter', array('movies' => $movies, 'cityList' => $cityList, 'city' => $city));
 }
Пример #2
0
 public static function store(array $seance)
 {
     $seance = array_only($seance, array('id', 'movieId', 'cinemaId', 'date', 'time', 'startTime'));
     $seance['movie_id'] = $seance['movieId'];
     unset($seance['movieId']);
     $seance['cinema_id'] = $seance['cinemaId'];
     unset($seance['cinemaId']);
     $seance['start_time'] = $seance['startTime'];
     unset($seance['startTime']);
     if (Seances::find($seance['id']) == null) {
         $seances = Seances::updateOrCreate($seance);
     }
     // $seances->save();
 }
 public function addToCalendar(Request $request, $dialog, $id)
 {
     $client = new Google_Client();
     $client->setScopes(SCOPES);
     $client->setAuthConfigFile(CLIENT_SECRET_PATH);
     //$client->setAccessType('offline');
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/google_calendar_callback');
     //  $credentialsPath = $this->expandHomeDirectory(CREDENTIALS_PATH);
     $request->session()->put('dialog', $dialog);
     $request->session()->put('seance', $id);
     // Request authorization from the user.
     if ($request->session()->get('access_token')) {
         $accessToken = $request->session()->get('access_token');
         $client->setAccessToken($accessToken);
         // Refresh the token if it's expired.
         if ($client->isAccessTokenExpired()) {
             $client->refreshToken(Session::find($request->session()->getId()));
         }
     } else {
         // Request authorization from the user.
         $authUrl = $client->createAuthUrl();
         return Response::make('', 302)->header('Location', filter_var($authUrl, FILTER_SANITIZE_URL));
     }
     $d = Messages::where('dialog_num', $dialog)->first();
     $user = User::where('id', $d->user_id_received == $request->user()->id ? $d->user_id_sent : $d->user_id_received)->first();
     $seance = Seances::where('id', $id)->with('getCinema')->with('getMovie')->first();
     $service = new Google_Service_Calendar($client);
     $start_date = new DateTime($seance->start_time);
     $start_date->sub(new DateInterval('PT3H'));
     $end_date = new DateTime($seance->start_time);
     $end_date->add(new DateInterval('PT' . $seance->getMovie->duration . 'M'));
     $end_date->sub(new DateInterval('PT3H'));
     $event = new Google_Service_Calendar_Event(array('summary' => 'Поход в кино', 'location' => Cities::find($seance->getCinema->city_id)->first()->city . ", " . $seance->getCinema->address, 'description' => $seance->getMovie->title, 'start' => array('dateTime' => $start_date->format('Y-m-d\\TH:i:sP'), 'timeZone' => 'Europe/Moscow'), 'end' => array('dateTime' => $end_date->format('Y-m-d\\TH:i:sP'), 'timeZone' => 'Europe/Moscow'), 'recurrence' => array('RRULE:FREQ=DAILY;COUNT=1'), 'attendees' => array(array('email' => $user->email)), 'reminders' => array('useDefault' => FALSE, 'overrides' => array(array('method' => 'email', 'minutes' => 24 * 60), array('method' => 'popup', 'minutes' => 10)))));
     $calendarId = 'primary';
     $event = $service->events->insert($calendarId, $event);
     return Response::make('', 302)->header('Location', filter_var($event->htmlLink, FILTER_SANITIZE_URL));
 }
Пример #4
0
 public static function getDynamicValues($type)
 {
     ini_set('memory_limit', '512M');
     ini_set("max_execution_time", "600");
     $file = public_path("upload/Tmp" . $type . ".json.gz");
     if ($type == "Cinemas") {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/cinemas.json.gz";
     } elseif ($type == "Seances") {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/seances/week.json.gz";
     } else {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/running/week.json.gz";
     }
     //dd($link);
     file_put_contents($file, fopen($link, 'r'));
     $fp = gzopen($file, "r");
     if ($fp != false) {
         $contents = gzread($fp, 134217720);
         $jsonArray = json_decode($contents, true);
         foreach ($jsonArray as $key => $value) {
             if ($type == "Cinemas") {
                 Cinemas::store($value);
             } elseif ($type == "Seances") {
                 Seances::store($value);
             } else {
                 Movies::store($value);
             }
         }
         gzclose($fp);
         unlink($file);
     } else {
         echo "404 not found";
     }
 }
Пример #5
0
 public function showSeanceInfo(Request $request, $dialog, $id)
 {
     $seance = Seances::where('id', $id)->with('getCinema')->with('getMovie')->first();
     return view()->make('user.seance_info', ['seance' => $seance]);
 }