add Last chance movies
This commit is contained in:
@@ -7,24 +7,30 @@ class EventCinema extends PhpObject
|
|||||||
private $asMovies;
|
private $asMovies;
|
||||||
|
|
||||||
//Remote
|
//Remote
|
||||||
const PROM_LINKS = array( 'https://www.eventcinemas.co.nz/Promotions/MemberMovieOfTheWeek#cinemas=502',
|
const EVENT_URL = 'https://www.eventcinemas.co.nz';
|
||||||
'https://www.eventcinemas.co.nz/Promotions/MembersMovieOfTheWeek#cinemas=502');
|
const CINEMA_ID = 502;
|
||||||
|
const PROM_LINKS = array( self::EVENT_URL.'/Promotions/MemberMovieOfTheWeek#cinemas='.self::CINEMA_ID,
|
||||||
|
self::EVENT_URL.'/Promotions/MembersMovieOfTheWeek#cinemas='.self::CINEMA_ID);
|
||||||
|
|
||||||
const PROM_LINK = 'https://www.eventcinemas.co.nz/Promotions/MemberMovieOfTheWeek#cinemas=502';
|
const LASTCHANCE_LINK = self::EVENT_URL.'/Promotions/LastChanceFilms#cinemas='.self::CINEMA_ID;
|
||||||
|
//https://www.eventcinemas.co.nz/Cinemas/GetSessions?cinemaIds=502&date=2017-07-04
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$this->loadMoviesFromDb();
|
$this->loadMoviesFromDb();
|
||||||
$this->addMovieOfTheWeek();
|
|
||||||
|
//Movie of the week is overwriting as it is cheaper than last chance films
|
||||||
|
$this->addNewMovies();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadMoviesFromDb()
|
private function loadMoviesFromDb()
|
||||||
{
|
{
|
||||||
if(!file_exists(self::DB)) $this->asMovies = array();
|
$this->asMovies = array();
|
||||||
else
|
if(file_exists(self::DB))
|
||||||
{
|
{
|
||||||
$sContent = file_get_contents(self::DB);
|
$sContent = file_get_contents(self::DB);
|
||||||
$this->asMovies = json_decode($sContent==''?'{}':$sContent, true);
|
if($sContent != '') $this->asMovies = json_decode($sContent, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,29 +75,103 @@ class EventCinema extends PhpObject
|
|||||||
return $sContent;
|
return $sContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addMovieOfTheWeek()
|
private function addNewMovies()
|
||||||
{
|
{
|
||||||
$asNewMovie = $this->getMovieOfTheWeek();
|
$aoMovies = array_merge($this->getLastChanceFilms(), $this->getMovieOfTheWeek());
|
||||||
$sTitle = $asNewMovie['title'];
|
foreach($aoMovies as $oMovie)
|
||||||
|
{
|
||||||
|
$asMovie = $oMovie->getMovieInfo();
|
||||||
|
$sTitle = $asMovie['title'];
|
||||||
|
|
||||||
//Merge with DB
|
//Merge with DB
|
||||||
if(!array_key_exists($sTitle, $this->asMovies))
|
if(!array_key_exists($sTitle, $this->asMovies))
|
||||||
{
|
{
|
||||||
$this->asMovies = array($sTitle=>$asNewMovie) + $this->asMovies;
|
$this->asMovies[$sTitle] = $asMovie;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//else $this->asMovies[$sTitle] = $asNewMovie;
|
|
||||||
|
|
||||||
$this->saveMovieToDb();
|
$this->saveMovieToDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMovieOfTheWeek()
|
private function getMovieOfTheWeek()
|
||||||
{
|
{
|
||||||
$sTitle = '';
|
|
||||||
$sDates = '';
|
|
||||||
$sWorkingLink = '';
|
|
||||||
|
|
||||||
//Tests all URLs
|
//Tests all URLs
|
||||||
foreach(self::PROM_LINKS as $sLink)
|
foreach(self::PROM_LINKS as $sLink)
|
||||||
|
{
|
||||||
|
$aoMovies = $this->getMovieListFromPage($sLink, 'Movie of the Week');
|
||||||
|
if(!empty($aoMovies)) break;
|
||||||
|
/*
|
||||||
|
$oMovie = new Movie();
|
||||||
|
$oXPath = $this->getXPath($sLink);
|
||||||
|
|
||||||
|
//Get header object
|
||||||
|
$oMovieSection = $oXPath->query('//*[@class="header-title"]//*[@class="featured-name arrow-top small"]');
|
||||||
|
if($oMovieSection->length > 0)
|
||||||
|
{
|
||||||
|
$oHeader = $oMovieSection->item(0)->childNodes;
|
||||||
|
$oMovie->setTitle($oHeader->item(3)->nodeValue);
|
||||||
|
$aoDetails = $oHeader->item(5)->childNodes;
|
||||||
|
$oMovie->setDates(mb_substr($aoDetails->item(1)->nodeValue, 6));
|
||||||
|
$oMovie->setLink($sLink);
|
||||||
|
$oMovie->setPromo('Movie of the Week');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aoMovies;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getLastChanceFilms()
|
||||||
|
{
|
||||||
|
return $this->getMovieListFromPage(self::LASTCHANCE_LINK, 'Last Chance');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getMovieListFromPage($sUrl, $sPromo='')
|
||||||
|
{
|
||||||
|
$aoMovies = array();
|
||||||
|
$oTimeZone = new DateTimeZone('Pacific/Auckland');
|
||||||
|
|
||||||
|
$oXPath = $this->getXPath($sUrl);
|
||||||
|
$oMoviesNodeList = $oXPath->query('//*[@class="movie-data"]');
|
||||||
|
if($oMoviesNodeList->length > 0)
|
||||||
|
{
|
||||||
|
$oMovieNode = $oMoviesNodeList->item(0);
|
||||||
|
$asMovies = json_decode($oMovieNode->getAttribute('data-movies'), true);
|
||||||
|
|
||||||
|
//Specific start/end fields
|
||||||
|
$oFrom = new DateTime(substr($oMovieNode->getAttribute('data-fromdate'), 0, 10), $oTimeZone);
|
||||||
|
$oTo = new DateTime(substr($oMovieNode->getAttribute('data-todate'), 0, 10), $oTimeZone);
|
||||||
|
|
||||||
|
//Avalaible dates (fallback)
|
||||||
|
$asDates = json_decode($oMovieNode->getAttribute('data-dates'), true);
|
||||||
|
foreach($asDates as $sDate)
|
||||||
|
{
|
||||||
|
$oDate = new DateTime($sDate, $oTimeZone);
|
||||||
|
if($oDate < $oFrom) $oFrom = $oDate;
|
||||||
|
if($oDate > $oTo) $oTo = $oDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sFrom = $oFrom->format("d/m");
|
||||||
|
$sTo = $oTo->format("d/m");
|
||||||
|
|
||||||
|
foreach ($asMovies as $asMovie)
|
||||||
|
{
|
||||||
|
$oMovie = new Movie($asMovie['Id']);
|
||||||
|
|
||||||
|
$oMovie->setTitle($asMovie['Name']);
|
||||||
|
$oMovie->setDates($sFrom.' - '.$sTo);
|
||||||
|
$oMovie->setLink(self::EVENT_URL.$asMovie['MovieUrl']);
|
||||||
|
$oMovie->setPromo($sPromo);
|
||||||
|
|
||||||
|
$aoMovies[] = $oMovie;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aoMovies;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getXPath($sLink)
|
||||||
{
|
{
|
||||||
//Get Event Cinema Page
|
//Get Event Cinema Page
|
||||||
$sContent = $this->getCurl($sLink);
|
$sContent = $this->getCurl($sLink);
|
||||||
@@ -101,19 +181,7 @@ class EventCinema extends PhpObject
|
|||||||
@$oDom->loadHTML($sContent);
|
@$oDom->loadHTML($sContent);
|
||||||
$oXPath = new DOMXPath($oDom);
|
$oXPath = new DOMXPath($oDom);
|
||||||
|
|
||||||
//Get header object
|
return $oXPath;
|
||||||
$oMovieSection = $oXPath->query('//*[@class="header-title"]//*[@class="featured-name arrow-top small"]');
|
|
||||||
if($oMovieSection->length > 0)
|
|
||||||
{
|
|
||||||
$oHeader = $oMovieSection->item(0)->childNodes;
|
|
||||||
$sTitle = $oHeader->item(3)->nodeValue;
|
|
||||||
$aoDetails = $oHeader->item(5)->childNodes;
|
|
||||||
$sDates = mb_substr($aoDetails->item(1)->nodeValue, 6);
|
|
||||||
$sWorkingLink = $sLink;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array('title'=>$sTitle, 'dates'=>$sDates, 'link'=>$sWorkingLink, 'date'=>date('r'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRss()
|
public function getRss()
|
||||||
@@ -131,14 +199,16 @@ class EventCinema extends PhpObject
|
|||||||
|
|
||||||
foreach($this->asMovies as $asMovie)
|
foreach($this->asMovies as $asMovie)
|
||||||
{
|
{
|
||||||
|
$sPromo = array_key_exists('promo', $asMovie)?$asMovie['promo']:'Movies';
|
||||||
|
|
||||||
$asItem = array();
|
$asItem = array();
|
||||||
$asItem['title'] = $asMovie['title'];
|
$asItem['title'] = $asMovie['title'];
|
||||||
$asItem['link'] = $asMovie['link'];
|
$asItem['link'] = $asMovie['link'];
|
||||||
$asItem['guid'] = $asMovie['title'];
|
$asItem['guid'] = $asMovie['title'];
|
||||||
$asItem['category'] = 'Movies';
|
$asItem['category'] = $sPromo;
|
||||||
$asItem['pub_date'] = $asMovie['date'];
|
$asItem['pub_date'] = $asMovie['date'];
|
||||||
$asItem['author'] = 'Event Cinema - Queen Street';
|
$asItem['author'] = 'Event Cinema - Queen Street';
|
||||||
$asItem['description'] = $asMovie['dates'].' '.date('Y');
|
$asItem['description'] = $sPromo.' - '.$asMovie['dates'];
|
||||||
|
|
||||||
$oFeed->addItem($asItem);
|
$oFeed->addItem($asItem);
|
||||||
}
|
}
|
||||||
|
|||||||
55
inc/movie.php
Normal file
55
inc/movie.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Movie extends PhpObject
|
||||||
|
{
|
||||||
|
private $iId;
|
||||||
|
private $sTitle;
|
||||||
|
private $sDates;
|
||||||
|
private $sLink;
|
||||||
|
private $sPromo;
|
||||||
|
|
||||||
|
public function __construct($iId=0)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->setId($iId);
|
||||||
|
$this->setTitle('');
|
||||||
|
$this->setDates('');
|
||||||
|
$this->setLink('');
|
||||||
|
$this->setPromo('');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($iId)
|
||||||
|
{
|
||||||
|
$this->iId = $iId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTitle($sTitle)
|
||||||
|
{
|
||||||
|
$this->sTitle = $sTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDates($sDates)
|
||||||
|
{
|
||||||
|
$this->sDates = $sDates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLink($sLink)
|
||||||
|
{
|
||||||
|
$this->sLink = $sLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPromo($sPromo)
|
||||||
|
{
|
||||||
|
$this->sPromo = $sPromo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMovieInfo()
|
||||||
|
{
|
||||||
|
return array( 'id'=>$this->iId,
|
||||||
|
'title'=>$this->sTitle,
|
||||||
|
'dates'=>$this->sDates,
|
||||||
|
'link'=>$this->sLink,
|
||||||
|
'promo'=>$this->sPromo,
|
||||||
|
'date'=>date('r'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ require_once '../objects/class_management.php';
|
|||||||
|
|
||||||
$oClassManagement = new ClassManagement('eventcinema');
|
$oClassManagement = new ClassManagement('eventcinema');
|
||||||
$oClassManagement->incClass('rss');
|
$oClassManagement->incClass('rss');
|
||||||
|
$oClassManagement->incClass('movie', true);
|
||||||
|
|
||||||
$oEventCinema = new EventCinema();
|
$oEventCinema = new EventCinema();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user