File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/figi/bu/classes/FigiEventController.php
<?php
class FigiEventController extends BaseController{
function __construct($event_entry,$router_base_url,$event_shows=null)
{
//d($event_entry);
$this->router_url = $router_base_url;
foreach($event_entry as $el => $val)
{
$this->$el = $val;
}
if(!isset($this->code) && isset($event_entry["@attributes"]))
{
$this->code = $event_entry["@attributes"]["code"];
}
if($event_shows) $this->setEventShows($event_shows);
else $this->setEventShow();
//d($this);
}
/*
* Set a show for a theatre item
*/
private function setEventShow()
{
//d($this->voorstellingen);
if( isset($this->voorstellingen) ){
//d($this->voorstellingen);
$this->show_select_tickets = true;
foreach((array) $this->voorstellingen as $voorstelling)
{
if(is_array($voorstelling[0])){
foreach($voorstelling as $subvoorstelling){
$date = strftime("%Y-%m-%d",strtotime($subvoorstelling["aanvang"]));
$hour_start = strftime("%H",strtotime($subvoorstelling["aanvang"]));
$this->event_shows[$date][] =
[
"id" => $subvoorstelling["@attributes"]["code"],
"start" => $subvoorstelling["aanvang"]//,
//"status"=> $subvoorstelling["status"],
//"end" => $voorstelling["einde"]
];
if($subvoorstelling["status"] == "niet reserveerbaar") $this->show_select_tickets = false;
}
}
else{
$date = strftime("%Y-%m-%d",strtotime($voorstelling["aanvang"]));
$hour_start = strftime("%H",strtotime($voorstelling["aanvang"]));
$this->event_shows[$date][] =
[
"id" => $voorstelling["@attributes"]["code"],
"start" => $voorstelling["aanvang"]//,
//"status"=> $voorstelling["status"]
//"end" => $voorstelling["einde"]
];
if($voorstelling["status"] == "niet reserveerbaar") $this->show_select_tickets = false;
}
}
}
}
public function visibleOnSite()
{
return $this->show_select_tickets == true ? true : false;
}
private function setEventShows($event_shows)
{
$this->event_shows = [];
$this->min_start_time = 24;
$this->max_end_time = 0;
if($event_shows["events"]["totalCount"] == 1){
$temp = array(0 => $event_shows["events"]["event"]);
$event_shows["events"]["event"] = $temp;
}
foreach($event_shows["events"]["event"] as $show){
$date = strftime("%Y-%m-%d",strtotime($show["aanvang"]));
$hour_start = strftime("%H",strtotime($show["aanvang"]));
//$hour_end = strftime("%H",strtotime($show["aanvang"]));
// first start time
if($hour_start < $this->min_start_time) $this->min_start_time = $hour_start;
// last end time
if($hour_start > $this->max_end_time) $this->max_end_time = $hour_start;
$this->event_shows[$date][] =
[
"id" => $show["voorstelling"],
"start" => $show["aanvang"],
"end" => $show["einde"],
"price" => $show["standaard_prijs"],
"available"=> $show["aantal_beschikbaar"]
];
}
}
/*
* Get-a-ticket events
*/
public function getImage()
{
return '<img alt="" class="lazyLoad" data-original="'. $this->image .'">';
// return '<img alt="" class="lazyLoad" data-original="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC">';//'. $this->image .'
}
public function getDuration()
{
return $this->duur." minuten";
}
public function html_cut($text, $max_length)
{
$tags = array();
$result = "";
$is_open = false;
$grab_open = false;
$is_close = false;
$in_double_quotes = false;
$in_single_quotes = false;
$tag = "";
$i = 0;
$stripped = 0;
$stripped_text = strip_tags($text);
while ($i < strlen($text) && $stripped < strlen($stripped_text) && $stripped < $max_length)
{
$symbol = $text{$i};
$result .= $symbol;
switch ($symbol)
{
case '<':
$is_open = true;
$grab_open = true;
break;
case '"':
if ($in_double_quotes)
$in_double_quotes = false;
else
$in_double_quotes = true;
break;
case "'":
if ($in_single_quotes)
$in_single_quotes = false;
else
$in_single_quotes = true;
break;
case '/':
if ($is_open && !$in_double_quotes && !$in_single_quotes)
{
$is_close = true;
$is_open = false;
$grab_open = false;
}
break;
case ' ':
if ($is_open)
$grab_open = false;
else
$stripped++;
break;
case '>':
if ($is_open)
{
$is_open = false;
$grab_open = false;
array_push($tags, $tag);
$tag = "";
}
else if ($is_close)
{
$is_close = false;
array_pop($tags);
$tag = "";
}
break;
default:
if ($grab_open || $is_close)
$tag .= $symbol;
if (!$is_open && !$is_close)
$stripped++;
}
$i++;
}
while ($tags)
$result .= "</".array_pop($tags).">";
return $result;
}
public function getIntroText($length=null)
{
// remove headers
//$text = preg_replace('/<(h1|h2|h3|h4)[^>]*>([\s\S]*?)<\/(h1|h2|h3|h4)[^>]*>/', '', $this->getDescLong());
return $this->html_cut($this->getDescLong(),$length=300);
/*
$text = trim(strip_tags($text));
$textlen = strlen($text);
if($textlen < $length && $length!=null) $return = $text;
else
{
$cropAfter = ($length != null) ? $length : 115;
$intro = substr(strip_tags($text), 0, $cropAfter);
$ls = strrpos($intro, ".")+1;
$return = substr($intro, 0, $ls);
$rest = substr(strip_tags($text), $ls, $textlen);
$this->setIntroSequal($rest);
}
return "<p>".$return."</p>";*/
}
private function setIntroSequal($text)
{
$this->intro_sequal = $text;
}
public function getIntroSequal()
{
return $this->intro_sequal;
}
public function getTextIntro()
{
return $this->omschrijving_kort;
}
/*
* Get XL masthead background Image
*/
public function getImpressionImage()
{
return '<img src="'. $this->images["image"] .'" alt="">';
}
public function getBackdropImg()
{
if(count($this->highres_images["highres"]) == 1) return '<div class="backdrop"><img src="'. $this->highres_images["highres"] .'" alt=""></div>';
else{
$html = '<div class="image-showcase">';
foreach($this->highres_images["highres"] as $img)
{
$html .= '<div class="case">';
$html .= '<div class="backdrop"><img src="'. $img .'" alt=""></div>';
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
}
public function getPosterImage()
{
return '<img src="'. $this->images["image"] .'" alt="">'; //$this->poster_img
}
public function getImageSrc()
{
return $this->image;
}
public function getShowImage($classname=null)
{
return '<img alt="" class="lazyLoad'. ($classname != null ? " ".$classname : "").'" data-original="'. $this->images["image"] .'">';
}
public function getArtist()
{
return $this->artiest;
}
public function getStartTime(){
return strftime("%H:%M uur",strtotime($this->aanvang));
}
public function getDateTime()
{
return strftime("%H:%M uur",strtotime($this->aanvang));
}
public function getLead()
{
return $this->titel;
}
public function getShowLink()
{
return $this->router_url ."/". $this->getCode() ."/". $this->validGATlink($this->getArtist().'-'.$this->getLead());
}
public function validGATlink($str){
$replace_chars = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ü'=>'u',
"?" => " ","!" => " ","(" => " ",")" => " "
);
$valid = strtr( $str, $replace_chars );
return strtolower(preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-]/",'-', trim($valid))));
}
public function getCode(){
return $this->code;
}
public function getDescLong()
{
$text = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $this->omschrijving_lang);
$text = preg_replace('/<h([1-6])(.*?)<\/h([1-6])>/si', '<p class="heading$1"$2</p>', $text);
return $text;
//return strip_tags($this->omschrijving_lang,'<p><br><ul><li><strong><a>');
}
public function getGenre(){
return $this->genre;
}
public function getShowPrice()
{
//d($this->speeldagen["speeldag"]);
$has_multiple = isset($this->speeldagen["speeldag"][0]) ? true : false;
// multiple days
if($has_multiple == true)
{
$playday = $this->speeldagen["speeldag"][0]["tijdstippen"];
// multiple shows on day
if(isset($playday["tijdstip"][0])) $price = $playday["tijdstip"][0]["standaard_prijs"];
else $price = $playday["tijdstip"]["standaard_prijs"];
}
// single day show
else{
$playday = $this->speeldagen["speeldag"]["tijdstippen"];
// show on a single day with multiple shows
if(isset($playday["tijdstip"][0])) $price = $playday["tijdstip"][0]["standaard_prijs"];
else $price = $playday["tijdstip"]["standaard_prijs"];
}
return "€ ".$price;
}
/*
* get theare ticket price
*/
public function getPrice()
{
return $this->standaard_prijs ? "€ ". $this->standaard_prijs : null;
}
public function getDate()
{
return $this->voorstellingen["voorstelling"]["aanvang"] ? strftime("%a %e %b %Y",strtotime($this->voorstellingen["voorstelling"]["aanvang"])) : null;
}
public function getTime()
{
if(!$this->voorstellingen["voorstelling"]["aanvang"]) return null;
else
{
$start = strtotime($this->voorstellingen["voorstelling"]["aanvang"]);
$end = isset($this->voorstellingen["voorstelling"]["einde"]) ? strftime("%H:%M",strtotime($this->voorstellingen["voorstelling"]["einde"])) : "";
return strftime("%H:%M", $start);// . ' - ' . $end;
}
}
public function getIcons(){
$icon_str = str_split($this->picture_rating);
$icons = "";
foreach($icon_str as $icon)
{
$icons .= '<img src="images/kijkwijzer/'.$icon.'.png" alt="" class="kw-icon">';
}
return $icons;
}
public function getEventDate()
{
if( isset($this->aanvang) ) return strftime("%e %B %Y",strtotime($this->aanvang));
}
public function getEventTime()
{
if($this->aanvang) return strftime("%H:%M",strtotime($this->aanvang));
}
public function getEventDateTime()
{
if($this->aanvang) return strftime("%a %e %B %Y - %H:%M",strtotime($this->aanvang));
}
public function getTimeStamp()
{
//echo $this->aanvang;
//echo strftime("%d-%m-%y",strtotime($this->aanvang))." ";
return strftime("%d-%m-%y",strtotime($this->aanvang));
}
public function getYoutubePreview(){
return $this->youtubes["tube"];
}
public function getDateIcon()
{
return '<div class="date-icon">
<i class="fal fa-calendar-alt"></i>
<span class="day">'. strftime("%a %e %B",strtotime($this->aanvang)) .'</span>
<i class="fal fa-clock"></i>
<span class="time">'. strftime("%H:%M uur",strtotime($this->aanvang)) .'</span>
</div>';
}
/*
* Get-a-ticket Categrories
*/
public function getCategoryId()
{
return $this->id;
}
public function getCategoryName()
{
return $this->descr;
}
public function hasRating()
{
return $this->picture_rating ? true : false;
}
}
?>