public function actionReservationsOfTheDay($currentDate = null)
 {
     if ($currentDate == null) {
         $currentDate = date('Y-m-d');
     }
     $models = \common\models\Reservation::findAll(['reservation_date' => $currentDate]);
     \Yii::$app->mailer->compose(['html' => 'reservationsOfTheDay-html', 'text' => 'reservationsOfTheDay-text'], ['models' => $models, 'currentDate' => $currentDate])->setTo('*****@*****.**')->setSubject("reservations of the day" . $currentDate)->send();
 }
 public function actionIndexWithRooms()
 {
     $reservations = \common\models\Reservation::find()->all();
     $outData = [];
     foreach ($reservations as $r) {
         $outData[] = array_merge($r->attributes, ['room' => $r->room->attributes]);
     }
     return $outData;
 }
 public function actionIndexWithRooms()
 {
     $reservations = Reservation::find()->all();
     $out = [];
     foreach ($reservations as $r) {
         $out[] = array_merge($r->attributes, ['room' => $r->room->attributes]);
     }
     return $out;
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReservations()
 {
     return $this->hasMany(Reservation::className(), ['customer_id' => 'id']);
 }
 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]);
 }