classes/XLite/Model/Product/GlobalTab.php line 15

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 XLite\Model\Product;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * The "tab" model class
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="global_product_tabs",
  13.  *      uniqueConstraints={
  14.  *          @ORM\UniqueConstraint (name="service_name", columns={"service_name"})
  15.  *      }
  16.  * )
  17.  */
  18. class GlobalTab extends \XLite\Model\AEntity implements \XLite\Model\Product\IProductTab\XLite\Model\Base\IModuleRelatedEntity
  19. {
  20.     public const TYPE_WIDGET 'widget';
  21.     public const TYPE_LIST 'list';
  22.     public const TYPE_TEMPLATE 'template';
  23.     /**
  24.      * Tab unique ID
  25.      *
  26.      * @var integer
  27.      *
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue (strategy="AUTO")
  30.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  31.      */
  32.     protected $id;
  33.     /**
  34.      * Tab position
  35.      *
  36.      * @var integer
  37.      *
  38.      * @ORM\Column (type="integer")
  39.      */
  40.     protected $position 0;
  41.     /**
  42.      * Tab name
  43.      *
  44.      * @var string
  45.      *
  46.      * @ORM\Column (type="string", nullable=true)
  47.      */
  48.     protected $service_name;
  49.     /**
  50.      * Tab provider(module namespace or core)
  51.      *
  52.      * @var \XLite\Model\Product\GlobalTabProvider[]
  53.      *
  54.      * @ORM\OneToMany (targetEntity="XLite\Model\Product\GlobalTabProvider", mappedBy="tab", cascade={"all"})
  55.      */
  56.     protected $providers;
  57.     /**
  58.      * @ORM\Column(type="string", nullable=true)
  59.      */
  60.     protected ?string $module null;
  61.     /**
  62.      * Constructor
  63.      *
  64.      * @param array $data Entity properties OPTIONAL
  65.      */
  66.     public function __construct(array $data = [])
  67.     {
  68.         $this->providers = new \Doctrine\Common\Collections\ArrayCollection();
  69.         parent::__construct($data);
  70.     }
  71.     /**
  72.      * Get id
  73.      *
  74.      * @return integer
  75.      */
  76.     public function getId()
  77.     {
  78.         return $this->id;
  79.     }
  80.     /**
  81.      * Return Position
  82.      *
  83.      * @return int
  84.      */
  85.     public function getPosition()
  86.     {
  87.         return $this->position;
  88.     }
  89.     /**
  90.      * Set Position
  91.      *
  92.      * @param int $position
  93.      *
  94.      * @return $this
  95.      */
  96.     public function setPosition($position)
  97.     {
  98.         $this->position $position;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Return Name
  103.      *
  104.      * @return string|null
  105.      */
  106.     public function getServiceName()
  107.     {
  108.         return $this->service_name;
  109.     }
  110.     /**
  111.      * Set Name
  112.      *
  113.      * @param string $service_name
  114.      *
  115.      * @return $this
  116.      */
  117.     public function setServiceName($service_name)
  118.     {
  119.         $this->service_name $service_name;
  120.         return $this;
  121.     }
  122.     /**
  123.      * Return Providers
  124.      *
  125.      * @return GlobalTabProvider[]
  126.      */
  127.     public function getProviders()
  128.     {
  129.         return $this->providers;
  130.     }
  131.     /**
  132.      * Set Providers
  133.      *
  134.      * @param GlobalTabProvider $provider
  135.      *
  136.      * @return $this
  137.      */
  138.     public function addProvider($provider)
  139.     {
  140.         $this->providers[] = $provider;
  141.         return $this;
  142.     }
  143.     /**
  144.      * Get provider by code
  145.      *
  146.      * @param $code
  147.      *
  148.      * @return array
  149.      */
  150.     public function getProviderByCode($code)
  151.     {
  152.         $provider array_filter($this->getProviders()->toArray(), static function ($v$k) use ($code) {
  153.             /** @var \XLite\Model\Product\GlobalTabProvider $v */
  154.             return $v->getCode() === $code;
  155.         }, ARRAY_FILTER_USE_BOTH);
  156.         return !empty($provider) ? array_shift($provider) : null;
  157.     }
  158.     /**
  159.      * Check if at least one provider available
  160.      *
  161.      * @return boolean
  162.      */
  163.     public function checkProviders()
  164.     {
  165.         foreach ($this->getProviders() as $provider) {
  166.             if ($provider->checkProvider()) {
  167.                 return true;
  168.             }
  169.         }
  170.         return false;
  171.     }
  172.     /**
  173.      * Check if tab available
  174.      *
  175.      * @return bool
  176.      */
  177.     public function isAvailable()
  178.     {
  179.         return $this->checkProviders();
  180.     }
  181.     /**
  182.      * Returns tab name
  183.      *
  184.      * @return string
  185.      */
  186.     public function getName()
  187.     {
  188.         return static::t($this->getServiceName());
  189.     }
  190.     public function getModule(): ?string
  191.     {
  192.         return $this->module;
  193.     }
  194.     public function setModule(string $module): void
  195.     {
  196.         $this->module $module;
  197.     }
  198. }