Esempio n. 1
0
 public function getId()
 {
     if ($this->flightVoyage) {
         return $this->flightVoyage->getId();
     }
     return $this->_id;
 }
 public function book()
 {
     //if we don't have a flight OR we moved to another flight
     if ($this->getCurrent() == null || $this->getCurrent()->flightVoyage->id != $this->flightVoyage->getId()) {
         //if we don't have a flight AND we moved to another flight
         if ($this->getCurrent() != null and $this->getCurrent()->flightVoyage->id != $this->flightVoyage->getId()) {
             $this->flightBooker = FlightBooker::model()->findByAttributes(array('flightVoyageId' => $this->flightVoyage->getId()));
             if (!$this->flightBooker) {
                 $this->flightBooker = new FlightBooker();
                 $this->flightBooker->flightVoyageId = $this->flightVoyage->getId();
                 $this->flightBooker->flightVoyage = $this->flightVoyage;
                 $this->flightBooker->status = 'enterCredentials';
                 $this->flightBooker->setFlightBookerComponent($this);
                 if (!$this->flightBooker->save()) {
                     VarDumper::dump($this->flightBooker->getErrors());
                 }
             }
             $this->flightBooker->setFlightBookerComponent($this);
         }
         if ($this->flightBooker == null) {
             Yii::trace('New flightBooker to db', 'FlightBookerComponent.book');
             $this->flightBooker = new FlightBooker();
             $this->flightBooker->flightVoyageId = $this->flightVoyage->getId();
             $this->flightBooker->flightVoyage = $this->flightVoyage;
             $this->flightBooker->status = 'enterCredentials';
             $this->flightBooker->setFlightBookerComponent($this);
             if (!$this->flightBooker->save()) {
                 VarDumper::dump($this->flightBooker->getErrors());
             }
         }
     }
     Yii::trace(CVarDumper::dumpAsString($this->flightBooker->getErrors()), 'FlightBookerComponent.book');
     if (!$this->flightBooker->id) {
         $this->flightBooker->id = $this->flightBooker->primaryKey;
     }
     Yii::app()->user->setState('flightVoyageId', $this->flightBooker->flightVoyage->id);
 }