modules/XC/CustomProductTabs/src/Model/Product/CustomGlobalTab.php line 19

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. use XC\CustomProductTabs\Main;
  9. /**
  10.  * Custom global tab model class
  11.  *
  12.  * @ORM\Entity
  13.  * @ORM\Table  (name="custom_global_tabs")
  14.  */
  15. class CustomGlobalTab extends \XLite\Model\Base\I18n
  16. {
  17.     /**
  18.      * Tab unique ID
  19.      *
  20.      * @var integer
  21.      *
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue (strategy="AUTO")
  24.      * @ORM\Column         (type="integer", options={ "unsigned": true })
  25.      */
  26.     protected $id;
  27.     /**
  28.      * Global tab
  29.      *
  30.      * @var \XLite\Model\Product\GlobalTab
  31.      * @ORM\OneToOne  (targetEntity="XLite\Model\Product\GlobalTab", inversedBy="custom_tab")
  32.      * @ORM\JoinColumn (name="global_tab_id", referencedColumnName="id", onDelete="CASCADE")
  33.      */
  34.     protected $global_tab;
  35.     /**
  36.      * @var \Doctrine\Common\Collections\Collection
  37.      *
  38.      * @ORM\OneToMany (targetEntity="XC\CustomProductTabs\Model\Product\CustomGlobalTabTranslation", mappedBy="owner", cascade={"all"})
  39.      */
  40.     protected $translations;
  41.     /**
  42.      * Assign new link to tab if empty
  43.      */
  44.     public function assignLink()
  45.     {
  46.         if (
  47.             $this->getGlobalTab()
  48.             && !$this->getGlobalTab()->getLink()
  49.         ) {
  50.             $this->getGlobalTab()->setLink(
  51.                 \XLite\Core\Database::getRepo('\XLite\Model\Product\GlobalTab')->generateTabLink($this)
  52.             );
  53.         }
  54.     }
  55.     public function assignModule()
  56.     {
  57.         if (
  58.             $this->getGlobalTab()
  59.             && !$this->getGlobalTab()->getModule()
  60.         ) {
  61.             [$author$name] = explode('-'Main::MODULE_ID);
  62.             $this->getGlobalTab()->setModule("$author\\$name");
  63.         }
  64.     }
  65.     /**
  66.      * Create entity
  67.      *
  68.      * @return boolean
  69.      */
  70.     public function create()
  71.     {
  72.         if (!$this->getGlobalTab()) {
  73.             $this->setGlobalTab(new \XLite\Model\Product\GlobalTab());
  74.             $this->getGlobalTab()->setPosition(\XLite\Core\Database::getRepo('XLite\Model\Product\GlobalTab')->getMinPosition() - 10);
  75.         }
  76.         if (!$this->getGlobalTab()->isPersistent()) {
  77.             \XLite\Core\Database::getEM()->persist($this->getGlobalTab());
  78.             $createAliases true;
  79.         }
  80.         $result parent::create();
  81.         if (isset($createAliases) && $result) {
  82.             \XLite\Core\Database::getRepo('XLite\Model\Product\GlobalTab')->createGlobalTabAliases($this->getGlobalTab());
  83.         }
  84.         return $result;
  85.     }
  86.     /**
  87.      * Return GlobalTab
  88.      *
  89.      * @return \XLite\Model\Product\GlobalTab
  90.      */
  91.     public function getGlobalTab()
  92.     {
  93.         return $this->global_tab;
  94.     }
  95.     /**
  96.      * Set GlobalTab
  97.      *
  98.      * @param \XLite\Model\Product\GlobalTab $global_tab
  99.      *
  100.      * @return $this
  101.      */
  102.     public function setGlobalTab($global_tab)
  103.     {
  104.         $this->global_tab $global_tab;
  105.         return $this;
  106.     }
  107.     /**
  108.      * Get id
  109.      *
  110.      * @return integer
  111.      */
  112.     public function getId()
  113.     {
  114.         return $this->id;
  115.     }
  116.     /**
  117.      * Return Enabled
  118.      *
  119.      * @return boolean
  120.      */
  121.     public function getEnabled()
  122.     {
  123.         return $this->getGlobalTab()->getEnabled();
  124.     }
  125.     /**
  126.      * Set Enabled
  127.      *
  128.      * @param boolean $enabled
  129.      *
  130.      * @return $this
  131.      */
  132.     public function setEnabled($enabled)
  133.     {
  134.         $this->getGlobalTab()->setEnabled($enabled);
  135.         return $this;
  136.     }
  137.     // {{{ Translation Getters / setters
  138.     /**
  139.      * @return string
  140.      */
  141.     public function getBriefInfo()
  142.     {
  143.         return $this->getTranslationField(__FUNCTION__);
  144.     }
  145.     /**
  146.      * @param string $brief_info
  147.      *
  148.      * @return \XLite\Model\Base\Translation
  149.      */
  150.     public function setBriefInfo($brief_info)
  151.     {
  152.         return $this->setTranslationField(__FUNCTION__$brief_info);
  153.     }
  154.     /**
  155.      * @return string
  156.      */
  157.     public function getContent()
  158.     {
  159.         return $this->getTranslationField(__FUNCTION__);
  160.     }
  161.     /**
  162.      * @param string $content
  163.      *
  164.      * @return \XLite\Model\Base\Translation
  165.      */
  166.     public function setContent($content)
  167.     {
  168.         return $this->setTranslationField(__FUNCTION__$content);
  169.     }
  170.     // }}}
  171. }