class PremiereReport {
private array $premieres;
public function __construct(array $premieres) {
$this->premieres = $premieres;
}
public function getPremieres(): array {
return $this->premieres;
}
public function getPremieresByYear(int $year): array {
return filterPremieresByYear($this->premieres, $year);
}
public function getPremieresByGenre(string $genreName): array {
return filterPremieresByGenre($this->premieres, $genreName);
}
public function getPremieresByCountry(string $countryName): array {
return filterPremieresByCountry($this->premieres, $countryName);
}
public function getPremieresByDate(string $startDate, string $endDate): array {
return filterPremieresByDate($this->premieres, $startDate, $endDate);
}
public function getUpcomingPremieres(int $days = 30): array {
$today = date('Y-m-d');
$futureDate = date('Y-m-d', strtotime("+{$days} days"));
return filterPremieresByDate($this->premieres, $today, $futureDate);
}
public function getRecentPremieres(int $days = 30): array {
$today = date('Y-m-d');
$pastDate = date('Y-m-d', strtotime("-{$days} days"));
return filterPremieresByDate($this->premieres, $pastDate, $today);
}
public function createDetailedReport(): string {
$report = "=== ОТЧЕТ ПО ПРЕМЬЕРАМ ===\n\n";
// Общая статистика
$report .= "📊 ОБЩАЯ СТАТИСТИКА:\n";
$report .= "Всего премьер: " . count($this->premieres) . "\n";
// Статистика по годам
$years = [];
foreach ($this->premieres as $premiere) {
$year = $premiere->year;
if (!isset($years[$year])) {
$years[$year] = 0;
}
$years[$year]++;
}
krsort($years);
$report .= "Премьер по годам:\n";
foreach ($years as $year => $count) {
$report .= "- {$year}: {$count} премьер\n";
}
$report .= "\n";
// Статистика по жанрам
$genres = [];
foreach ($this->premieres as $premiere) {
foreach ($premiere->genres as $genre) {
$genreName = $genre->genre;
if (!isset($genres[$genreName])) {
$genres[$genreName] = 0;
}
$genres[$genreName]++;
}
}
arsort($genres);
$report .= "Премьер по жанрам:\n";
foreach (array_slice($genres, 0, 10) as $genre => $count) {
$report .= "- {$genre}: {$count} премьер\n";
}
$report .= "\n";
// Статистика по странам
$countries = [];
foreach ($this->premieres as $premiere) {
foreach ($premiere->countries as $country) {
$countryName = $country->country;
if (!isset($countries[$countryName])) {
$countries[$countryName] = 0;
}
$countries[$countryName]++;
}
}
arsort($countries);
$report .= "Премьер по странам:\n";
foreach (array_slice($countries, 0, 10) as $country => $count) {
$report .= "- {$country}: {$count} премьер\n";
}
$report .= "\n";
// Ближайшие премьеры
$upcoming = $this->getUpcomingPremieres(30);
$report .= "🎬 БЛИЖАЙШИЕ ПРЕМЬЕРЫ (30 дней):\n";
foreach (array_slice($upcoming, 0, 10) as $premiere) {
$report .= "• {$premiere->getDisplayName()} ({$premiere->premiereRu})\n";
}
$report .= "\n";
// Все премьеры
$report .= "📋 ВСЕ ПРЕМЬЕРЫ:\n";
$sortedPremieres = sortPremieresByDate($this->premieres, true);
foreach ($sortedPremieres as $premiere) {
$report .= "\n• {$premiere->getDisplayName()}\n";
$report .= " ID: {$premiere->kinopoiskId}\n";
$report .= " Год: {$premiere->year}\n";
$report .= " Премьера: {$premiere->premiereRu}\n";
if ($premiere->duration) {
$report .= " Продолжительность: {$premiere->duration} мин.\n";
}
$countries = implode(', ', array_map('strval', $premiere->countries));
if ($countries) {
$report .= " Страны: {$countries}\n";
}
$genres = implode(', ', array_map('strval', $premiere->genres));
if ($genres) {
$report .= " Жанры: {$genres}\n";
}
}
return $report;
}
public function createHtmlReport(string $title): string {
$html = "<!DOCTYPE html>\n<html>\n<head>\n";
$html .= "<title>{$title}</title>\n";
$html .= "<style>\n";
$html .= ".report { max-width: 1200px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; }\n";
$html .= ".section { margin-bottom: 30px; }\n";
$html .= ".section-title { font-size: 20px; font-weight: bold; margin-bottom: 15px; padding: 10px; background-color: #f8f9fa; border-radius: 5px; }\n";
$html .= ".premiere-item { margin-bottom: 15px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }\n";
$html .= ".premiere-title { font-weight: bold; font-size: 18px; margin-bottom: 10px; }\n";
$html .= ".premiere-meta { font-size: 14px; color: #666; margin-bottom: 5px; }\n";
$html .= ".premiere-poster { width: 100px; height: 150px; object-fit: cover; border-radius: 5px; }\n";
$html .= ".stats { background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-bottom: 20px; }\n";
$html .= ".premiere-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 15px; }\n";
$html .= ".upcoming { border-left: 5px solid #28a745; }\n";
$html .= ".recent { border-left: 5px solid #007bff; }\n";
$html .= "</style>\n</head>\n<body>\n";
$html .= "<div class='report'>\n";
$html .= "<h1>{$title}</h1>\n";
// Статистика
$html .= "<div class='stats'>\n";
$html .= "<h2>Общая статистика</h2>\n";
$html .= "<p><strong>Всего премьер:</strong> " . count($this->premieres) . "</p>\n";
$html .= "</div>\n";
// Ближайшие премьеры
$upcoming = $this->getUpcomingPremieres(30);
$html .= "<div class='section'>\n";
$html .= "<div class='section-title'>🎬 Ближайшие премьеры (30 дней)</div>\n";
$html .= "<div class='premiere-grid'>\n";
foreach (array_slice($upcoming, 0, 12) as $premiere) {
$html .= "<div class='premiere-item upcoming'>\n";
$html .= "<img src='{$premiere->posterUrlPreview}' alt='{$premiere->getDisplayName()}' class='premiere-poster'>\n";
$html .= "<div class='premiere-title'>{$premiere->getDisplayName()}</div>\n";
$html .= "<div class='premiere-meta'>Год: {$premiere->year}</div>\n";
$html .= "<div class='premiere-meta'>Премьера: {$premiere->premiereRu}</div>\n";
if ($premiere->duration) {
$html .= "<div class='premiere-meta'>Продолжительность: {$premiere->duration} мин.</div>\n";
}
$countries = implode(', ', array_map('strval', $premiere->countries));
if ($countries) {
$html .= "<div class='premiere-meta'>Страны: {$countries}</div>\n";
}
$genres = implode(', ', array_map('strval', $premiere->genres));
if ($genres) {
$html .= "<div class='premiere-meta'>Жанры: {$genres}</div>\n";
}
$html .= "</div>\n";
}
$html .= "</div>\n</div>\n";
// Все премьеры
$html .= "<div class='section'>\n";
$html .= "<div class='section-title'>📋 Все премьеры</div>\n";
$html .= "<div class='premiere-grid'>\n";
$sortedPremieres = sortPremieresByDate($this->premieres, true);
foreach ($sortedPremieres as $premiere) {
$html .= "<div class='premiere-item'>\n";
$html .= "<img src='{$premiere->posterUrlPreview}' alt='{$premiere->getDisplayName()}' class='premiere-poster'>\n";
$html .= "<div class='premiere-title'>{$premiere->getDisplayName()}</div>\n";
$html .= "<div class='premiere-meta'>ID: {$premiere->kinopoiskId}</div>\n";
$html .= "<div class='premiere-meta'>Год: {$premiere->year}</div>\n";
$html .= "<div class='premiere-meta'>Премьера: {$premiere->premiereRu}</div>\n";
if ($premiere->duration) {
$html .= "<div class='premiere-meta'>Продолжительность: {$premiere->duration} мин.</div>\n";
}
$countries = implode(', ', array_map('strval', $premiere->countries));
if ($countries) {
$html .= "<div class='premiere-meta'>Страны: {$countries}</div>\n";
}
$genres = implode(', ', array_map('strval', $premiere->genres));
if ($genres) {
$html .= "<div class='premiere-meta'>Жанры: {$genres}</div>\n";
}
$html .= "</div>\n";
}
$html .= "</div>\n</div>\n</div>\n</body>\n</html>";
return $html;
}
}
// Использование
$premieres = $filmService->getPremieres();
$report = new PremiereReport($premieres);
// Создание текстового отчета
$textReport = $report->createDetailedReport();
echo $textReport;
// Создание HTML отчета
$htmlReport = $report->createHtmlReport('Отчет по премьерам');
file_put_contents('premieres_report.html', $htmlReport);
echo "\n✅ HTML отчет сохранен в premieres_report.html\n";