diff --git a/app/Http/Controllers/Repertoire.php b/app/Http/Controllers/Repertoire.php index 98dbf5d..038ef82 100644 --- a/app/Http/Controllers/Repertoire.php +++ b/app/Http/Controllers/Repertoire.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Paper\CinemaHelios; use App\Paper\CinemaMultikino; use DiDom\Document; use App\Paper\Paper; @@ -10,7 +11,7 @@ class Repertoire extends Controller { private $main; - private $icon = '/small/film.png'; + private $icon = 'film'; public function __construct() { @@ -22,7 +23,7 @@ class Repertoire extends Controller { $date = date('d/m/Y'); $repertuarText = $this->cinemacityRepertuar($date); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); return back(); } @@ -32,7 +33,7 @@ class Repertoire extends Controller $date = new \DateTime(); $date->modify('+1 day'); $repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y')); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); return back(); } @@ -58,51 +59,50 @@ class Repertoire extends Controller } - private function multikinoRepertuar($date) - { - - $text = ''; - $repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date)); - $text .= "Repertuar Multikino Gdańsk\n"; - $text .= $date . "\n\n"; - - foreach ($repertuar->results as $movie) { - $text .= $movie->title . "\n"; - $text .= $movie->print_version . "\n"; - - $hours = []; - foreach ($movie->seances as $seans) { - $hours[] = date('H:i', strtotime($seans->beginning_date)); - } - $text .= implode(', ', $hours) . "\n\n"; - } - - return $text; - } +// private function multikinoRepertuar($date) +// { +// +// $text = ''; +// $repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date)); +// $text .= "Repertuar Multikino Gdańsk\n"; +// $text .= $date . "\n\n"; +// +// foreach ($repertuar->results as $movie) { +// $text .= $movie->title . "\n"; +// $text .= $movie->print_version . "\n"; +// +// $hours = []; +// foreach ($movie->seances as $seans) { +// $hours[] = date('H:i', strtotime($seans->beginning_date)); +// } +// $text .= implode(', ', $hours) . "\n\n"; +// } +// +// return $text; +// } public function today_multikino() { $multikino = new CinemaMultikino(); - $repertuarText = $multikino->convertToPrint(date('Y-m-d'), 4); + $multikino->setCinemaId(4); + $multikino->setDay(date('Y-m-d')); + + $repertuarText = $multikino->convertToPrint(); $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } public function tomorrow_multikino() { - $date = new \DateTime(); - $date->modify('+1 day'); $multikino = new CinemaMultikino(); - $repertuarText = $multikino->convertToPrint($date->format('Y-m-d'), 4); + $multikino->setDay(date_create()->modify('+1 day')->format('Y-m-d')); + $multikino->setCinemaId(4); + + $repertuarText = $multikino->convertToPrint(); $this->main->sendPrint('', $repertuarText, $this->icon); return back(); - - -// $repertuarText = $this->multikinoRepertuar($date->format('Y-m-d')); -// $this->main->sendPrint('', $repertuarText); -// return back(); } @@ -112,7 +112,7 @@ class Repertoire extends Controller $date->modify('+1 day'); $repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y')); - $this->main->sendPrint('', $repertuarText, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } @@ -126,15 +126,28 @@ class Repertoire extends Controller public function today_helios() { - $this->main->sendPrint('', $this->helios(0, 2), $this->icon); - $this->main->sendPrint('', $this->helios(0, 49)); + + $helios = new CinemaHelios(); + $helios->setDay(0); + $helios->setCinemaId([2, 49]); + $helios->convertToPrint(); + + $repertuarText = $helios->convertToPrint(); + $this->main->sendPrint('', $repertuarText, $this->icon); + return back(); } public function tomorrow_helios() { - $this->main->sendPrint('', $this->helios(1, 2), $this->icon); - $this->main->sendPrint('', $this->helios(1, 49)); + $helios = new CinemaHelios(); + $helios->setDay(1); + $helios->setCinemaId([2, 49]); + $helios->convertToPrint(); + + $repertuarText = $helios->convertToPrint(); + $this->main->sendPrint('', $repertuarText, $this->icon); + return back(); } @@ -157,40 +170,6 @@ class Repertoire extends Controller $this->tomorrow_gdynskiecentrumfilmowe(); } - private function helios($day, $cinemaId) - { - $url = 'http://www.helios.pl/2,Gdansk/Repertuar/axRepertoire/?dzien=' . $day . '&kino=' . $cinemaId; - - - $data = json_decode(file_get_contents($url)); - $document = new Document(); - $data->html = str_replace(["\n", "\t"], '', $data->html); - $document->loadHtml($data->html); - - - $cinemas = [2 => 'Helios Alfa', 49 => 'Helios Metropolia']; - - $text = ''; - $text .= "Repertuar $cinemas[$cinemaId]\n"; - - $date = new \DateTime(); - $date->modify('+' . $day . ' day'); - - $text .= $date->format('d-m-Y') . "\n\n"; - - - foreach ($document->find('.seance') as $seans) { - $text .= trim($seans->find('.movie-title')[0]->text()) . "\n"; - $hours = []; - foreach ($seans->find('.time li') as $hour) { - $hours[] = $hour->text(); - } - $text .= implode(', ', array_unique($hours)) . "\n\n"; - } - - return $text; - } - private function gdynskieCentrumFilmowe($date) { diff --git a/app/Paper/CinemaHelios.php b/app/Paper/CinemaHelios.php new file mode 100644 index 0000000..a351c0c --- /dev/null +++ b/app/Paper/CinemaHelios.php @@ -0,0 +1,86 @@ + 'Helios Alfa', 49 => 'Helios Metropolia']; + + public function setCinemaId($cinemaId) + { + $this->cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + } + + function fetchRepertorire() + { + if (is_null($this->cinemaId) || is_null($this->day)) + throw new \Exception('Day or cinemaid not set.'); + + if (!is_array($this->cinemaId)) { + $this->cinemaId = (array)$this->cinemaId; + } + + $documents = []; + foreach ($this->cinemaId as $cinema) { + $url = 'http://www.helios.pl/2,Gdansk/Repertuar/axRepertoire/?dzien=' . $this->day . '&kino=' . $cinema; + $data = json_decode(file_get_contents($url)); + + $document = new Document(); + $data->html = str_replace(["\n", "\t"], '', $data->html); + $document->loadHtml($data->html); + $documents[] = $document; + } + return $documents; + } + + function parseRepertoire() + { + $documents = $this->fetchRepertorire(); + $cinemas = []; + foreach ($documents as $document) { + $movies = []; + foreach ($document->find('.seance') as $seans) { + $movie = []; + $movie['title'] = trim($seans->find('.movie-title')[0]->text()); + + $hours = []; + foreach ($seans->find('.time li') as $hour) { + $hours[] = $hour->text(); + } + $movie['hours'] = array_unique($hours); + $movies[] = $movie; + } + $cinemas[] = $movies; + } + return $cinemas; + } + + function convertToPrint() + { + $cinemas = $this->parseRepertoire(); + $text = ''; + foreach ($cinemas as $cinemaId => $filmy) { + $text .= "Repertuar " . $this->cinemas[$this->cinemaId[$cinemaId]] . "\n"; + $text .= date_create()->modify("+$this->day day")->format('d-m-Y') . "\n\n"; + + foreach ($filmy as $film) { + $text .= $film['title'] . "\n"; + $text .= implode(', ', array_unique($film['hours'])) . "\n\n"; + } + $text .= "\n"; + } + return $text; + } +} \ No newline at end of file diff --git a/app/Paper/CinemaMultikino.php b/app/Paper/CinemaMultikino.php index 89b30a4..c0f7167 100644 --- a/app/Paper/CinemaMultikino.php +++ b/app/Paper/CinemaMultikino.php @@ -8,35 +8,47 @@ use App\Paper\Interfaces\Cinema; class CinemaMultikino implements Cinema { + private $cinemaId; + private $day; - function fetchRepertorire($day, $cinemaId = null) + public function setCinemaId($cinemaId) { - $moviePath = 'https://multikino.pl/data/filmswithshowings/' . $cinemaId; + $this->cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + } + + function fetchRepertorire() + { + + if (is_null($this->cinemaId) || is_null($this->day)) + throw new \Exception('Day or cinemaid not set.'); + $moviePath = 'https://multikino.pl/data/filmswithshowings/' . $this->cinemaId; $movieContent = file_get_contents($moviePath); - print_r($movieContent); $movieJson = json_decode($movieContent, 0); return $movieJson; } - function parseRepertoire($day, $cinemaId = null) + function parseRepertoire() { - $movieJson = $this->fetchRepertorire($day, $cinemaId); + $movieJson = $this->fetchRepertorire(); -echo $day; -// print_r($movieJson); $filmy = []; foreach ($movieJson->films as $movie) { $film = []; $film['id'] = $movie->id; $film['title'] = $movie->title; $film['times'] = []; - $film['date'] = $day; + $film['date'] = $this->day; $film['runningtime'] = $movie->info_runningtime; $film['genres'] = []; $film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short); if ($movie->original_s_count > 0 && $movie->show_showings) { foreach ($movie->showings as $shoving) { - if ($shoving->date_time == $day) { + if ($shoving->date_time == $this->day) { foreach ($shoving->times as $time) { $film['times'][] = $time->time . " " . $time->screen_type; } @@ -53,28 +65,27 @@ echo $day; } } -// print_r($filmy); - die(); return $filmy; } - function convertToPrint($day, $cinemaId = null) + function convertToPrint() { - $filmy = $this->parseRepertoire($day, $cinemaId); + $filmy = $this->parseRepertoire(); $text = ''; $text .= "Repertuar Multikino Gdańsk\n"; - $text .= $day . "\n\n"; + $text .= $this->day . "\n\n"; foreach ($filmy as $movie) { - $text .= $movie['title']. "\n"; - $text .= '('.$movie['runningtime']. ")\n"; + $text .= $movie['title'] . "\n"; + $text .= '(' . $movie['runningtime'] . ")\n"; $text .= implode(', ', $movie['genres']) . "\n\n"; $text .= $movie['synopsis_short'] . "\n\n"; $text .= implode(', ', $movie['times']) . "\n"; $text .= "--------------------------------\n\n"; } + return $text; } } \ No newline at end of file diff --git a/app/Paper/Interfaces/Cinema.php b/app/Paper/Interfaces/Cinema.php index 7f22b1b..6f2893f 100644 --- a/app/Paper/Interfaces/Cinema.php +++ b/app/Paper/Interfaces/Cinema.php @@ -11,10 +11,14 @@ namespace App\Paper\Interfaces; */ interface Cinema { - function fetchRepertorire($day, $cinemaId = null); + function setCinemaId($cinemaId); - function parseRepertoire($day, $cinemaId = null); + function setDay($day); - function convertToPrint($day, $cinemaId = null); + function fetchRepertorire(); + + function parseRepertoire(); + + function convertToPrint(); } \ No newline at end of file