91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Paper;
|
|
|
|
|
|
use App\Paper\Interfaces\Cinema;
|
|
|
|
class CinemaMultikino implements Cinema
|
|
{
|
|
|
|
private $cinemaId;
|
|
private $day;
|
|
|
|
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.');
|
|
$moviePath = 'https://multikino.pl/data/filmswithshowings/' . $this->cinemaId;
|
|
$movieContent = file_get_contents($moviePath);
|
|
$movieJson = json_decode($movieContent, 0);
|
|
return $movieJson;
|
|
}
|
|
|
|
function parseRepertoire()
|
|
{
|
|
$movieJson = $this->fetchRepertorire();
|
|
|
|
$filmy = [];
|
|
foreach ($movieJson->films as $movie) {
|
|
$film = [];
|
|
$film['id'] = $movie->id;
|
|
$film['title'] = $movie->title;
|
|
$film['times'] = [];
|
|
$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 == $this->day) {
|
|
foreach ($shoving->times as $time) {
|
|
$film['times'][] = $time->time . " " . $time->screen_type;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($movie->genres->names as $genre) {
|
|
$film['genres'][] = $genre->name;
|
|
}
|
|
|
|
if (count($film['times'])) {
|
|
$filmy[] = $film;
|
|
}
|
|
}
|
|
|
|
return $filmy;
|
|
}
|
|
|
|
function convertToPrint()
|
|
{
|
|
$filmy = $this->parseRepertoire();
|
|
|
|
$text = '';
|
|
$text .= "Repertuar Multikino Gdańsk\n";
|
|
$text .= $this->day . "\n\n";
|
|
|
|
foreach ($filmy as $movie) {
|
|
$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;
|
|
}
|
|
} |