modules/XC/CustomProductTabs/src/Model/Product/Tab.php line 22

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 XC\CustomProductTabs\Model\Product;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * The "tab" model class
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table  (name="product_tabs",
  13.  *      uniqueConstraints={
  14.  *          @ORM\UniqueConstraint (name="product_global_tab", columns={"product_id", "global_tab_id"})
  15.  *      }
  16.  * )
  17.  */
  18. class Tab extends \XLite\Model\Base\I18n implements \XLite\Model\Product\IProductTab
  19. {
  20.     /**
  21.      * Tab unique ID
  22.      *
  23.      * @var integer
  24.      *
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue (strategy="AUTO")
  27.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  28.      */
  29.     protected $id;
  30.     /**
  31.      * Tab position
  32.      *
  33.      * @var integer
  34.      *
  35.      * @ORM\Column (type="integer")
  36.      */
  37.     protected $position 0;
  38.     /**
  39.      * Is tab available or not
  40.      *
  41.      * @var boolean
  42.      *
  43.      * @ORM\Column (type="boolean")
  44.      */
  45.     protected $enabled true;
  46.     /**
  47.      * Link
  48.      *
  49.      * @var string
  50.      *
  51.      * @ORM\Column (type="string",nullable=true)
  52.      */
  53.     protected $link null;
  54.     /**
  55.      * Tab product
  56.      *
  57.      * @var \XLite\Model\Product
  58.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product", inversedBy="tabs")
  59.      * @ORM\JoinColumn (name="product_id", referencedColumnName="product_id", onDelete="CASCADE")
  60.      */
  61.     protected $product;
  62.     /**
  63.      * Global tab product
  64.      *
  65.      * @var \XLite\Model\Product\GlobalTab
  66.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Product\GlobalTab", inversedBy="product_specific_aliases")
  67.      * @ORM\JoinColumn (name="global_tab_id", referencedColumnName="id", onDelete="CASCADE")
  68.      */
  69.     protected $global_tab;
  70.     /**
  71.      * @var \Doctrine\Common\Collections\Collection
  72.      *
  73.      * @ORM\OneToMany (targetEntity="XC\CustomProductTabs\Model\Product\TabTranslation", mappedBy="owner", cascade={"all"})
  74.      */
  75.     protected $translations;
  76.     /**
  77.      * Assign new link to tab if empty
  78.      */
  79.     public function assignLink()
  80.     {
  81.         if (
  82.             !$this->isGlobal()
  83.             && !$this->getLink()
  84.         ) {
  85.             $this->setLink(
  86.                 \XLite\Core\Database::getRepo('\XC\CustomProductTabs\Model\Product\Tab')
  87.                     ->generateTabLink($this)
  88.             );
  89.         }
  90.     }
  91.     /**
  92.      * @inheritdoc
  93.      */
  94.     public function cloneEntity()
  95.     {
  96.         $new parent::cloneEntity();
  97.         $new->setGlobalTab($this->getGlobalTab());
  98.         return $new;
  99.     }
  100.     /**
  101.      * Get id
  102.      *
  103.      * @return integer
  104.      */
  105.     public function getId()
  106.     {
  107.         return $this->id;
  108.     }
  109.     /**
  110.      * Set position
  111.      *
  112.      * @param integer $position
  113.      *
  114.      * @return $this
  115.      */
  116.     public function setPosition($position)
  117.     {
  118.         $this->position $position;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Get position
  123.      *
  124.      * @return integer
  125.      */
  126.     public function getPosition()
  127.     {
  128.         return $this->position;
  129.     }
  130.     /**
  131.      * Set enabled
  132.      *
  133.      * @param boolean $enabled
  134.      *
  135.      * @return $this
  136.      */
  137.     public function setEnabled($enabled)
  138.     {
  139.         $this->enabled $enabled;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get enabled
  144.      *
  145.      * @return boolean
  146.      */
  147.     public function getEnabled()
  148.     {
  149.         return $this->enabled;
  150.     }
  151.     /**
  152.      * Return Link
  153.      *
  154.      * @return mixed
  155.      */
  156.     public function getLink()
  157.     {
  158.         return $this->link preg_replace('/[^a-z0-9-_]/i''-'$this->link) : '';
  159.     }
  160.     /**
  161.      * Set Link
  162.      *
  163.      * @param mixed $link
  164.      *
  165.      * @return $this
  166.      */
  167.     public function setLink($link)
  168.     {
  169.         $this->link $link;
  170.         return $this;
  171.     }
  172.     /**
  173.      * Set product
  174.      *
  175.      * @param \XLite\Model\Product $product
  176.      *
  177.      * @return $this
  178.      */
  179.     public function setProduct(\XLite\Model\Product $product null)
  180.     {
  181.         $this->product $product;
  182.         return $this;
  183.     }
  184.     /**
  185.      * Get product
  186.      *
  187.      * @return \XLite\Model\Product
  188.      */
  189.     public function getProduct()
  190.     {
  191.         return $this->product;
  192.     }
  193.     /**
  194.      * Return GlobalTab
  195.      *
  196.      * @return \XLite\Model\Product\GlobalTab
  197.      */
  198.     public function getGlobalTab()
  199.     {
  200.         return $this->global_tab;
  201.     }
  202.     /**
  203.      * Set GlobalTab
  204.      *
  205.      * @param \XLite\Model\Product\GlobalTab $global_tab
  206.      *
  207.      * @return $this
  208.      */
  209.     public function setGlobalTab($global_tab)
  210.     {
  211.         $this->global_tab $global_tab;
  212.         return $this;
  213.     }
  214.     /**
  215.      * Return Name
  216.      *
  217.      * @return string|null
  218.      */
  219.     public function getServiceName()
  220.     {
  221.         return $this->getGlobalTab()
  222.             ? $this->getGlobalTab()->getServiceName()
  223.             : null;
  224.     }
  225.     /**
  226.      * Check if tab available
  227.      *
  228.      * @return bool
  229.      */
  230.     public function isAvailable()
  231.     {
  232.         $result $this->isGlobalStatic()
  233.             ? $this->getGlobalTab()->checkProviders()
  234.             : true;
  235.         return $result && $this->getEnabled();
  236.     }
  237.     /**
  238.      * Check if tab is alias to global
  239.      *
  240.      * @return bool
  241.      */
  242.     public function isGlobal()
  243.     {
  244.         return (bool)$this->getGlobalTab();
  245.     }
  246.     /**
  247.      * Check if tab is alias to global custom
  248.      *
  249.      * @return bool
  250.      */
  251.     public function isGlobalCustom()
  252.     {
  253.         return $this->isGlobal() && $this->getGlobalTab()->getCustomTab();
  254.     }
  255.     /**
  256.      * Check if tab is alias to global static
  257.      *
  258.      * @return bool
  259.      */
  260.     public function isGlobalStatic()
  261.     {
  262.         return $this->getGlobalTab() && $this->getGlobalTab()->getServiceName();
  263.     }
  264.     // {{{ Translation Getters / setters
  265.     /**
  266.      * Get name
  267.      *
  268.      * @return string
  269.      */
  270.     public function getName()
  271.     {
  272.         return $this->isGlobal()
  273.             ? $this->getGlobalTab()->getName()
  274.             : $this->getTranslationField(__FUNCTION__);
  275.     }
  276.     /**
  277.      * Get content
  278.      *
  279.      * @return string
  280.      */
  281.     public function getBriefInfo()
  282.     {
  283.         return $this->isGlobalCustom()
  284.             ? $this->getGlobalTab()->getCustomTab()->getBriefInfo()
  285.             : $this->getTranslationField(__FUNCTION__);
  286.     }
  287.     /**
  288.      * @param string $brief_info
  289.      *
  290.      * @return \XLite\Model\Base\Translation
  291.      */
  292.     public function setBriefInfo($brief_info)
  293.     {
  294.         return $this->setTranslationField(__FUNCTION__$brief_info);
  295.     }
  296.     /**
  297.      * Get content
  298.      *
  299.      * @return string
  300.      */
  301.     public function getContent()
  302.     {
  303.         return $this->isGlobalCustom()
  304.             ? $this->getGlobalTab()->getCustomTab()->getContent()
  305.             : $this->getTranslationField(__FUNCTION__);
  306.     }
  307.     /**
  308.      * @param string $content
  309.      *
  310.      * @return \XLite\Model\Base\Translation
  311.      */
  312.     public function setContent($content)
  313.     {
  314.         return $this->setTranslationField(__FUNCTION__$content);
  315.     }
  316.     // }}}
  317. }