Example #1
0
 /**
  * Set state
  *
  * @param mixed $state State object or state id or custom state name
  *
  * @return void
  * @todo Refactor?
  */
 public function setState($state)
 {
     if ($state instanceof \XLite\Model\State) {
         // Set by state object
         if ($state->getStateId()) {
             if (!$this->state || $this->state->getStateId() != $state->getStateId()) {
                 $this->state = $state;
             }
             $this->setCustomState($this->state->getState());
         } else {
             $this->state = null;
             $this->setCustomState($state->getState());
         }
     } elseif (is_string($state)) {
         // Set custom state
         $this->state = null;
         $this->setCustomState($state);
     }
 }
Example #2
0
 /**
  * Comparison states function for usort()
  *
  * @param \XLite\Model\State $a First state object
  * @param \XLite\Model\State $b Second state object
  *
  * @return integer
  */
 public static function sortStates($a, $b)
 {
     $aCountry = $a->getCountry()->getCountry();
     $aState = $a->getState();
     $bCountry = $b->getCountry()->getCountry();
     $bState = $b->getState();
     if ($aCountry == $bCountry && $aState == $bState) {
         $result = 0;
     } elseif ($aCountry == $bCountry) {
         $result = $aState > $bState ? 1 : -1;
     } else {
         $result = $aCountry > $bCountry ? 1 : -1;
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function prepareEntityBeforeCommit($type)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type));
     return parent::prepareEntityBeforeCommit($type);
 }
Example #4
0
 /**
  * Check - specified state is selected or not
  *
  * @param \XLite\Model\State $state Specidied (current) state
  *
  * @return boolean
  */
 public function isStateSelected(\XLite\Model\State $state)
 {
     return $state->getStateId() == $this->getParam(self::PARAM_STATE)->getStateId();
 }