Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Room::find()->notDeleted()->with(['hotel', 'roomType']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'hotel_id' => $this->hotel_id, 'room_type_id' => $this->room_type_id, 'date' => $this->date ? strtotime($this->date) : null, 'allotment' => $this->allotment, 'price' => $this->price, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'deleted' => $this->deleted]);
     return $dataProvider;
 }
Exemple #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRoom()
 {
     return $this->hasOne(Room::className(), ['id' => 'room_id']);
 }
Exemple #3
0
 public function getRooms()
 {
     return $this->hasMany(Room::className(), ['id' => 'room_id'])->via('reservations');
 }
 public function actionIndexRss()
 {
     \Yii::$app->response->format = 'rss';
     $provider = new \yii\data\ActiveDataProvider(['query' => \common\models\Room::find(), 'pagination' => ['pageSize' => 20]]);
     return $provider;
 }
Exemple #5
0
 /**
  * Finds the Room model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Room the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Room::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionIndexWithRelationships()
 {
     // 1. Check what parameter of detail has been passed
     $room_id = Yii::$app->request->get('room_id', null);
     $reservation_id = Yii::$app->request->get('reservation_id', null);
     $customer_id = Yii::$app->request->get('customer_id', null);
     // 2. Fill three models: roomSelected, reservationSelected and customerSelected and
     //    Fill three arrays of models: rooms, reservations and customer;
     $roomSelected = null;
     $reservationSelected = null;
     $customerSelected = null;
     if ($room_id != null) {
         $roomSelected = Room::findOne($room_id);
         $rooms = array($roomSelected);
         $reservations = $roomSelected->reservations;
         $customers = $roomSelected->customers;
     } else {
         if ($reservation_id != null) {
             $reservationSelected = Reservation::findOne($reservation_id);
             $rooms = array($reservationSelected->room);
             $reservations = array($reservationSelected);
             $customers = array($reservationSelected->customer);
         } else {
             if ($customer_id != null) {
                 $customerSelected = Customer::findOne($customer_id);
                 $rooms = $customerSelected->rooms;
                 $reservations = $customerSelected->reservations;
                 $customers = array($customerSelected);
             } else {
                 $rooms = Room::find()->all();
                 $reservations = Reservation::find()->all();
                 $customers = Customer::find()->all();
             }
         }
     }
     return $this->render('index-with-relationships', ['roomSelected' => $roomSelected, 'reservationSelected' => $reservationSelected, 'customerSelected' => $customerSelected, 'rooms' => $rooms, 'reservations' => $reservations, 'customers' => $customers]);
 }