src/Entity/EntityDescription.php line 13

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: adv
  5.  * Date: 15.12.15
  6.  * Time: 23:33
  7.  */
  8. namespace Slivki\Entity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. class EntityDescription extends Entity implements \JsonSerializable {
  11.     const TYPE 0;
  12.     const TYPE_OFFER_CONDITIONS_ID 1;
  13.     const TYPE_OFFER_FEATURES_ID 2;
  14.     const TYPE_OFFER_LOCATION_ID 3;
  15.     const TYPE_OFFER_DESCRIPTION_ID 4;
  16.     const TYPE_OFFER_LOGO_ID 6;
  17.     const TYPE_OFFER_LEGAL_ID 7;
  18.     const TYPE_OFFER_WORKING_HOURS_ID 8;
  19.     const TYPE_SALE_DESCRIPTION_ID 9;
  20.     const TYPE_SALE_FANCY_DESCRIPTION_ID 10;
  21.     const TYPE_FOOD_ORDER_DESCRIPTION_ID 11;
  22.     public const TYPE_VENDOR_CONDITION 12;
  23.     public const TYPE_BRIEF_DELIVERY_CONDITION 13;
  24.     protected $typeID;
  25.     protected $entityID;
  26.     protected $description;
  27.     protected $offer;
  28.     protected $entityDescriptionSliderImages;
  29.     protected $sortOrder;
  30.     public function __construct() {
  31.         if (!defined('static::TYPE')) {
  32.             throw new \Exception('Constant TYPE is not defined in ' get_class($this));
  33.         }
  34.         $this->entityDescriptionSliderImages = new ArrayCollection();
  35.     }
  36.     public function getTypeID() {
  37.         return $this->typeID;
  38.     }
  39.     public function setTypeID($typeID) {
  40.         $this->typeID $typeID;
  41.     }
  42.     public function getEntityID() {
  43.         return $this->entityID;
  44.     }
  45.     public function setEntityID($entityID) {
  46.         $this->entityID $entityID;
  47.     }
  48.     public function getDescription() {
  49.         return $this->description;
  50.     }
  51.     public function setDescription($description) {
  52.         $this->description $description;
  53.     }
  54.     public function getSortOrder() {
  55.         return $this->sortOrder;
  56.     }
  57.     public function setSortOrder($sortOrder) {
  58.         $this->sortOrder $sortOrder;
  59.     }
  60.     /**
  61.      * @return \Slivki\Entity\Offer
  62.      */
  63.     public function getOffer() {
  64.         return $this->offer;
  65.     }
  66.     public function setOffer(Offer $offer) {
  67.         $this->offer $offer;
  68.         $this->entityID $offer->getID();
  69.     }
  70.     public function getEntityDescriptionSliderImages() {
  71.         return $this->entityDescriptionSliderImages;
  72.     }
  73.     public function addEntityDescriptionSliderImage(EntityDescriptionSliderImage $entityDescriptionSliderImage) {
  74.         if (!$this->entityDescriptionSliderImages->contains($entityDescriptionSliderImage)) {
  75.             $this->entityDescriptionSliderImages->add($entityDescriptionSliderImage);
  76.         }
  77.     }
  78.     public function getType() {
  79.         return static::TYPE;
  80.     }
  81.     public function jsonSerialize(): array
  82.     {
  83.         return [
  84.             'ID' => $this->ID,
  85.             'sortOrder' => $this->sortOrder,
  86.             'typeID' => $this->typeID,
  87.             'description' => $this->description,
  88.             'entityDescriptionSliderImages' => $this->entityDescriptionSliderImages->toArray()
  89.         ];
  90.     }
  91.     public static function fromJSON($data) {
  92.         $class = static::class;
  93.         $description = new $class();
  94.         $description->setDescription($data->description);
  95.         $description->setTypeID($data->typeID);
  96.         $description->setID($data->ID);
  97.         $description->setSortOrder($data->sortOrder);
  98.         foreach ($data->entityDescriptionSliderImages as $sliderImage) {
  99.             $description->addEntityDescriptionSliderImage(EntityDescriptionSliderImage::fromJSON($sliderImage));
  100.         }
  101.         return $description;
  102.     }
  103.     public static function getDescriptionClass($type) {
  104.         $classes = ['EntityDescription''SaleDescription''SaleFancyDescription''SaleLoadMoreBtnDescription''SaleLoadMoreBtnDescription'];
  105.         if (!isset($classes[$type])) {
  106.             throw new \Exception('Class not found. ' $type);
  107.         }
  108.         return "Slivki\Entity\\" $classes[$type];
  109.     }
  110. }