示例#1
0
 public function actionMainform($isFancy = 0)
 {
     $model = new SimpleformModel();
     $model->scenario = 'forrent';
     if (isset($_POST['SimpleformModel']) && BlockIp::checkAllowIp(Yii::app()->controller->currentUserIpLong)) {
         $request = Yii::app()->request;
         $isForBuy = $request->getPost('isForBuy', 0);
         $model->attributes = $_POST['SimpleformModel'];
         if ($isForBuy) {
             $model->scenario = 'forbuy';
         }
         if ($model->validate()) {
             if (!$isForBuy) {
                 $model->time_inVal = $this->getI18nTimeIn($model->time_in);
                 $model->time_outVal = $this->getI18nTimeOut($model->time_out);
             }
             $types = Apartment::getI18nTypesArray();
             $model->type = $types[$model->type];
             $notifier = new Notifier();
             if (!$isForBuy) {
                 $notifier->raiseEvent('onNewSimpleBookingForRent', $model);
             } else {
                 $notifier->raiseEvent('onNewSimpleBookingForBuy', $model);
             }
             Yii::app()->user->setFlash('success', tt('Operation successfully complete. Your order will be reviewed by administrator.'));
         }
     }
     $user = null;
     if (!Yii::app()->user->isGuest) {
         $user = User::model()->findByPk(Yii::app()->user->getId());
     }
     $type = Apartment::getTypesWantArray();
     if ($isFancy) {
         $this->excludeJs();
         $this->renderPartial('simpleform', array('model' => $model, 'type' => $type, 'user' => $user, 'isFancy' => true), false, true);
     } else {
         $this->render('simpleform', array('model' => $model, 'type' => $type, 'user' => $user, 'isFancy' => false));
     }
 }
示例#2
0
 public function actionBookingform($isFancy = 0)
 {
     Yii::app()->getModule('apartments');
     $this->modelName = 'Apartment';
     $apartment = $this->loadModel();
     $this->modelName = 'Booking';
     $booking = new Booking();
     $booking->scenario = 'bookingform';
     if (isset($_POST['Booking'])) {
         $booking->attributes = $_POST['Booking'];
         $booking->apartment_id = $apartment->id;
         if ($booking->validate()) {
             $booking->time_inVal = $this->getI18nTimeIn($booking->time_in);
             $booking->time_outVal = $this->getI18nTimeOut($booking->time_out);
             if (issetModule('bookingtable')) {
                 Bookingtable::addRecord($booking);
             }
             $notifier = new Notifier();
             $types = Apartment::getI18nTypesArray();
             $booking->type = $types[Apartment::TYPE_RENTING];
             $ownerApartment = User::model()->findByPk($apartment->owner_id);
             $booking->ownerEmail = $ownerApartment->email;
             $notifier->raiseEvent('onNewBooking', $booking, array('user' => $ownerApartment));
             Yii::app()->user->setFlash('success', tt('Operation successfully complete. Your order will be reviewed by owner.'));
             $this->redirect($apartment->getUrl());
         }
     }
     $user = null;
     if (!Yii::app()->user->isGuest) {
         $user = User::model()->findByPk(Yii::app()->user->getId());
     }
     if ($isFancy) {
         $this->excludeJs();
         $this->renderPartial('bookingform', array('apartment' => $apartment, 'model' => $booking, 'isFancy' => true, 'user' => $user), false, true);
     } else {
         $this->render('bookingform', array('apartment' => $apartment, 'model' => $booking, 'isFancy' => false, 'user' => $user));
     }
 }