Vorschaubilder von Reiseprogrammen zuverlässig per Typ 2 laden.
Korrigiert das Doctrine-Mapping für travel_program_image.type und wählt in getPreviewImage() explizit das Box-/Suchbild statt eines beliebigen Bildes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9d22a5fdc9
commit
64dce95f20
2 changed files with 119 additions and 79 deletions
|
|
@ -142,7 +142,7 @@ class TravelProgram
|
|||
*/
|
||||
private $htmlDescription;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="payment_conditions", type="text", length=65535, nullable=true)
|
||||
|
|
@ -205,7 +205,7 @@ class TravelProgram
|
|||
*/
|
||||
private $travelAgenda;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="travel_company", type="integer", nullable=true)
|
||||
|
|
@ -317,7 +317,7 @@ class TravelProgram
|
|||
*/
|
||||
private $insurance2;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var \AppBundle\Entity\TravelInsurance
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelInsurance")
|
||||
|
|
@ -327,7 +327,7 @@ class TravelProgram
|
|||
*/
|
||||
private $insurance3;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @var \AppBundle\Entity\TravelInsurance
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\TravelInsurance")
|
||||
|
|
@ -395,6 +395,7 @@ class TravelProgram
|
|||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="AppBundle\Entity\TravelProgramImage", mappedBy="program")
|
||||
* @ORM\OrderBy({"id" = "ASC"})
|
||||
*/
|
||||
private $images;
|
||||
|
||||
|
|
@ -890,37 +891,37 @@ class TravelProgram
|
|||
{
|
||||
$lines = array();
|
||||
$count = 0;
|
||||
if($this->htmlDescription){
|
||||
if ($this->htmlDescription) {
|
||||
|
||||
$text = $this->htmlDescription;
|
||||
$regex = '#<h2>(.*?)</h2>#';
|
||||
preg_match_all($regex, $text, $matches);
|
||||
foreach ($matches[1] as $val){
|
||||
if(strpos($val, ':')){
|
||||
foreach ($matches[1] as $val) {
|
||||
if (strpos($val, ':')) {
|
||||
$v = explode(':', $val);
|
||||
$int = (int) filter_var($v[0], FILTER_SANITIZE_NUMBER_INT);
|
||||
if($int) {
|
||||
$lines[$int] = array('count'=> $count, 'day' => trim($v[1]), 'date' => $startDate->format('d.m.Y'));
|
||||
if ($int) {
|
||||
$lines[$int] = array('count' => $count, 'day' => trim($v[1]), 'date' => $startDate->format('d.m.Y'));
|
||||
$startDate->modify('+1 day');
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($this->classDescription){
|
||||
if ($this->classDescription) {
|
||||
$text = $this->classDescription;
|
||||
//standard //komfort
|
||||
$regex = "'<ul class=\"standard\">(.*?)</ul>'si";
|
||||
preg_match_all($regex, $text, $matches);
|
||||
if(isset($matches[1][0]) && strpos($matches[1][0], '</li>')){
|
||||
if (isset($matches[1][0]) && strpos($matches[1][0], '</li>')) {
|
||||
$text = $matches[1][0];
|
||||
$regex = '#<li>(.*?)</li>#';
|
||||
preg_match_all($regex, $text, $matches);
|
||||
foreach ($matches[1] as $val){
|
||||
if(strpos($val, ':')){
|
||||
foreach ($matches[1] as $val) {
|
||||
if (strpos($val, ':')) {
|
||||
$v = explode(':', $val);
|
||||
$int = (int) filter_var($v[0], FILTER_SANITIZE_NUMBER_INT);
|
||||
if($int && isset($lines[$int])) {
|
||||
if ($int && isset($lines[$int])) {
|
||||
$lines[$int]['night'] = trim($v[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1122,7 +1123,7 @@ class TravelProgram
|
|||
return $this->travelAgenda;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set travelCompany
|
||||
*
|
||||
* @param integer $travelCompany
|
||||
|
|
@ -1278,8 +1279,7 @@ class TravelProgram
|
|||
*/
|
||||
public function getIsAvailWeekday($weekday)
|
||||
{
|
||||
if ($this->weekdays == null)
|
||||
{
|
||||
if ($this->weekdays == null) {
|
||||
return false;
|
||||
}
|
||||
return in_array($weekday, explode(',', $this->weekdays));
|
||||
|
|
@ -1463,7 +1463,7 @@ class TravelProgram
|
|||
return $this->insurance2;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set insurance3
|
||||
*
|
||||
* @param \AppBundle\Entity\TravelInsurance $insurance2
|
||||
|
|
@ -1487,7 +1487,7 @@ class TravelProgram
|
|||
return $this->insurance3;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set insurance3
|
||||
*
|
||||
* @param \AppBundle\Entity\TravelInsurance $insurance2
|
||||
|
|
@ -1751,77 +1751,113 @@ class TravelProgram
|
|||
|
||||
private function assertTravelDateNotDefinedYet($key, $header = null)
|
||||
{
|
||||
if($header){
|
||||
if (isset($this->headerTravelDateByKey[$key]))
|
||||
{
|
||||
if ($header) {
|
||||
if (isset($this->headerTravelDateByKey[$key])) {
|
||||
return true; //throw new \Exception('Travel period with key '. $key .' already exists');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($this->travelDateByKey[$key]))
|
||||
{
|
||||
if (isset($this->travelDateByKey[$key])) {
|
||||
return true; //throw new \Exception('Travel period with key '. $key .' already exists');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addTravelDateFromNonSeasonTravelPeriod($key, TravelPeriod $travelPeriod,
|
||||
FlightPeriod $flightPeriod = null, $currencyFactor, $header = null)
|
||||
{
|
||||
public function addTravelDateFromNonSeasonTravelPeriod(
|
||||
$key,
|
||||
TravelPeriod $travelPeriod,
|
||||
FlightPeriod $flightPeriod = null,
|
||||
$currencyFactor,
|
||||
$header = null
|
||||
) {
|
||||
|
||||
$now = new \DateTime();
|
||||
|
||||
if($travelPeriod->getStartDate() <= $now){
|
||||
if ($travelPeriod->getStartDate() <= $now) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if($header){
|
||||
if(!$this->assertTravelDateNotDefinedYet($key, $header)){
|
||||
if ($header) {
|
||||
if (!$this->assertTravelDateNotDefinedYet($key, $header)) {
|
||||
|
||||
$this->headerTravelDateByKey[$key] = TravelDate::createForNonSeasonTravelPeriod($key, $travelPeriod, $flightPeriod, $currencyFactor);
|
||||
}
|
||||
return $this->headerTravelDateByKey[$key];;
|
||||
}
|
||||
|
||||
if(!$this->assertTravelDateNotDefinedYet($key)){
|
||||
if (!$this->assertTravelDateNotDefinedYet($key)) {
|
||||
$this->travelDateByKey[$key] = TravelDate::createForNonSeasonTravelPeriod($key, $travelPeriod, $flightPeriod, $currencyFactor);
|
||||
}
|
||||
return $this->travelDateByKey[$key];
|
||||
}
|
||||
|
||||
public function addTravelDateFromSeasonTravelPeriod($key, TravelPeriod $travelPeriod, $index, \DateTime $start,
|
||||
\DateTime $end = null, FlightPeriod $flightPeriod = null, $currencyFactor, $header = null)
|
||||
{
|
||||
public function addTravelDateFromSeasonTravelPeriod(
|
||||
$key,
|
||||
TravelPeriod $travelPeriod,
|
||||
$index,
|
||||
\DateTime $start,
|
||||
\DateTime $end = null,
|
||||
FlightPeriod $flightPeriod = null,
|
||||
$currencyFactor,
|
||||
$header = null
|
||||
) {
|
||||
|
||||
if($header){
|
||||
if(!$this->assertTravelDateNotDefinedYet($key, $header)){
|
||||
if ($header) {
|
||||
if (!$this->assertTravelDateNotDefinedYet($key, $header)) {
|
||||
$this->isHeaderTravelDateMapTainted = true;
|
||||
$this->headerTravelDateByKey[$key] = TravelDate::createForSeasonTravelPeriod($key, $travelPeriod, $index, $start,
|
||||
$end, $flightPeriod, $currencyFactor);
|
||||
$this->headerTravelDateByKey[$key] = TravelDate::createForSeasonTravelPeriod(
|
||||
$key,
|
||||
$travelPeriod,
|
||||
$index,
|
||||
$start,
|
||||
$end,
|
||||
$flightPeriod,
|
||||
$currencyFactor
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(!$this->assertTravelDateNotDefinedYet($key)){
|
||||
if (!$this->assertTravelDateNotDefinedYet($key)) {
|
||||
$this->isTravelDateMapTainted = true;
|
||||
$this->travelDateByKey[$key] = TravelDate::createForSeasonTravelPeriod($key, $travelPeriod, $index, $start,
|
||||
$end, $flightPeriod, $currencyFactor);
|
||||
$this->travelDateByKey[$key] = TravelDate::createForSeasonTravelPeriod(
|
||||
$key,
|
||||
$travelPeriod,
|
||||
$index,
|
||||
$start,
|
||||
$end,
|
||||
$flightPeriod,
|
||||
$currencyFactor
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function addTravelDate($key, TravelPeriod $travelPeriod, FlightPeriod $flightPeriod = null, $currencyFactor,
|
||||
\DateTime $start = null, \DateTime $end = null, $index = null)
|
||||
{
|
||||
if(!$this->assertTravelDateNotDefinedYet($key)){
|
||||
$this->isTravelDateMapTainted = true;
|
||||
$this->travelDateByKey[$key] = new TravelDate($key, $travelPeriod, $flightPeriod, $currencyFactor, $start, $end,
|
||||
$index);
|
||||
public function addTravelDate(
|
||||
$key,
|
||||
TravelPeriod $travelPeriod,
|
||||
FlightPeriod $flightPeriod = null,
|
||||
$currencyFactor,
|
||||
\DateTime $start = null,
|
||||
\DateTime $end = null,
|
||||
$index = null
|
||||
) {
|
||||
if (!$this->assertTravelDateNotDefinedYet($key)) {
|
||||
$this->isTravelDateMapTainted = true;
|
||||
$this->travelDateByKey[$key] = new TravelDate(
|
||||
$key,
|
||||
$travelPeriod,
|
||||
$flightPeriod,
|
||||
$currencyFactor,
|
||||
$start,
|
||||
$end,
|
||||
$index
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function hasTravelDate($key, $header = null)
|
||||
{
|
||||
if($header){
|
||||
if ($header) {
|
||||
return isset($this->headerTravelDateByKey[$key]);
|
||||
}
|
||||
return isset($this->travelDateByKey[$key]);
|
||||
|
|
@ -1829,7 +1865,7 @@ class TravelProgram
|
|||
|
||||
public function getTravelDate($key, $header = null)
|
||||
{
|
||||
if($header){
|
||||
if ($header) {
|
||||
return $this->headerTravelDateByKey[$key] ?? null;
|
||||
}
|
||||
return $this->travelDateByKey[$key] ?? null;
|
||||
|
|
@ -1840,17 +1876,15 @@ class TravelProgram
|
|||
*/
|
||||
public function getTravelDates($header = null)
|
||||
{
|
||||
if($header){
|
||||
if ($this->isHeaderTravelDateMapTainted)
|
||||
{
|
||||
if ($header) {
|
||||
if ($this->isHeaderTravelDateMapTainted) {
|
||||
ksort($this->headerTravelDateByKey);
|
||||
$this->isHeaderTravelDateMapTainted = false;
|
||||
}
|
||||
return $this->headerTravelDateByKey;
|
||||
}
|
||||
|
||||
if ($this->isTravelDateMapTainted)
|
||||
{
|
||||
if ($this->isTravelDateMapTainted) {
|
||||
ksort($this->travelDateByKey);
|
||||
$this->isTravelDateMapTainted = false;
|
||||
}
|
||||
|
|
@ -1859,9 +1893,8 @@ class TravelProgram
|
|||
|
||||
public function hasTravelDates($header = null)
|
||||
{
|
||||
if($header){
|
||||
if ($header) {
|
||||
return !empty($this->headerTravelDateByKey);
|
||||
|
||||
}
|
||||
return !empty($this->travelDateByKey);
|
||||
}
|
||||
|
|
@ -1875,14 +1908,12 @@ class TravelProgram
|
|||
public function getLowestPrice()
|
||||
{
|
||||
$lowestPrice = -1;
|
||||
foreach ($this->getTravelDates() as $travelDate)
|
||||
{
|
||||
if($travelDate->getStatus() == 0){
|
||||
foreach ($this->getTravelDates() as $travelDate) {
|
||||
if ($travelDate->getStatus() == 0) {
|
||||
continue;
|
||||
}
|
||||
$curLowestPrice = $travelDate->getLowestPrice();
|
||||
if ($lowestPrice < 0 || $curLowestPrice < $lowestPrice)
|
||||
{
|
||||
if ($lowestPrice < 0 || $curLowestPrice < $lowestPrice) {
|
||||
$lowestPrice = $curLowestPrice;
|
||||
}
|
||||
}
|
||||
|
|
@ -1925,14 +1956,23 @@ class TravelProgram
|
|||
|
||||
public function getPreviewImage()
|
||||
{
|
||||
foreach ($this->getImages() as $image)
|
||||
{
|
||||
if ($image->getType() == 2)
|
||||
{
|
||||
return $image;
|
||||
$images = $this->getImages();
|
||||
if ($images->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$previewImage = null;
|
||||
foreach ($images as $image) {
|
||||
if ((int) $image->getType() === 2) {
|
||||
$previewImage = $image;
|
||||
}
|
||||
}
|
||||
return $this->getImages()[0];
|
||||
|
||||
if ($previewImage !== null) {
|
||||
return $previewImage;
|
||||
}
|
||||
|
||||
return $images->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ class TravelProgramImage
|
|||
private $description;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @var int|null 1=Gallery, 2=Box/Suche, 3=Header, 4=Slider
|
||||
*
|
||||
* @ORM\Column(name="type", type="boolean", nullable=true)
|
||||
* @ORM\Column(name="type", type="smallint", nullable=true)
|
||||
*/
|
||||
private $type;
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ class TravelProgramImage
|
|||
/**
|
||||
* Set type
|
||||
*
|
||||
* @param boolean $type
|
||||
* @param int|null $type
|
||||
*
|
||||
* @return TravelProgramImage
|
||||
*/
|
||||
|
|
@ -158,7 +158,7 @@ class TravelProgramImage
|
|||
/**
|
||||
* Get type
|
||||
*
|
||||
* @return boolean
|
||||
* @return int|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue