classes/XLite/Model/Config.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 XLite\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use XLite\Model\Base\IModuleRelatedEntity;
  9. /**
  10.  * DB-based configuration registry
  11.  *
  12.  * @ORM\Entity
  13.  * @ORM\Table  (name="config",
  14.  *      uniqueConstraints={
  15.  *          @ORM\UniqueConstraint (name="nc", columns={"name", "category"})
  16.  *      },
  17.  *      indexes={
  18.  *          @ORM\Index (name="orderby", columns={"orderby"}),
  19.  *          @ORM\Index (name="type", columns={"type"})
  20.  *      }
  21.  * )
  22.  */
  23. class Config extends \XLite\Model\Base\I18n implements IModuleRelatedEntity
  24. {
  25.     /**
  26.      * Name for the Shipping category options
  27.      */
  28.     public const SHIPPING_CATEGORY 'Shipping';
  29.     /**
  30.      * Prefix for the shipping values
  31.      */
  32.     public const SHIPPING_VALUES_PREFIX 'anonymous_';
  33.     /**
  34.      * Option unique name
  35.      *
  36.      * @var string
  37.      *
  38.      * @ORM\Id
  39.      * @ORM\GeneratedValue (strategy="AUTO")
  40.      * @ORM\Column (type="integer")
  41.      */
  42.     protected $config_id;
  43.     /**
  44.      * Option name
  45.      *
  46.      * @var string
  47.      *
  48.      * @ORM\Column (type="string", length=32)
  49.      */
  50.     protected $name;
  51.     /**
  52.      * Option category
  53.      *
  54.      * @var string
  55.      *
  56.      * @ORM\Column (type="string", length=64)
  57.      */
  58.     protected $category;
  59.     /**
  60.      * Option type
  61.      * Allowed values:'','text','textarea','checkbox','country','state','select','serialized','separator'
  62.      *     or form field class name
  63.      *
  64.      * @var string
  65.      *
  66.      * @ORM\Column (type="string", length=128)
  67.      */
  68.     protected $type '';
  69.     /**
  70.      * Option position within category
  71.      *
  72.      * @var integer
  73.      *
  74.      * @ORM\Column (type="integer")
  75.      */
  76.     protected $orderby 0;
  77.     /**
  78.      * Option value
  79.      *
  80.      * @var string
  81.      *
  82.      * @ORM\Column (type="text")
  83.      */
  84.     protected $value '';
  85.     /**
  86.      * New value temporary field
  87.      *
  88.      * @var string
  89.      */
  90.     protected $newValue;
  91.     /**
  92.      * Widget parameters
  93.      *
  94.      * @var array
  95.      *
  96.      * @ORM\Column (type="array", nullable=true)
  97.      */
  98.     protected $widgetParameters;
  99.     /**
  100.      * @var \Doctrine\Common\Collections\Collection
  101.      *
  102.      * @ORM\OneToMany (targetEntity="XLite\Model\ConfigTranslation", mappedBy="owner", cascade={"all"})
  103.      */
  104.     protected $translations;
  105.     /**
  106.      * @ORM\Column(type="string", nullable=true)
  107.      */
  108.     protected ?string $module;
  109.     /**
  110.      * Set new value
  111.      *
  112.      * @param string $value Value
  113.      *
  114.      * @return void
  115.      */
  116.     public function setNewValue($value)
  117.     {
  118.         $this->newValue $value;
  119.     }
  120.     /**
  121.      * Returns new value
  122.      *
  123.      * @return string
  124.      */
  125.     public function getNewValue()
  126.     {
  127.         return $this->newValue;
  128.     }
  129.     /**
  130.      * Get config_id
  131.      *
  132.      * @return integer
  133.      */
  134.     public function getConfigId()
  135.     {
  136.         return $this->config_id;
  137.     }
  138.     /**
  139.      * Set name
  140.      *
  141.      * @param string $name
  142.      * @return Config
  143.      */
  144.     public function setName($name)
  145.     {
  146.         $this->name $name;
  147.         return $this;
  148.     }
  149.     /**
  150.      * Get name
  151.      *
  152.      * @return string
  153.      */
  154.     public function getName()
  155.     {
  156.         return $this->name;
  157.     }
  158.     /**
  159.      * Set category
  160.      *
  161.      * @param string $category
  162.      * @return Config
  163.      */
  164.     public function setCategory($category)
  165.     {
  166.         $this->category $category;
  167.         return $this;
  168.     }
  169.     /**
  170.      * Get category
  171.      *
  172.      * @return string
  173.      */
  174.     public function getCategory()
  175.     {
  176.         return $this->category;
  177.     }
  178.     /**
  179.      * Set type
  180.      *
  181.      * @param string $type
  182.      * @return Config
  183.      */
  184.     public function setType($type)
  185.     {
  186.         $this->type $type;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Get type
  191.      *
  192.      * @return string
  193.      */
  194.     public function getType()
  195.     {
  196.         return $this->type;
  197.     }
  198.     /**
  199.      * Set orderby
  200.      *
  201.      * @param integer $orderby
  202.      * @return Config
  203.      */
  204.     public function setOrderby($orderby)
  205.     {
  206.         $this->orderby $orderby;
  207.         return $this;
  208.     }
  209.     /**
  210.      * Get orderby
  211.      *
  212.      * @return integer
  213.      */
  214.     public function getOrderby()
  215.     {
  216.         return $this->orderby;
  217.     }
  218.     /**
  219.      * Set value
  220.      *
  221.      * @param string $value
  222.      * @return Config
  223.      */
  224.     public function setValue($value)
  225.     {
  226.         $this->value $value;
  227.         return $this;
  228.     }
  229.     /**
  230.      * Get value
  231.      *
  232.      * @return string
  233.      */
  234.     public function getValue()
  235.     {
  236.         return $this->value;
  237.     }
  238.     /**
  239.      * Set widgetParameters
  240.      *
  241.      * @param array $widgetParameters
  242.      * @return Config
  243.      */
  244.     public function setWidgetParameters($widgetParameters)
  245.     {
  246.         $this->widgetParameters $widgetParameters;
  247.         return $this;
  248.     }
  249.     /**
  250.      * Get widgetParameters
  251.      *
  252.      * @return array
  253.      */
  254.     public function getWidgetParameters()
  255.     {
  256.         return $this->widgetParameters;
  257.     }
  258.     /**
  259.      * Detach self
  260.      */
  261.     public function detach()
  262.     {
  263.         \XLite\Core\Database::getEM()->detach($this);
  264.         // prevents detach if not initialized
  265.         if (empty($this->translations) || !$this->translations->isInitialized()) {
  266.             return;
  267.         }
  268.         foreach ($this->getTranslations() as $translation) {
  269.             $translation->detach();
  270.         }
  271.     }
  272.     // {{{ Translation Getters / setters
  273.     /**
  274.      * @return string
  275.      */
  276.     public function getOptionName()
  277.     {
  278.         return $this->getTranslationField(__FUNCTION__);
  279.     }
  280.     /**
  281.      * @param string $optionName
  282.      *
  283.      * @return \XLite\Model\Base\Translation
  284.      */
  285.     public function setOptionName($optionName)
  286.     {
  287.         return $this->setTranslationField(__FUNCTION__$optionName);
  288.     }
  289.     /**
  290.      * @return string
  291.      */
  292.     public function getOptionComment()
  293.     {
  294.         return $this->getTranslationField(__FUNCTION__);
  295.     }
  296.     /**
  297.      * @param string $optionComment
  298.      *
  299.      * @return \XLite\Model\Base\Translation
  300.      */
  301.     public function setOptionComment($optionComment)
  302.     {
  303.         return $this->setTranslationField(__FUNCTION__$optionComment);
  304.     }
  305.     // }}}
  306.     public function getModule(): ?string
  307.     {
  308.         return $this->module;
  309.     }
  310.     public function setModule(string $module): void
  311.     {
  312.         $this->module $module;
  313.     }
  314. }