modules/QSL/SpecialOffersBase/src/Model/OfferType.php line 20

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\SpecialOffersBase\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Special Offer Type model.
  10.  *
  11.  * It stores information on what special offer logic should be used and offer settings.
  12.  *
  13.  * @ORM\Entity (repositoryClass="\QSL\SpecialOffersBase\Model\Repo\OfferType")
  14.  * @ORM\Table  (name="special_offer_types",
  15.  *      indexes={
  16.  *          @ORM\Index (name="type_id", columns={"type_id"}),
  17.  *          @ORM\Index (name="processorClass", columns={"processorClass"}),
  18.  *          @ORM\Index (name="position", columns={"position"}),
  19.  *          @ORM\Index (name="enabled", columns={"enabled"})
  20.  *      }
  21.  * )
  22.  */
  23. class OfferType extends \XLite\Model\Base\I18n
  24. {
  25.     /**
  26.      * Unique identifier of the offer type.
  27.      *
  28.      * @var integer
  29.      *
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue (strategy="AUTO")
  32.      * @ORM\Column         (type="integer")
  33.      */
  34.     protected $type_id;
  35.     /**
  36.      * Whether the offer type is enabled, or not.
  37.      *
  38.      * @var boolean
  39.      *
  40.      * @ORM\Column (type="boolean")
  41.      */
  42.     protected $enabled true;
  43.     /**
  44.      * Name of the class that implements the offer logic.
  45.      *
  46.      * @var string
  47.      *
  48.      * @ORM\Column (type="string", length=255)
  49.      */
  50.     protected $processorClass;
  51.     /**
  52.      * Name of the class that implements the View Model logic.
  53.      *
  54.      * @var string
  55.      *
  56.      * @ORM\Column (type="string", length=255)
  57.      */
  58.     protected $viewModelClass;
  59.     /**
  60.      * Position of the exit offer among other ones in the list.
  61.      *
  62.      * @var integer
  63.      *
  64.      * @ORM\Column (type="integer")
  65.      */
  66.     protected $position 0;
  67.     /**
  68.      * Special offers of this type.
  69.      *
  70.      * @var \Doctrine\Common\Collections\Collection
  71.      *
  72.      * @ORM\OneToMany (targetEntity="QSL\SpecialOffersBase\Model\SpecialOffer", mappedBy="offerType", cascade={"remove"})
  73.      */
  74.     protected $specialOffers// when the offer type is deleted, the operation cascades to all related offers (via Doctrine)
  75.     /**
  76.      * Cached processor class instance.
  77.      *
  78.      * @var \QSL\SpecialOffersBase\Logic\Order\SpecialOffer\ASpecialOffer
  79.      */
  80.     protected $processor;
  81.     /**
  82.      * @var \Doctrine\Common\Collections\Collection
  83.      *
  84.      * @ORM\OneToMany (targetEntity="QSL\SpecialOffersBase\Model\OfferTypeTranslation", mappedBy="owner", cascade={"all"})
  85.      */
  86.     protected $translations;
  87.     /**
  88.      * Checks if the special offer has correct processor and view model classes.
  89.      *
  90.      * @return boolean
  91.      */
  92.     public function hasAllRequiredClasses()
  93.     {
  94.         return class_exists($this->getProcessorClass())
  95.             && class_exists($this->getViewModelClass());
  96.     }
  97.     /**
  98.      * Returns the processor class for this special offer type.
  99.      *
  100.      * @return \QSL\SpecialOffersBase\Logic\Order\SpecialOffer\ASpecialOffer
  101.      */
  102.     public function getProcessor()
  103.     {
  104.         if (!isset($this->processor)) {
  105.             $this->processor $this->factoryProcessor();
  106.         }
  107.         return $this->processor;
  108.     }
  109.     /**
  110.      * Creates a new instance of the processor class for this special offer type.
  111.      *
  112.      * @return \QSL\SpecialOffersBase\Logic\Order\SpecialOffer\ASpecialOffer
  113.      */
  114.     protected function factoryProcessor()
  115.     {
  116.         $class $this->getProcessorClass();
  117.         return class_exists($class) ? new $class() : null;
  118.     }
  119.     /**
  120.      * Returns the model identifier.
  121.      *
  122.      * @return integer
  123.      */
  124.     public function getTypeId()
  125.     {
  126.         return $this->type_id;
  127.     }
  128.     /**
  129.      * Confgiures whether the special offer type is enabled, or disabled.
  130.      *
  131.      * @param boolean $enabled New state
  132.      *
  133.      * @return OfferType
  134.      */
  135.     public function setEnabled($enabled)
  136.     {
  137.         $this->enabled $enabled;
  138.         return $this;
  139.     }
  140.     /**
  141.      * Checks if the special offer type is enabled, or not.
  142.      *
  143.      * @return boolean
  144.      */
  145.     public function getEnabled()
  146.     {
  147.         return $this->enabled;
  148.     }
  149.     /**
  150.      * Updates the name of the processor class for the special offer.
  151.      *
  152.      * @param string $processorClass Class name
  153.      *
  154.      * @return OfferType
  155.      */
  156.     public function setProcessorClass($processorClass)
  157.     {
  158.         $this->processorClass $processorClass;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Returns the name of the processor class for the special offer type.
  163.      *
  164.      * @return string
  165.      */
  166.     public function getProcessorClass()
  167.     {
  168.         return $this->processorClass;
  169.     }
  170.     /**
  171.      * Updates the name of the view class for the special offer type.
  172.      *
  173.      * @param string $viewModelClass Class name
  174.      *
  175.      * @return OfferType
  176.      */
  177.     public function setViewModelClass($viewModelClass)
  178.     {
  179.         $this->viewModelClass $viewModelClass;
  180.         return $this;
  181.     }
  182.     /**
  183.      * Returns the name of the view class for the special offer type.
  184.      *
  185.      * @return string
  186.      */
  187.     public function getViewModelClass()
  188.     {
  189.         return $this->viewModelClass;
  190.     }
  191.     /**
  192.      * Updates the position of the special offer type among others.
  193.      *
  194.      * @param integer $position New position
  195.      *
  196.      * @return OfferType
  197.      */
  198.     public function setPosition($position)
  199.     {
  200.         $this->position $position;
  201.         return $this;
  202.     }
  203.     /**
  204.      * Returns the position of the special offer type among others.
  205.      *
  206.      * @return integer
  207.      */
  208.     public function getPosition()
  209.     {
  210.         return $this->position;
  211.     }
  212.     /**
  213.      * Associates a special offer with the special offer type.
  214.      *
  215.      * @param \QSL\SpecialOffersBase\Model\SpecialOffer $specialOffers Special offer model
  216.      *
  217.      * @return OfferType
  218.      */
  219.     public function addSpecialOffers(\QSL\SpecialOffersBase\Model\SpecialOffer $specialOffers)
  220.     {
  221.         $this->specialOffers[] = $specialOffers;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Returns special offers of the type.
  226.      *
  227.      * @return \Doctrine\Common\Collections\Collection
  228.      */
  229.     public function getSpecialOffers()
  230.     {
  231.         return $this->specialOffers;
  232.     }
  233. }