classes/XLite/Model/State.php line 25

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.  * State
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table (name="states",
  13.  *      uniqueConstraints={
  14.  *          @ORM\UniqueConstraint (name="code", columns={"code","country_code"})
  15.  *      },
  16.  *      indexes={
  17.  *          @ORM\Index (name="state", columns={"state"})
  18.  *      }
  19.  * )
  20.  */
  21. class State extends \XLite\Model\AEntity
  22. {
  23.     /**
  24.      * State unique id
  25.      *
  26.      * @var integer
  27.      *
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue (strategy="AUTO")
  30.      * @ORM\Column (type="integer")
  31.      */
  32.     protected $state_id;
  33.     /**
  34.      * State name
  35.      *
  36.      * @var string
  37.      *
  38.      * @ORM\Column (type="string", length=64)
  39.      */
  40.     protected $state;
  41.     /**
  42.      * State code
  43.      *
  44.      * @var string
  45.      *
  46.      * @ORM\Column (type="string", length=64)
  47.      */
  48.     protected $code;
  49.     /**
  50.      * Country (relation)
  51.      *
  52.      * @var \XLite\Model\Country
  53.      *
  54.      * @ORM\ManyToOne (targetEntity="XLite\Model\Country", inversedBy="states", cascade={"merge","detach"})
  55.      * @ORM\JoinColumn (name="country_code", referencedColumnName="code", onDelete="CASCADE")
  56.      */
  57.     protected $country;
  58.     /**
  59.      * Region (relation)
  60.      *
  61.      * @var \XLite\Model\Region
  62.      *
  63.      * @ORM\ManyToOne (targetEntity="XLite\Model\Region", inversedBy="states", cascade={"merge","detach"})
  64.      * @ORM\JoinColumn (name="region_code", referencedColumnName="code", onDelete="CASCADE")
  65.      */
  66.     protected $region;
  67.     /**
  68.      * Set code
  69.      *
  70.      * @param string $code Code
  71.      *
  72.      * @return void
  73.      */
  74.     public function setCode($code)
  75.     {
  76.         if ($this->code != $code && $this->getCountry()) {
  77.             $elements \XLite\Core\Database::getRepo('XLite\Model\ZoneElement')->findBy(
  78.                 [
  79.                     'element_type'  => \XLite\Model\ZoneElement::ZONE_ELEMENT_STATE,
  80.                     'element_value' => $this->getCountry()->getCode() . '_' $this->code,
  81.                 ]
  82.             );
  83.             foreach ($elements as $element) {
  84.                 $element->setElementValue($this->getCountry()->getCode() . '_' $code);
  85.             }
  86.             if ($elements) {
  87.                 \XLite\Core\Database::getRepo('XLite\Model\Zone')->cleanCache();
  88.             }
  89.         }
  90.         $this->code $code;
  91.         return $this;
  92.     }
  93.     /**
  94.      * Get state_id
  95.      *
  96.      * @return integer
  97.      */
  98.     public function getStateId()
  99.     {
  100.         return $this->state_id;
  101.     }
  102.     /**
  103.      * Set state
  104.      *
  105.      * @param string $state
  106.      * @return State
  107.      */
  108.     public function setState($state)
  109.     {
  110.         $this->state $state;
  111.         return $this;
  112.     }
  113.     /**
  114.      * Get state
  115.      *
  116.      * @return string
  117.      */
  118.     public function getState()
  119.     {
  120.         return $this->state;
  121.     }
  122.     /**
  123.      * Get code
  124.      *
  125.      * @return string
  126.      */
  127.     public function getCode()
  128.     {
  129.         return $this->code;
  130.     }
  131.     /**
  132.      * Set country
  133.      *
  134.      * @param \XLite\Model\Country $country
  135.      * @return State
  136.      */
  137.     public function setCountry(\XLite\Model\Country $country null)
  138.     {
  139.         $this->country $country;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get country
  144.      *
  145.      * @return \XLite\Model\Country
  146.      */
  147.     public function getCountry()
  148.     {
  149.         return $this->country;
  150.     }
  151.     /**
  152.      * Set region
  153.      *
  154.      * @param \XLite\Model\Region $region
  155.      * @return State
  156.      */
  157.     public function setRegion(\XLite\Model\Region $region null)
  158.     {
  159.         $this->region $region;
  160.         return $this;
  161.     }
  162.     /**
  163.      * Get region
  164.      *
  165.      * @return \XLite\Model\Region
  166.      */
  167.     public function getRegion()
  168.     {
  169.         return $this->region;
  170.     }
  171. }