示例#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
 public static function setTransition($transitionInfo)
 {
     $criteria = new EMongoCriteria(array('conditions' => array('className' => array('equals' => $transitionInfo['modelName']), 'objectId' => array('equals' => $transitionInfo['modelId']))));
     /** @var WorkflowStates $wfStates  */
     //echo WorkflowStates::model()->count($criteria);
     $wfStates = WorkflowStates::model()->find($criteria);
     if ($wfStates) {
         //VarDumper::dump($wfStates);die();
         if ($transitionInfo['type'] == 'after') {
             $wfStates->lastState = $transitionInfo['stateTo'];
         }
     } else {
         $wfStates = new self();
         $wfStates->className = $transitionInfo['modelName'];
         $wfStates->objectId = $transitionInfo['modelId'];
         $wfStates->transitions = array();
     }
     $wfStates->transitions[] = $transitionInfo;
     $wfStates->updated = time();
     $wfStates->save();
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = WorkflowStates::model()->findByPk(new MongoID($id));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionGetInfo($id)
 {
     /** @var OrderBooking $model  */
     $model = $this->loadModel($id);
     $retArr = $model->attributes;
     $retArr['userDescription'] = $model->userDescription;
     $retArr['bookings'] = array();
     foreach ($model->flightBookers as $flightBooker) {
         $booking = array();
         $booking['status'] = $model->stateAdapter($flightBooker->status);
         $booking['type'] = 'Авиа';
         $booking['className'] = get_class($flightBooker);
         $booking['modelId'] = $flightBooker->id;
         $booking['description'] = $flightBooker->fullDescription;
         if ($flightBooker->price) {
             $booking['price'] = $flightBooker->price;
         } else {
             if ($flightBooker->flightVoyage->price) {
                 $booking['price'] = $flightBooker->flightVoyage->price;
             }
         }
         //! FIXME use YII urlgen
         $wfStates = WorkflowStates::model()->findByAttributes(array('className' => 'FlightBooker', 'objectId' => $flightBooker->id));
         if (count($wfStates) == 1) {
             $booking['wfUrl'] = '/admin/logging/workflowStates#' . $wfStates->_id;
         }
         $retArr['bookings'][] = $booking;
     }
     foreach ($model->hotelBookers as $hotelBooker) {
         $booking = array();
         $booking['status'] = $model->stateAdapter($hotelBooker->status);
         $booking['type'] = 'Отель';
         $booking['description'] = $hotelBooker->fullDescription;
         if ($hotelBooker->price) {
             $booking['price'] = $hotelBooker->price;
         } else {
             if (isset($hotelBooker->hotel)) {
                 if (isset($hotelBooker->hotel->rubPrice)) {
                     $booking['price'] = $hotelBooker->hotel->rubPrice;
                 }
             }
         }
         //! FIXME use YII urlgen
         $wfStates = WorkflowStates::model()->findByAttributes(array('className' => 'HotelBooker', 'objectId' => $hotelBooker->id));
         if (count($wfStates) == 1) {
             $booking['wfUrl'] = '/admin/logging/workflowStates#' . $wfStates->_id;
         }
         $retArr['bookings'][] = $booking;
     }
     echo json_encode($retArr);
 }