classes/XLite/Model/AddressField.php line 16

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. /**
  9.  * @ORM\Entity
  10.  * @ORM\Table (name="address_field")
  11.  */
  12. class AddressField extends \XLite\Model\Base\I18n implements \XLite\Model\Base\IModuleRelatedEntity
  13. {
  14.     /**
  15.      * @var int
  16.      *
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue (strategy="AUTO")
  19.      * @ORM\Column (type="integer", nullable=false)
  20.      */
  21.     protected $id;
  22.     /**
  23.      * Service name for address field
  24.      * For example: firstname, lastname, country_code and so on.
  25.      *
  26.      * The field is named with this value in the address forms.
  27.      * Also the "service-name-{$serviceName}" CSS class is added to the field
  28.      *
  29.      * @var string
  30.      * @ORM\Column(type="string", length=128, unique=true, nullable=false)
  31.      */
  32.     protected $serviceName;
  33.     /**
  34.      * Getter name for address field (for AView::getAddressSectionData)
  35.      * For example:
  36.      * country for country_code
  37.      * state for state_id, custom_state
  38.      *
  39.      * The field is named with this value in the address forms.
  40.      * Also the "service-name-{$serviceName}" CSS class is added to the field
  41.      *
  42.      * @var string
  43.      * @ORM\Column(type="string", length=128, nullable=false)
  44.      */
  45.     protected $viewGetterName '';
  46.     /**
  47.      * Schema class for "Form field widget".
  48.      * This class will be used in form widgets
  49.      *
  50.      * Possible values are:
  51.      *
  52.      * \XLite\View\FormField\Input\Text
  53.      * \XLite\View\FormField\Select\Country
  54.      * \XLite\View\FormField\Select\Title
  55.      *
  56.      * For more information check "\XLite\View\FormField\*" class family.
  57.      *
  58.      * The '\XLite\View\FormField\Input\Text' class (standard input text field)
  59.      * is taken for additional fields by default.
  60.      *
  61.      * @var string
  62.      * @ORM\Column(type="string", length=256, nullable=false)
  63.      */
  64.     protected $schemaClass '\XLite\View\FormField\Input\Text';
  65.     /**
  66.      * Flag if the field is an additional one (This field could be removed)
  67.      *
  68.      * @var bool
  69.      * @ORM\Column(type="boolean")
  70.      */
  71.     protected $additional true;
  72.     /**
  73.      * Flag if the field is a required one
  74.      *
  75.      * @var bool
  76.      * @ORM\Column(type="boolean")
  77.      */
  78.     protected $required true;
  79.     /**
  80.      * Flag if the field is an enabled one
  81.      *
  82.      * @var bool
  83.      * @ORM\Column(type="boolean")
  84.      */
  85.     protected $enabled true;
  86.     /**
  87.      * @var int
  88.      *
  89.      * @ORM\Column (type="integer")
  90.      */
  91.     protected $position 0;
  92.     /**
  93.      * @var \Doctrine\Common\Collections\Collection
  94.      *
  95.      * @ORM\OneToMany (targetEntity="XLite\Model\AddressFieldTranslation", mappedBy="owner", cascade={"all"})
  96.      */
  97.     protected $translations;
  98.     /**
  99.      * @ORM\Column(type="string", nullable=true)
  100.      */
  101.     protected ?string $module;
  102.     public function getModule(): ?string
  103.     {
  104.         return $this->module;
  105.     }
  106.     public function setModule(string $module): void
  107.     {
  108.         $this->module $module;
  109.     }
  110.     /**
  111.      * Return CSS classes for this field name entry
  112.      *
  113.      * @return string
  114.      */
  115.     public function getCSSFieldName()
  116.     {
  117.         return 'address-' $this->getServiceName() . ($this->getAdditional() ? ' field-additional' '');
  118.     }
  119.     /**
  120.      * Get id
  121.      *
  122.      * @return integer
  123.      */
  124.     public function getId()
  125.     {
  126.         return $this->id;
  127.     }
  128.     /**
  129.      * Set serviceName
  130.      *
  131.      * @param string $serviceName
  132.      * @return AddressField
  133.      */
  134.     public function setServiceName($serviceName)
  135.     {
  136.         $this->serviceName $serviceName;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Get serviceName
  141.      *
  142.      * @return string
  143.      */
  144.     public function getServiceName()
  145.     {
  146.         return $this->serviceName;
  147.     }
  148.     /**
  149.      * Set viewGetterName
  150.      *
  151.      * @param string $viewGetterName
  152.      * @return AddressField
  153.      */
  154.     public function setViewGetterName($viewGetterName)
  155.     {
  156.         $this->viewGetterName $viewGetterName;
  157.         return $this;
  158.     }
  159.     /**
  160.      * Get viewGetterName
  161.      *
  162.      * @return string
  163.      */
  164.     public function getViewGetterName()
  165.     {
  166.         return $this->viewGetterName;
  167.     }
  168.     /**
  169.      * Set schemaClass
  170.      *
  171.      * @param string $schemaClass
  172.      * @return AddressField
  173.      */
  174.     public function setSchemaClass($schemaClass)
  175.     {
  176.         $this->schemaClass $schemaClass;
  177.         return $this;
  178.     }
  179.     /**
  180.      * Get schemaClass
  181.      *
  182.      * @return string
  183.      */
  184.     public function getSchemaClass()
  185.     {
  186.         return $this->schemaClass;
  187.     }
  188.     /**
  189.      * Set additional
  190.      *
  191.      * @param boolean $additional
  192.      * @return AddressField
  193.      */
  194.     public function setAdditional($additional)
  195.     {
  196.         $this->additional $additional;
  197.         return $this;
  198.     }
  199.     /**
  200.      * Get additional
  201.      *
  202.      * @return boolean
  203.      */
  204.     public function getAdditional()
  205.     {
  206.         return $this->additional;
  207.     }
  208.     /**
  209.      * Set required
  210.      *
  211.      * @param boolean $required
  212.      * @return AddressField
  213.      */
  214.     public function setRequired($required)
  215.     {
  216.         $this->required $required;
  217.         return $this;
  218.     }
  219.     /**
  220.      * Get required
  221.      *
  222.      * @return boolean
  223.      */
  224.     public function getRequired()
  225.     {
  226.         return $this->required;
  227.     }
  228.     /**
  229.      * Set enabled
  230.      *
  231.      * @param boolean $enabled
  232.      * @return AddressField
  233.      */
  234.     public function setEnabled($enabled)
  235.     {
  236.         $this->enabled = (bool)$enabled;
  237.         return $this;
  238.     }
  239.     /**
  240.      * Get enabled
  241.      *
  242.      * @return boolean
  243.      */
  244.     public function getEnabled()
  245.     {
  246.         return $this->enabled;
  247.     }
  248.     /**
  249.      * Set position
  250.      *
  251.      * @param integer $position
  252.      * @return AddressField
  253.      */
  254.     public function setPosition($position)
  255.     {
  256.         $this->position $position;
  257.         return $this;
  258.     }
  259.     /**
  260.      * Get position
  261.      *
  262.      * @return integer
  263.      */
  264.     public function getPosition()
  265.     {
  266.         return $this->position;
  267.     }
  268.     /**
  269.      * @return bool
  270.      */
  271.     public function isHidden(): bool
  272.     {
  273.         return static::isHiddenField($this->getServiceName());
  274.     }
  275.     /**
  276.      * Whether the field should not be showed in the address bloks, etc.
  277.      *
  278.      * @param string $serviceName Service name.
  279.      *
  280.      * @return bool True if the field should not be among the visible and editable form fields, false otherwise.
  281.      */
  282.     public static function isHiddenField(string $serviceName): bool
  283.     {
  284.         return in_array($serviceName, [ 'email' ], true);
  285.     }
  286. }