public function actionMultipleGrid()
 {
     /**
      * Reservations
      */
     $reservationsQuery = Reservation::find();
     $reservationsSearchModel = new ReservationSearch();
     if (isset($_GET['ReservationSearch'])) {
         $reservationsSearchModel->load(Yii::$app->request->get());
         $reservationsQuery->joinWith(['customer']);
         $reservationsQuery->andFilterWhere(['LIKE', 'customer.name', $reservationsSearchModel->getAttribute('customer.name')]);
         $reservationsQuery->andFilterWhere(['LIKE', 'customer.surname', $reservationsSearchModel->getAttribute('customer.surname')]);
         $reservationsQuery->andFilterWhere(['id' => $reservationsSearchModel->id, 'customer_id' => $reservationsSearchModel->customer_id, 'room_id' => $reservationsSearchModel->room_id, 'price_per_day' => $reservationsSearchModel->price_per_day]);
     }
     $resultQueryAveragePricePerDay = $reservationsQuery->average('price_per_day');
     $dataProvider = new ActiveDataProvider(['query' => $reservationsQuery, 'sort' => ['sortParam' => 'reservations-sort-param'], 'pagination' => ['pageSize' => 10, 'pageParam' => 'reseravations-page-param']]);
     $reservationsDataProvider = new ActiveDataProvider(['query' => $reservationsQuery, 'sort' => ['sortParam' => 'reservations-sort-param'], 'pagination' => ['pageSize' => 10, 'pageParam' => 'reservations-page-param']]);
     /**
      * Rooms
      */
     $roomsQuery = Room::find();
     $roomsSearchModel = new Room();
     if (isset($_GET['Room'])) {
         $roomsSearchModel->load(Yii::$app->request->get());
         $roomsQuery->andFilterWhere(['id' => $roomsSearchModel->id, 'floor' => $roomsSearchModel->floor, 'room_number' => $roomsSearchModel->room_number, 'has_conditioner' => $roomsSearchModel->has_conditioner, 'has_phone' => $roomsSearchModel->has_phone, 'has_tv' => $roomsSearchModel->has_tv, 'available_from' => $roomsSearchModel->available_from]);
     }
     $roomsDataProvider = new ActiveDataProvider(['query' => $roomsQuery, 'sort' => ['sortParam' => 'rooms-sort-param'], 'pagination' => ['pageSize' => 10, 'pageParam' => 'rooms-page-param']]);
     return $this->render('multipleGrid', ['reservationsDataProvider' => $reservationsDataProvider, 'reservationsSearchModel' => $reservationsSearchModel, 'roomsDataProvider' => $roomsDataProvider, 'roomsSearchModel' => $roomsSearchModel, 'resultQueryAveragePricePerDay' => $resultQueryAveragePricePerDay]);
 }
Example #2
0
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['detail', 'id' => $model->id]);
     }
     return $this->render('detail', compact('model'));
 }
 /**
  * Creates a new Room model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Person model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $modelPerson = new Person();
     $modelsHouse = [new House()];
     $modelsRoom = [[new Room()]];
     if ($modelPerson->load(Yii::$app->request->post())) {
         $modelsHouse = Model::createMultiple(House::classname());
         Model::loadMultiple($modelsHouse, Yii::$app->request->post());
         // validate person and houses models
         $valid = $modelPerson->validate();
         $valid = Model::validateMultiple($modelsHouse) && $valid;
         if (isset($_POST['Room'][0][0])) {
             foreach ($_POST['Room'] as $indexHouse => $rooms) {
                 foreach ($rooms as $indexRoom => $room) {
                     $data['Room'] = $room;
                     $modelRoom = new Room();
                     $modelRoom->load($data);
                     $modelsRoom[$indexHouse][$indexRoom] = $modelRoom;
                     $valid = $modelRoom->validate();
                 }
             }
         }
         if ($valid) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelPerson->save(false)) {
                     foreach ($modelsHouse as $indexHouse => $modelHouse) {
                         if ($flag === false) {
                             break;
                         }
                         $modelHouse->person_id = $modelPerson->id;
                         if (!($flag = $modelHouse->save(false))) {
                             break;
                         }
                         if (isset($modelsRoom[$indexHouse]) && is_array($modelsRoom[$indexHouse])) {
                             foreach ($modelsRoom[$indexHouse] as $indexRoom => $modelRoom) {
                                 $modelRoom->house_id = $modelHouse->id;
                                 if (!($flag = $modelRoom->save(false))) {
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelPerson->id]);
                 } else {
                     $transaction->rollBack();
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['modelPerson' => $modelPerson, 'modelsHouse' => empty($modelsHouse) ? [new House()] : $modelsHouse, 'modelsRoom' => empty($modelsRoom) ? [[new Room()]] : $modelsRoom]);
 }
 /**
  * Creates a new Room model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = 'admin';
     $model = new Room();
     if ($model->load(Yii::$app->request->post())) {
         $model->photo = $model->uploadMultiple($model, 'room_img');
         $model->save();
         return $this->redirect(['view', 'id' => $model->roomid]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #6
0
 public function actionCreate()
 {
     $model = new Room();
     $modelCanSave = false;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelCanSave = true;
         // $model->fileImage = UploadedFile::getInstance($model,'fileImage');
         // if($model->fileImage){
         //     $model->fileImage->saveAs(Yii::getAlias('@uploadedfiledir').'/'.$model->fileImage->baseName.'.'.$model->fileImage->extension);
         // }
     }
     return $this->render('create', ['model' => $model, 'modelSaved' => $modelCanSave]);
 }
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['detail', 'id' => $model->id]);
     }
     // if (isset($POST['Room'])) {
     //     $model->attributes = $_POST['Room'];
     //
     //     if ($model->save()) {
     //         return $this->redirect(['view', 'id' => $model->id]);
     //     }
     // }
     return $this->render('create', ['model' => $model]);
 }
Example #8
0
 public function actionCreate()
 {
     $model = new Room();
     if ($model->load(Yii::$app->request->post())) {
         $image = UploadedFile::getInstance($model, 'fileImage');
         if ($image) {
             $ext = $image->extension;
             $name = Yii::$app->security->generateRandomString(11);
             if ($image->saveAs(Yii::getAlias('@uploadedFilesDir/' . $name . '.' . $ext))) {
                 $model->fileImage = "{$name}.{$ext}";
             }
         }
         if ($model->save()) {
             $this->redirect(['rooms/index']);
         }
     }
     return $this->render('create', ['model' => $model, 'type' => 'Create']);
 }
 public function actionGrid()
 {
     $queryReservation = Reservation::find();
     $queryRoom = Room::find();
     $searchReservation = new ReservationSearch();
     $searchRoom = new Room();
     if (isset($_GET['ReservationSearch'])) {
         $searchReservation->load(Yii::$app->request->get());
         $queryReservation->joinWith(['customer']);
         $queryReservation->andFilterWhere(['LIKE', 'customer.surname', $searchReservation->getAttribute('customer.surname')]);
         $queryReservation->andFilterWhere(['id' => $searchReservation->id, 'room_id' => $searchReservation->room_id, 'customer_id' => $searchReservation->customer_id, 'price_per_day' => $searchReservation->price_per_day]);
     }
     $avg = $queryReservation->average('price_per_day');
     if (isset($_GET['Room'])) {
         $searchRoom->load(Yii::$app->request->get());
         $queryRoom->andFilterWhere(['id' => $searchRoom->id, 'floor' => $searchRoom->floor, 'room_number' => $searchRoom->room_number, 'has_conditioner' => $searchRoom->has_conditioner, 'has_tv' => $searchRoom->has_tv, 'has_phone' => $searchRoom->has_phone, 'available_from' => $searchRoom->available_from, 'price_per_day' => $searchRoom->price_per_day, 'description' => $searchRoom->description]);
     }
     $dataReservation = new ActiveDataProvider(['query' => $queryReservation, 'sort' => ['sortParam' => 'reservations_sort_param'], 'pagination' => ['pageSize' => 3, 'pageParam' => 'reservations_page_param']]);
     $dataRoom = new ActiveDataProvider(['query' => $queryRoom, 'sort' => ['sortParam' => 'rooms_sort_param'], 'pagination' => ['pageSize' => 3, 'pageParam' => 'rooms_sort_param']]);
     return $this->render('grid', ['dataReservation' => $dataReservation, 'dataRoom' => $dataRoom, 'searchReservation' => $searchReservation, 'searchRoom' => $searchRoom, 'averagePrice' => $avg]);
 }