<?php
namespace DestiSuiteBundle\Model\DataObject;
use Pimcore\Model\DataObject\Experience as ExperienceBase;
use Pimcore\Model\DataObject;
use DestiSuiteBundle\Model\Traits\WebsiteVisibilityTrait;
use DestiSuiteBundle\Model\Traits\SluggableTrait;
use DestiSuiteBundle\Model\Traits\PeriodTrait;
use DestiSuiteBundle\Repository\ExperienceRepository;
use DestiSuiteBundle\Services\Interfaces\CustomBookingServiceInterface;
class Experience extends ExperienceBase
{
use WebsiteVisibilityTrait, SluggableTrait, PeriodTrait;
const ORDERING_PRIORITY_HIGH = 10;
const ORDERING_PRIORITY_NORMAL = 0;
const ORDERING_PRIORITY_LOW = -10;
public static function getDs_bundle_type()
{
try {
$bundleType = \Pimcore::getContainer()->getParameter('ds_experience_bundle')['type'];
} catch (\Exception $ex) {
$bundleType = '';
}
return $bundleType;
}
public function hasBookingFunction()
{
try {
$booking = \Pimcore::getContainer()->getParameter('ds_experience_bundle')['booking'];
} catch (\Exception $ex) {
$booking = false;
}
if(self::getDs_bundle_type() == 'feratel' && !empty($this->getFid())) {
return true;
} elseif(self::getDs_bundle_type() == 'custom') {
// check if has booking feature in future
$bookingServiceName = \Pimcore::getContainer()->getParameter('ds_experience_bundle')['booking_service'];
if (!empty($bookingServiceName)) {
$service = \Pimcore::getContainer()->get($bookingServiceName);
if (!$service instanceof CustomBookingServiceInterface) {
throw new \Exception('ds_experience_bundle.booking_service does not implements DestiSuiteBundle\Services\Interfaces\CustomBookingServiceInterface');
}
return $service->hasBookingDates($this);
}
return $booking;
}
}
public function getMainCategory()
{
if (!empty($this->getCategories())) {
return $this->getCategories()[0];
}
return null;
}
public function getMainImage()
{
if (!empty($this->getOverwriteGallery())) {
$items = $this->getOverwriteGallery()->getItems();
if (!empty($items) && !empty($items[0]) && !empty($items[0]->getImage())) {
return $items[0]->getImage();
}
}
if (!empty($this->getGallery())) {
$items = $this->getGallery()->getItems();
if (!empty($items) && !empty($items[0]) && !empty($items[0]->getImage())) {
return $items[0]->getImage();
}
}
}
public function isVisible($multisiteOwner = null, $locale = null)
{
if(empty($this->isPublished())) {
return false;
}
if(empty($this->getTitle($locale))) {
return false;
}
if ($this->isExpired() && empty($this->getVisibleAfterExpiration())) {
return false;
}
if ( empty($this->isVisibleInWebsite($multisiteOwner)) ) {
return false;
}
return true;
}
public function isTopEvent()
{
if ($this->getOrderingPriority() == self::ORDERING_PRIORITY_HIGH) {
return true;
}
return false;
}
public function getMarkerData()
{
$list = array();
if (empty($this->getLocations())) {
return $list;
}
foreach ($this->getLocations() as $operator) {
if (!empty($operator->getPosition())) {
$list[] = array(
'lat' => $operator->getPosition()->getLatitude(),
'lng' => $operator->getPosition()->getLongitude(),
'id' => $this->getId(),
'url' => null,
);
}
}
/*
if (empty($list) && !empty($this->getMeetingPoint())) {
$list[] = array(
'lat' => $this->getMeetingPoint()->getLatitude(),
'lng' => $this->getMeetingPoint()->getLongitude(),
'id' => $this->getId(),
'url' => null,
);
}
*/
return $list;
}
public function getCorrelatedEvents($locale, $multisiteOwner)
{
$correlated = array();
if (!empty($this->getCorrelated())) {
foreach ($this->getCorrelated() as $correlatedEl) {
if($correlatedEl->isVisible($multisiteOwner)) {
$correlated[] = $correlatedEl;
}
}
}
// when nothing set, fetch by same category
if (empty($correlated) && !empty($this->getCategories())) {
$filters = array(
'categories' => $this->getCategories(),
'excludeIds' => array($this->getId()),
);
$correlated = ExperienceRepository::getNextEntities($locale, $multisiteOwner, $filters, 6);
}
return $correlated;
}
}