modules/QSL/Make/src/Model/Level4.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace QSL\Make\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use QSL\Make\API\Endpoint\Level4\DTO\Level4Input as Input;
  10. use QSL\Make\API\Endpoint\Level4\DTO\Level4Output as Output;
  11. /**
  12.  * @ORM\Entity (repositoryClass="\QSL\Make\Model\Repo\Level4")
  13.  * @ORM\Table  (name="level4",
  14.  *      indexes={
  15.  *          @ORM\Index (name="enabled", columns={"enabled"}),
  16.  *          @ORM\Index (name="level3", columns={"level3_id"}),
  17.  *          @ORM\Index (name="showOnFrontPage", columns={"showOnFrontPage"})
  18.  *      }
  19.  * )
  20.  * @ApiPlatform\ApiResource(
  21.  *     shortName="Make/Model/Year - Level4",
  22.  *     input=Input::class,
  23.  *     output=Output::class,
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/qsl/make/level4/{id}.{_format}",
  28.  *              "identifiers"={"id"},
  29.  *              "requirements"={"id"="\d+"}
  30.  *          },
  31.  *          "put"={
  32.  *              "method"="PUT",
  33.  *              "path"="/qsl/make/level4/{id}.{_format}",
  34.  *              "identifiers"={"id"},
  35.  *              "requirements"={"id"="\d+"}
  36.  *          },
  37.  *          "delete"={
  38.  *              "method"="DELETE",
  39.  *              "path"="/qsl/make/level4/{id}.{_format}",
  40.  *              "identifiers"={"id"},
  41.  *              "requirements"={"id"="\d+"}
  42.  *          }
  43.  *     },
  44.  *     collectionOperations={
  45.  *          "get"={
  46.  *              "method"="GET",
  47.  *              "path"="/qsl/make/level4.{_format}",
  48.  *              "identifiers"={}
  49.  *          },
  50.  *          "post"={
  51.  *              "method"="POST",
  52.  *              "path"="/qsl/make/level4.{_format}",
  53.  *              "identifiers"={},
  54.  *              "controller"="xcart.api.qsl.make.level4.controller"
  55.  *          }
  56.  *     },
  57.  *     attributes={
  58.  *         "pagination_items_per_page" = 100
  59.  *     }
  60.  * )
  61.  */
  62. class Level4 extends ALevel
  63. {
  64.     /**
  65.      * Level3
  66.      *
  67.      * @var \QSL\Make\Model\Level3
  68.      *
  69.      * @ORM\ManyToOne (targetEntity="QSL\Make\Model\Level3", inversedBy="level4", cascade={"merge","detach"})
  70.      * @ORM\JoinColumn (name="level3_id", referencedColumnName="id", onDelete="CASCADE")
  71.      */
  72.     protected $level3;
  73.     /**
  74.      * Relation to a ModelProduct entities
  75.      *
  76.      * @var \Doctrine\Common\Collections\ArrayCollection
  77.      *
  78.      * @ORM\OneToMany (targetEntity="QSL\Make\Model\Level4Product", mappedBy="level", cascade={"all"})
  79.      * @ORM\OrderBy   ({"position" = "ASC"})
  80.      */
  81.     protected $level4Product;
  82.     /**
  83.      * One-to-one relation with image
  84.      *
  85.      * @var \QSL\Make\Model\Image\Level4
  86.      *
  87.      * @ORM\OneToMany (targetEntity="QSL\Make\Model\Image\Level4", mappedBy="level", cascade={"all"})
  88.      */
  89.     protected $images;
  90.     /**
  91.      * @var \QSL\Make\Model\Image\Level4Logo
  92.      *
  93.      * @ORM\OneToOne  (targetEntity="QSL\Make\Model\Image\Level4Logo", mappedBy="level", cascade={"all"})
  94.      */
  95.     protected $logo;
  96.     /**
  97.      * Clean URLs
  98.      *
  99.      * @var \Doctrine\Common\Collections\ArrayCollection
  100.      *
  101.      * @ORM\OneToMany (targetEntity="XLite\Model\CleanURL", mappedBy="level4", cascade={"all"})
  102.      * @ORM\OrderBy   ({"id" = "ASC"})
  103.      */
  104.     protected $cleanURLs;
  105.     /**
  106.      * @var \Doctrine\Common\Collections\Collection
  107.      *
  108.      * @ORM\OneToMany (targetEntity="QSL\Make\Model\Level4Translation", mappedBy="owner", cascade={"all"})
  109.      */
  110.     protected $translations;
  111.     /**
  112.      * @return \Doctrine\Common\Collections\ArrayCollection
  113.      */
  114.     public function getCleanURLs()
  115.     {
  116.         return $this->cleanURLs;
  117.     }
  118.     /**
  119.      * @@param \Doctrine\Common\Collections\ArrayCollection
  120.      */
  121.     public function setCleanURLs($value)
  122.     {
  123.         $this->cleanURLs $value;
  124.     }
  125.     /**
  126.      * Add cleanURL
  127.      *
  128.      * @param \XLite\Model\CleanURL $cleanURL
  129.      */
  130.     public function addCleanURLs(\XLite\Model\CleanURL $cleanURL)
  131.     {
  132.         $this->cleanURLs[] = $cleanURL;
  133.     }
  134.     /**
  135.      * @param $value
  136.      *
  137.      * @return $this
  138.      */
  139.     public function setImages($value)
  140.     {
  141.         $this->images $value;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return Image\Level4
  146.      */
  147.     public function getImages()
  148.     {
  149.         return $this->images;
  150.     }
  151.     /**
  152.      * @return \QSL\Make\Model\Image\Level4Logo
  153.      */
  154.     public function getLogo()
  155.     {
  156.         return $this->logo;
  157.     }
  158.     /**
  159.      * @param \QSL\Make\Model\Image\Level4Logo $value
  160.      */
  161.     public function setLogo($value)
  162.     {
  163.         $this->logo $value;
  164.     }
  165.     /**
  166.      * @return string
  167.      */
  168.     public function getCustomerTitle()
  169.     {
  170.         return $this->getTitle() ?: $this->getLevel3()->getCustomerTitle();
  171.     }
  172.     /**
  173.      * @return string
  174.      */
  175.     public function getCustomerValue()
  176.     {
  177.         return $this->getLevel3()->getCustomerValue() . ' ' $this->getValue();
  178.     }
  179.     /**
  180.      * @return string
  181.      */
  182.     public function getDisplayDescription()
  183.     {
  184.         return $this->getDescription() ?: $this->getLevel3()->getDisplayDescription();
  185.     }
  186.     /**
  187.      * @return Image\Level4
  188.      */
  189.     public function getCustomerImage()
  190.     {
  191.         return $this->getImages()->count() ? $this->getImages() : $this->getLevel3()->getCustomerImage();
  192.     }
  193.     /**
  194.      * @return mixed
  195.      */
  196.     public function getLevel3()
  197.     {
  198.         return $this->level3;
  199.     }
  200.     /**
  201.      * @param mixed $value
  202.      *
  203.      * @return \QSL\Make\Model\Level4
  204.      */
  205.     public function setLevel3($value)
  206.     {
  207.         $this->level3 $value;
  208.         return $this;
  209.     }
  210.     /**
  211.      * @return mixed
  212.      */
  213.     public function getLevel4Product()
  214.     {
  215.         return $this->level4Product;
  216.     }
  217.     /**
  218.      * @param mixed $value
  219.      *
  220.      * @return \QSL\Make\Model\Level4
  221.      */
  222.     public function addLevel4Product($value)
  223.     {
  224.         $this->level4Product[] = $value;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @param mixed $value
  229.      *
  230.      * @return \QSL\Make\Model\Level4
  231.      */
  232.     public function setLevelProduct($value)
  233.     {
  234.         return $this->addLevel4Product($value);
  235.     }
  236.     /**
  237.      * @return string
  238.      */
  239.     public function getLevelName($delimiter ' ')
  240.     {
  241.         return $this->getLevel3()->getLevelName($delimiter) . $delimiter $this->getValue();
  242.     }
  243.     public function getPathData(): array
  244.     {
  245.         $result $this->getLevel3()->getPathData();
  246.         $result[] = ['id' => $this->getId(), 'name' => $this->getValue()];
  247.         return $result;
  248.     }
  249.     /**
  250.      * @return array
  251.      */
  252.     public function getLevelSelectors()
  253.     {
  254.         return array_merge(
  255.             $this->getLevel3()->getLevelSelectors(),
  256.             [
  257.                 \XLite\Core\Config::getInstance()->QSL->Make->level4name => [
  258.                     'id'    => $this->getId(),
  259.                     'value' => $this->getValue(),
  260.                 ],
  261.             ]
  262.         );
  263.     }
  264.     /**
  265.      * Constructor
  266.      *
  267.      * @param array $data Entity properties OPTIONAL
  268.      */
  269.     public function __construct(array $data = [])
  270.     {
  271.         $this->level4Product = new \Doctrine\Common\Collections\ArrayCollection();
  272.         $this->cleanURLs     = new \Doctrine\Common\Collections\ArrayCollection();
  273.         parent::__construct($data);
  274.     }
  275.     /**
  276.      * @return integer
  277.      */
  278.     public function getProductsCount()
  279.     {
  280.         return \XLite\Core\Database::getRepo('QSL\Make\Model\Level4Product')
  281.             ->search(new \XLite\Core\CommonCell(['level' => $this]), \XLite\Model\Repo\ARepo::SEARCH_MODE_COUNT);
  282.     }
  283.     /**
  284.      * @return array
  285.      */
  286.     public function getProducts()
  287.     {
  288.         return array_map(
  289.             static function ($modelProduct) {
  290.                 return $modelProduct->getProduct();
  291.             },
  292.             $this->getLevel4Product()->toArray()
  293.         );
  294.     }
  295.     /**
  296.      * @param integer $productId
  297.      *
  298.      * @return boolean
  299.      */
  300.     public function hasProduct($productId)
  301.     {
  302.         return in_array(
  303.             $productId,
  304.             array_map(
  305.                 static function ($product) {
  306.                     return $product->getProductId();
  307.                 },
  308.                 $this->getProducts()
  309.             )
  310.         );
  311.     }
  312.     /**
  313.      * @return string
  314.      */
  315.     public function getLevelPath()
  316.     {
  317.         return $this->getLevel3()->getLevelPath() . '-' $this->getValue();
  318.     }
  319.     /**
  320.      * @return string
  321.      */
  322.     public function getUrl()
  323.     {
  324.         return LC_USE_CLEAN_URLS
  325.             $this->getCleanURL()
  326.             : \XLite\Core\Converter::buildURL('level_front_page''', ['id' => $this->getId()]);
  327.     }
  328.     /**
  329.      * @return \QSL\Make\Model\Level3
  330.      */
  331.     public function getParentLevel()
  332.     {
  333.         return $this->getLevel3();
  334.     }
  335.     public function getDepth(): int
  336.     {
  337.         return 4;
  338.     }
  339. }