public function populate($roomType, $dates) { $this->roomType = $roomType; foreach ($dates as $date) { $criteria = new CDbCriteria(); $criteria->condition = ':date between dateFrom and dateTo and roomid=:roomId and confirmreservation=true'; $criteria->params = array(":date" => $date, ":roomId" => $this->roomType->id); $result = Reservation::model()->findAll($criteria); $this->reservations[$date] = $result; } }
/** * Test we can update the reservation. */ public function testUpdate() { $this->resetReservationTable(); $this->resetDateTimes(); $reservation = new Reservation(); $reservation->setAttributes(array('roomid' => 1, 'datefrom' => $this->_dateOverlapFrom, 'numberofnights' => $this->_numberofnights)); $reservation->save(false); $newDateTo = DateTime::createFromFormat('Y-m-d', $this->_dateOverlapToObj->format('Y-m-d')); $newDateTo->add(new DateInterval('P10D')); $reservation = Reservation::model()->findByPk($reservation->getAttribute('id')); $reservation->setAttribute('dateto', $newDateTo->format('Y-m-d')); $reservation->setAttribute('confirmreservation', true); //must run validation rules $this->assertTrue($reservation->save()); $reservation = Reservation::model()->findByPk($reservation->getAttribute('id')); $this->assertEquals($newDateTo->format('Y-m-d'), $reservation->dateto); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'payment' page. */ public function actionCreate() { $model = new ReservationDetails(); $model->reservation = Reservation::model()->findByPk(Yii::app()->session['reservationid']); $model->reservation->setAttribute('confirmreservation', true); if (isset($_POST['ReservationDetails'])) { if ($model->reservation->save()) { $model->attributes = $_POST['ReservationDetails']; $model->setAttribute('reservationid', $model->reservation->id); if ($model->save()) { if (!Yii::app()->user->isGuest) { $this->redirect(array('reservation/update', 'id' => $model->reservation->id)); } else { $this->redirect(array('viewPayment')); } } } else { throw new CHttpException(500, 'Unable to save reservation'); } } $this->render('create', array('model' => $model)); }
public function actionCancel($id) { $reservation = Reservation::model()->findByPk($id); if (isset($reservation)) { $reservation->status = 'CANCELED'; $reservation->save(); } $this->redirect(Yii::app()->request->getBaseUrl(true) . '#cuenta'); }
/** * 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 = Reservation::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }