src/Entity/Banner/AbstractBannerBase.php line 233

Open in your IDE?
  1. <?php
  2. namespace Slivki\Entity\Banner;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use JsonSerializable;
  6. use Slivki\Entity\Category;
  7. use Slivki\Entity\City;
  8. use Slivki\Entity\Entity;
  9. use function array_map;
  10. abstract class AbstractBannerBase extends Entity implements JsonSerializable
  11. {
  12.     const TYPE NULL;
  13.     protected $typeID;
  14.     protected $title;
  15.     protected $URL;
  16.     protected $filePath;
  17.     protected $filePathMobile;
  18.     protected $substitutePath;
  19.     protected $active;
  20.     protected $javaScript;
  21.     protected $json;
  22.     protected $code;
  23.     protected $codeFilePath;
  24.     protected $position;
  25.     private ?string $pixelCode;
  26.     private ?string $pixelCodeMobile;
  27.     protected ?Collection $cities;
  28.     protected ?Collection $categories;
  29.     protected $cityID;
  30.     protected $cityIds;
  31.     public function __construct()
  32.     {
  33.         $this->cities = new ArrayCollection();
  34.         $this->categories = 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 getTitle() {
  43.         return $this->title;
  44.     }
  45.     public function getMailingURL() {
  46.         return $this->URL explode("?"$this->URL)[0] : '';
  47.     }
  48.     public function setTitle($title) {
  49.         $this->title $title;
  50.     }
  51.     public function getURL() {
  52.         return $this->URL;
  53.     }
  54.     public function setURL($URL) {
  55.         $this->URL $URL;
  56.     }
  57.     public function getFilePath() {
  58.         return $this->filePath;
  59.     }
  60.     public function setFilePath($filePath) {
  61.         $this->filePath $filePath;
  62.     }
  63.     public function getFilePathMobile() {
  64.         return $this->filePathMobile;
  65.     }
  66.     public function setFilePathMobile($filePathMobile) {
  67.         $this->filePathMobile $filePathMobile;
  68.     }
  69.     public function getSubstitutePath() {
  70.         return $this->substitutePath;
  71.     }
  72.     public function setSubstitutePath($substitutePath) {
  73.         $this->substitutePath $substitutePath;
  74.     }
  75.     public function isActive() {
  76.         return $this->active;
  77.     }
  78.     public function setActive($active) {
  79.         $this->active $active;
  80.     }
  81.     public function isJavaScript() {
  82.         return $this->javaScript;
  83.     }
  84.     public function setJavaScript($javaScript) {
  85.         $this->javaScript $javaScript;
  86.     }
  87.     public function isJson() {
  88.         return $this->json;
  89.     }
  90.     public function setJson($json) {
  91.         $this->json $json;
  92.     }
  93.     public function getCode() {
  94.         return $this->code;
  95.     }
  96.     public function setCode($code) {
  97.         $this->code $code;
  98.     }
  99.     public function getCodeFilePath() {
  100.         return $this->codeFilePath;
  101.     }
  102.     public function setCodeFilePath($codeFilePath) {
  103.         $this->codeFilePath $codeFilePath;
  104.     }
  105.     public function getPixelCode(): ?string
  106.     {
  107.         return $this->pixelCode;
  108.     }
  109.     public function setPixelCode(?string $pixelCode): void
  110.     {
  111.         $this->pixelCode $pixelCode;
  112.     }
  113.     public function getPixelCodeMobile(): ?string
  114.     {
  115.         return $this->pixelCodeMobile;
  116.     }
  117.     public function setPixelCodeMobile(?string $pixelCodeMobile): void
  118.     {
  119.         $this->pixelCodeMobile $pixelCodeMobile;
  120.     }
  121.     public function getCategories(): Collection
  122.     {
  123.         return $this->categories;
  124.     }
  125.     public function addCategory(Category $category): void
  126.     {
  127.         if (!$this->categories->contains($category)) {
  128.             $this->categories->add($category);
  129.         }
  130.     }
  131.     public function removeCategory($category): void
  132.     {
  133.         $this->categories->removeElement($category);
  134.     }
  135.     public function getCategoriesIds(): array
  136.     {
  137.         return array_map(static fn (Category $category) => $category->getID(), $this->getCategories()->toArray());
  138.     }
  139.     public function jsonSerialize(): array
  140.     {
  141.         return [
  142.             'ID' => $this->ID,
  143.             'title' => $this->title,
  144.             'url' => $this->URL,
  145.             'filePath' => $this->filePath,
  146.             'active' => $this->active,
  147.             'pixelCode' => $this->pixelCode,
  148.             'pixelCodeMobile' => $this->pixelCodeMobile,
  149.             'cityIds' => $this->getCityIds(),
  150.             'categoryIds' => $this->getCategoriesIds(),
  151.         ];
  152.     }
  153.     public function getPosition() {
  154.         return $this->position;
  155.     }
  156.     public function setPosition($position) {
  157.         $this->position $position;
  158.     }
  159.     public function editPosition(int $position): void
  160.     {
  161.         $this->position $position;
  162.     }
  163.     public function activate(): void
  164.     {
  165.         $this->active true;
  166.     }
  167.     public function deactivate(): void
  168.     {
  169.         $this->active false;
  170.     }
  171.     public function addCity(City $city): void
  172.     {
  173.         if (!$this->cities->contains($city)) {
  174.             $this->cities->add($city);
  175.         }
  176.     }
  177.     public function removeCities(): void
  178.     {
  179.         $this->cities->clear();
  180.     }
  181.     public function getCityIds(): array
  182.     {
  183.         return array_map(
  184.             function(City $city) {
  185.                 return $city->getID();
  186.             },
  187.             $this->cities->toArray()
  188.         );
  189.     }
  190. }