コード例 #1
0
 public function onAfterSave($event)
 {
     //CVarDumper::dump(get_class_vars(get_class($event->sender)));
     $transition = array();
     $transition['type'] = 'afterSave';
     $transition['modelName'] = get_class($event->sender);
     $transition['modelId'] = $event->sender->primaryKey;
     $transition['state'] = $event->sender->{$this->statusAttribute};
     $transition['time'] = date('Y-m-d H:i:s');
     $transition['requestIds'] = SWLogActiveRecord::$requestIds;
     SWLogActiveRecord::$requestIds = array();
     //CVarDumper::dump($transition);
     WorkflowStates::setTransition($transition);
     //return parent::afterSave();
 }
コード例 #2
0
ファイル: HotelBooker.php プロジェクト: niranjan2m/Voyanga
 public function afterSave()
 {
     if (!$this->statusChanged) {
         return parent::afterSave();
     }
     $method = 'stage' . ucfirst($this->swGetStatus()->getId());
     if (isset(Yii::app()->controller) and $action = Yii::app()->controller->createAction($method)) {
         $action->execute();
     } elseif (method_exists(Yii::app()->hotelBooker, $method) or method_exists($this->hotelBookerComponent, $method)) {
         if ($this->hotelBookerComponent) {
             $this->hotelBookerComponent->{$method}();
             return parent::afterSave();
         } elseif (Yii::app()->hotelBooker) {
             Yii::app()->hotelBooker->{$method}();
             return parent::afterSave();
         }
         throw new CException('Unknown ' . $method . ' of FlightBooker');
     }
 }
コード例 #3
0
 public function actionGetInfo($id)
 {
     $wfStates = WorkflowStates::model()->findByPk(new MongoID($id));
     Yii::import('site.common.components.hotelBooker.*');
     //Yii::import('hotelBooker.models.*');
     //Yii::import('hotelBooker.*');
     Yii::import('site.common.modules.hotel.models.*');
     $modelObject = SWLogActiveRecord::model($wfStates->className)->findByPk($wfStates->objectId);
     //VarDumper::dump($modelObject);
     $desc = '';
     $stages = array();
     $lastStageName = '';
     $lastStageId = 0;
     foreach ($wfStates->transitions as $i => $transition) {
         if ($transition['type'] == 'before') {
             if (count($stages) == 0) {
                 $stages[] = array('stageName' => $transition['stateFrom'], 'requestIds' => array());
             }
             $n = count($stages);
             if (isset($transition['requestIds'])) {
                 if (count($transition['requestIds']) > 0) {
                     $stages[$n - 1]['requestIds'] = $transition['requestIds'];
                     foreach ($stages[$n - 1]['requestIds'] as $j => $reqId) {
                         $requestModel = EMongoDocument::model($reqId['class'])->findByAttributes(array($reqId['keyName'] => $reqId['key']));
                         $stages[$n - 1]['requestIds'][$j]['methodName'] = $requestModel->methodName;
                         $stages[$n - 1]['requestIds'][$j]['description'] = $requestModel->requestDescription;
                     }
                 }
             }
             $stages[] = array('stageName' => $transition['stateTo'], 'requestIds' => array(), 'time' => $transition['time']);
         } elseif ($transition['type'] == 'afterSave') {
             if (count($stages) == 0) {
                 $stages[] = array('stageName' => $transition['state'], 'requestIds' => $transition['requestIds']);
             }
             $n = count($stages);
             if (isset($transition['requestIds'])) {
                 if (count($transition['requestIds']) > 0) {
                     $stages[$n - 1]['requestIds'] = $transition['requestIds'];
                     foreach ($stages[$n - 1]['requestIds'] as $j => $reqId) {
                         $requestModel = EMongoDocument::model($reqId['class'])->findByAttributes(array($reqId['keyName'] => $reqId['key']));
                         $stages[$n - 1]['requestIds'][$j]['methodName'] = $requestModel->methodName;
                         $stages[$n - 1]['requestIds'][$j]['description'] = $requestModel->requestDescription;
                     }
                 }
             }
             //$stages[] = array('stageName'=>$transition['stateTo'],'requestIds'=>array(),'time'=>$transition['time']);
         }
     }
     //VarDumper::dump($stages);
     $retArr = array('stages' => $stages, 'class' => $wfStates->className, 'objectId' => $wfStates->objectId);
     /*$widget = new CTextHighlighter();
       $widget->language = 'xml';
       $retArr['methodName'] = $model->methodName;
       $retArr['requestXml'] = $widget->highlight($model->requestXml);
       $retArr['responseXml'] = $widget->highlight($model->responseXml);
       $retArr['timestamp'] = date("Y-m-d H:i:s",$model->timestamp);
       $retArr['executionTime'] = Yii::app()->format->formatNumber($model->executionTime);
       $retArr['errorDescription'] = $model->errorDescription;*/
     //$retArr['responseXml'] = $model->responseXml;
     //echo $model->requestXml);
     echo json_encode($retArr);
     die;
 }
コード例 #4
0
 public function stageTicketingRepeat()
 {
     $this->status('ticketingError');
     return;
     //pass;
     $this->flightBooker->tryCount++;
     $this->flightBooker->save();
     if ($this->flightBooker->tryCount > 3) {
         $this->status('ticketingError');
     } else {
         $flightTicketingParams = new FlightTicketingParams();
         $flightTicketingParams->nemoBookId = $this->flightBooker->nemoBookId;
         $flightTicketingParams->pnr = $this->flightBooker->pnr;
         /** @var FlightTicketingResponse $flightTicketingResponse  */
         $flightTicketingResponse = Yii::app()->gdsAdapter->FlightTicketing($flightTicketingParams);
         SWLogActiveRecord::$requestIds = array_merge(SWLogActiveRecord::$requestIds, GDSNemoAgency::$requestIds);
         GDSNemoAgency::$requestIds = array();
         if ($flightTicketingResponse->status == 1) {
             $this->status('ticketReady');
         } else {
             //TODO: переставить стутус через время T + считать количество раз.
             $res = Yii::app()->cron->add(time() + appParams('flight_repeat_time'), 'flightbooking', 'ChangeState', array('flightBookerId' => $this->flightBooker->id, 'newState' => 'ticketingRepeat'));
             if ($res) {
                 $this->flightBooker->saveTaskInfo('ticketingRepeat', $res);
                 return true;
             }
             //$this->status('ticketingRepeat');
         }
     }
 }
コード例 #5
0
 public function stageTicketingRepeat()
 {
     echo "event ticketing repeat {$this->hotelBooker->tryCount}\n";
     $this->hotelBooker->tryCount++;
     echo "after ++ {$this->hotelBooker->tryCount}\n";
     //return;
     //$this->hotelBooker->save(); рекурсия
     if ($this->hotelBooker->tryCount > 3) {
         $this->status('ticketingError');
         return;
     }
     $hotelOrderParams = new HotelOrderParams();
     $hotelOrderParams->hotel = $this->hotel;
     $contactName = '';
     foreach ($this->hotelBooker->hotelBookingPassports as $passport) {
         $roomer = new Roomer();
         $roomer->setFromHotelBookingPassport($passport);
         $roomer->roomId = $passport->roomKey;
         if (!$contactName) {
             $contactName = $roomer->fullName;
         }
         $hotelOrderParams->roomers[] = $roomer;
     }
     $hotelOrderParams->contactPhone = $this->hotelBooker->orderBooking->phone;
     $hotelOrderParams->contactEmail = $this->hotelBooker->orderBooking->email;
     $hotelOrderParams->contactName = $contactName;
     $hotelBookClient = new HotelBookClient();
     if ($this->hotelBooker->orderId) {
         $orderInfo = new HotelOrderResponse();
         $orderInfo->orderId = $this->hotelBooker->orderId;
     } else {
         $orderInfo = $hotelBookClient->addOrder($hotelOrderParams);
         SWLogActiveRecord::$requestIds = array_merge(SWLogActiveRecord::$requestIds, HotelBookClient::$requestIds);
         HotelBookClient::$requestIds = array();
     }
     if ($orderInfo->orderId) {
         $this->hotelBooker->orderId = $orderInfo->orderId;
         $confirmInfo = $hotelBookClient->confirmOrder($orderInfo->orderId);
         SWLogActiveRecord::$requestIds = array_merge(SWLogActiveRecord::$requestIds, HotelBookClient::$requestIds);
         HotelBookClient::$requestIds = array();
         if (!$confirmInfo->error) {
             $this->status('ticketReady');
         } else {
             echo $this->hotelBooker->id;
             $res = Yii::app()->cron->add(time() + appParams('hotel_repeat_time'), 'hotelbooking', 'ChangeState', array('hotelBookerId' => $this->hotelBooker->id, 'newState' => 'ticketingRepeat'));
             if ($res) {
                 $this->hotelBooker->saveTaskInfo('repeatTime', $res);
             }
             //$this->status('ticketingRepeat');
         }
     } else {
         $res = Yii::app()->cron->add(time() + appParams('hotel_repeat_time'), 'hotelbooking', 'ChangeState', array('hotelBookerId' => $this->hotelBooker->id, 'newState' => 'ticketingRepeat'));
         if ($res) {
             $this->hotelBooker->saveTaskInfo('repeatTime', $res);
         }
         //$this->status('ticketingRepeat');
     }
 }