public function run($key) { $parts = explode('_', $key); $cacheId = $parts[0]; $searchId = $parts[1]; $resultId = $parts[2]; $resultSearch = Yii::app()->cache->get('hotelResult' . $cacheId); //TODO: need working without cache, if state more then enterCredentials if (!$resultSearch) { $hotelBooker = HotelBooker::model()->findByAttributes(array('hotelResultKey' => 'hotel_key' . $key)); if ($hotelBooker) { $foundedHotel = unserialize($hotelBooker->hotelInfo); $foundedHotel->cacheId = $cacheId; } } else { $foundedHotel = null; foreach ($resultSearch['hotels'] as $hotel) { if ($hotel->resultId == $resultId) { $foundedHotel = $hotel; $foundedHotel->cacheId = $cacheId; break; } } if (!$foundedHotel) { $hotelBooker = HotelBooker::model()->findByAttributes(array('hotelResultKey' => 'hotel_key' . $key)); if ($hotelBooker) { $foundedHotel = unserialize($hotelBooker->hotelInfo); $foundedHotel->cacheId = $cacheId; } } } if (isset($foundedHotel) and $foundedHotel) { Yii::app()->hotelBooker->hotel = $foundedHotel; Yii::app()->hotelBooker->book(); $status1 = Yii::app()->hotelBooker->current->swGetStatus()->getId(); $actionName = 'stage' . ucfirst($status1); if ($action = $this->getController()->createAction($actionName)) { $action->execute(); } else { Yii::app()->hotelBooker->{$actionName}(); } } else { throw new CHttpException(500, 'You request expired hotel not found'); } }
public function forHotelItem($item) { $hotelBooker = HotelBooker::model()->findByPk($item->hotelBookerId); $hotelPassports = HotelBookingPassport::model()->findAllByAttributes(array('hotelBookingId' => $item->hotelBookerId)); if ($hotelBooker) { $loop = true; $count = 0; while ($loop) { $voucherInfo = $this->hotelClient->voucher($hotelBooker->orderId); $voucherAvailable = true; //VarDumper::dump($voucherInfo); //die(); //UtilsHelper::soapObjectsArray($voucherInfo->voucherAvailable); foreach ($voucherInfo->voucherAvailable as $avail) { $voucherAvailable = $voucherAvailable && ($avail ? $avail != '0' ? true : false : false); } if ($voucherAvailable) { $loop = false; break; } else { $count++; if ($count > 2) { $loop = false; return false; break; } sleep(10); } } $hotelInfo = $this->hotelClient->hotelDetail($hotelBooker->hotel->hotelId); $this->hotelClient->hotelSearchDetails($hotelBooker->hotel); $pnr = implode(', ', $voucherInfo->references); if ($voucherInfo->suppliers) { $pnr .= ' (' . implode(', ', $voucherInfo->suppliers) . ')'; } if (!$this->orderBookingId) { $this->orderBookingId = $hotelBooker->orderBookingId; $this->orderBooking = OrderBooking::model()->findByPk($this->orderBookingId); } $pdfFileName = $this->controller->renderPdf('ticketHotel', array('type' => 'hotel', 'ticket' => $hotelBooker->hotel, 'bookingId' => $this->orderBooking->readableId, 'pnr' => $pnr, 'hotelPassports' => $hotelPassports, 'hotelInfo' => $hotelInfo)); return array('realName' => $pdfFileName, 'visibleName' => "hotel_{$hotelBooker->hotel->city->code}_" . date('Ymd', strtotime($hotelBooker->hotel->checkIn)) . ".pdf"); } }
public function transferMoney() { $bookingModel = $this->getOrderBooking(); /** @var FlightBooker[] $flightBookers */ $flightBookers = FlightBooker::model()->findAllByAttributes(array('orderBookingId' => $bookingModel->primaryKey)); foreach ($flightBookers as $flightBooker) { $status = $flightBooker->status; if (strpos($status, '/') !== false) { $status = substr($status, strpos($status, '/') + 1); } $flightBookerComponent = new FlightBookerComponent(); $flightBookerComponent->setFlightBookerFromId($flightBooker->id); $flightBookerComponent->status('transferMoney'); //$flightBooker->timeout; } $hotelBookers = HotelBooker::model()->findAllByAttributes(array('orderBookingId' => $bookingModel->primaryKey)); foreach ($hotelBookers as $hotelBooker) { $status = $hotelBooker->status; if (strpos($status, '/') !== false) { $status = substr($status, strpos($status, '/') + 1); } $hotelBookerComponent = new HotelBookerComponent(); $hotelBookerComponent->setHotelBookerFromId($hotelBooker->id); $hotelBookerComponent->status('transferMoney'); } }
public function getChannel() { $parts = explode('_', $this->channel); $ucFirstParts = array(); foreach ($parts as $part) { $ucFirstParts[] = ucfirst($part); } $className = 'Payments_Channel_' . implode('_', $ucFirstParts); Yii::import("common.extensions.payments.models." . $className); $flightBookers = FlightBooker::model()->findAllByAttributes(array('billId' => $this->id)); $hotelBookers = HotelBooker::model()->findAllByAttributes(array('billId' => $this->id)); $bookers = Yii::app()->payments->preProcessBookers(array_merge($flightBookers, $hotelBookers)); if (count($bookers) > 1) { throw new Exception("More than 1 processed booker for bill"); } $booker = $bookers[0]; if (!$booker) { # Would never happen in theory throw new Exception("No booker for given bill"); } # FIXME passing this is hella retarded return new $className($this, $booker); }
public function getPassportsFromDb() { $hotelBookerId = $this->hotelBookerId; $hotelBooker = HotelBooker::model()->findByPk($hotelBookerId); if (!$hotelBooker) { return array(); } return HotelBookingPassport::model()->findAll(array('condition' => 'hotelBookingId=:hbid', 'params' => array(':hbid' => $hotelBooker->id), 'order' => 'id')); }
public function setHotelBookerFromId($hotelBookerId) { $this->hotelBooker = HotelBooker::model()->findByPk($hotelBookerId); if (!$this->hotelBooker) { throw new CException('HotelBooker with id ' . $hotelBookerId . ' not found'); } $this->hotelBooker->setHotelBookerComponent($this); $this->hotel = unserialize($this->hotelBooker->hotelInfo); $this->hotelBooker->hotel = $this->hotel; }