<?php
namespace AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
#[ORM\Table(name: 'booking_extra')]
#[ORM\Entity(repositoryClass: \AdminBundle\Repository\BookingExtraRepository::class)]
#[ORM\HasLifecycleCallbacks]
class BookingExtra
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
static $statusTypes = [
self::STATUS_ACTIVE => 'active',
self::STATUS_INACTIVE => 'inactive',
];
const BOOKING_EXTRA_FILE_FOLDER = 'upload/booking-extra/';
/**
* @var integer
*/
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
protected $id;
/**
* @var string
*/
#[ORM\Column(name: 'name', type: 'string', length: 255, nullable: false)]
protected $name;
/**
* @var string
*/
#[ORM\Column(name: 'short_name', type: 'string', length: 64, nullable: false)]
protected $shortName;
/**
* @var string
*/
#[ORM\Column(type: 'string', length: 64, nullable: true)]
protected $icon;
/**
* @var string
*/
#[ORM\Column(name: 'extras_details', type: 'text', nullable: true)]
protected $extraDetails;
/**
* @var string
*/
#[ORM\Column(name: 'image', type: 'string', length: 255, nullable: true)]
protected $image;
/**
* @var string
*/
#[ORM\Column(name: 'show_on_booking_form', type: 'boolean', nullable: true, options: ['default' => 1])]
protected $showOnBookingForm = true;
/**
* @var string
*/
#[ORM\Column(name: 'pre_checked', type: 'boolean', nullable: true, options: ['default' => 0])]
protected $preChecked = false;
/**
* @var integer
*/
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(name: 'priority', type: 'integer', nullable: true)]
protected $priority;
#[Assert\File(mimeTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])]
protected $imageFile;
/**
* @var integer
*/
#[ORM\Column(name: 'status', type: 'integer')]
protected $status;
/**
* @var float
*/
#[ORM\Column(name: 'charge', type: 'decimal', precision: 7, scale: 2, nullable: false)]
protected $charge;
#[ORM\OneToMany(targetEntity: \BookingBookingExtra::class, mappedBy: 'bookingExtra')]
protected $bookingBookingExtras;
/**
* @var \DateTime
*/
#[ORM\Column(name: 'updated', type: 'datetime', nullable: true)]
protected $updated;
public function __construct()
{
$this->bookingBookingExtras = new ArrayCollection();
$this->updated = new \DateTime();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getBookingBookingExtras()
{
return $this->bookingBookingExtras;
}
/**
* @param mixed $bookingBookingExtras
*/
public function setBookingBookingExtras($bookingBookingExtras)
{
$this->bookingBookingExtras = $bookingBookingExtras;
}
/**
* @return string
*/
public function getExtraDetails()
{
return $this->extraDetails;
}
/**
* @param string $extraDetails
*/
public function setExtraDetails($extraDetails)
{
$this->extraDetails = $extraDetails;
}
/**
* @return array
*/
public static function getStatusTypes()
{
return self::$statusTypes;
}
/**
* @return string
*/
public function getShortName()
{
return $this->shortName;
}
public function setShortName($shortName)
{
$this->shortName = $shortName;
}
/**
* @return string
*/
public function getIcon()
{
return $this->icon;
}
public function setIcon($icon)
{
$this->icon = $icon;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
public function setImage($image)
{
$this->image = $image;
}
/**
* @return int
*/
public function getStatus()
{
return $this->status;
}
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return float
*/
public function getCharge()
{
return $this->charge;
}
public function setCharge($charge)
{
$this->charge = $charge;
}
/**
* @param UploadedFile $picture
*/
public function setImageFile(UploadedFile $imageFile = null)
{
$this->imageFile = $imageFile;
}
public function getImageFile()
{
return $this->imageFile;
}
public function getImagePath()
{
if (!$this->image) {
return ;
}
return self::BOOKING_EXTRA_FILE_FOLDER . $this->image;
}
public function uploadImage()
{
if (null === $this->getImageFile()) {
return;
}
$this->removeImageFile();
$filename = sha1(uniqid(mt_rand(), true));
$this->image = $filename.'.'.$this->getImageFile()->guessExtension();
$this->getImageFile()->move(
self::BOOKING_EXTRA_FILE_FOLDER,
$this->image
);
$this->setImageFile(null);
}
public function removeImageFile()
{
if ($imageFile = $this->getImagePath()) {
@unlink($imageFile);
}
}
public function setUpdated($updated)
{
$this->updated = $updated;
}
public function getUpdated()
{
return $this->updated;
}
public function refreshUpdated()
{
$this->setUpdated(new \DateTime());
}
#[ORM\PreUpdate]
#[ORM\PrePersist]
public function lifecycleFileUpload()
{
$this->uploadImage();
}
#[ORM\PostRemove]
public function removeUpload()
{
$this->removeImageFile();
}
public function __toString()
{
return $this->getName() ? $this->getName() : 'n\a';
}
/**
* @return mixed
*/
public function getShowOnBookingForm()
{
return $this->showOnBookingForm;
}
/**
* @param mixed $showOnBookingForm
*/
public function setShowOnBookingForm($showOnBookingForm)
{
$this->showOnBookingForm = $showOnBookingForm;
}
/**
* @return string
*/
public function getPreChecked()
{
return $this->preChecked;
}
/**
* @param string $preChecked
*/
public function setPreChecked($preChecked)
{
$this->preChecked = $preChecked;
}
/**
* @return int
*/
public function getPriority()
{
return $this->priority;
}
/**
* @param int $priority
*/
public function setPriority($priority)
{
$this->priority = $priority;
}
}