public function testCreate()
 {
     $connection = Yii::app()->db;
     $sql = "delete from reservation";
     $command = $connection->createCommand($sql);
     $command->execute();
     $dateOverlapFromObj = new DateTime();
     $dateOverlapFrom = $dateOverlapFromObj->format('Y-m-d');
     $reservation = new Reservation();
     $reservation->setAttributes(array('roomid' => 1, 'datefrom' => $dateOverlapFrom, 'numberofnights' => 10, 'confirmreservation' => true));
     $id = $reservation->save();
     $reservationdetails = new Reservationdetails();
     $reservationdetails->setAttributes(array('reservationid' => $reservation->getAttribute('id'), 'title' => "Mr", 'firstname' => "John", 'lastname' => "Smith", 'contactnumber' => "0123456789", 'emailaddress' => "*****@*****.**", 'city' => "City", 'county' => "County", 'country' => "UK", 'postcode' => "ab12 4cd", 'postaddress' => 'Test postal address', 'otherinfo' => "Test"));
     $this->assertTrue($reservationdetails->save());
     return $reservationdetails;
 }
Пример #2
0
 /**
  * 
  * Populates our temporary table with the number of rooms allocated on a particular day.
  * @param Reservation $reservation
  */
 private function updateRoomCounts($reservation)
 {
     $bookingid = $reservation->getAttribute('bookingid');
     $datefrom = $reservation->getAttribute('datefrom');
     $dateto = $reservation->getAttribute('dateto');
     $roomid = $reservation->getAttribute('roomid');
     $sql = "SELECT date(`datefrom`)as datefrom,date(`dateto`)as dateto FROM reservation WHERE ";
     $sql .= $this->GetOverlapCheckSQL();
     $sql .= " and roomid=:roomid";
     $sql .= " and confirmreservation=true";
     /**
      * We're updating a reservation, make sure we don't include this in the search.
      */
     if ($reservation->getAttribute('id')) {
         $sql .= " and id != :reservationid ";
     }
     $command = $this->_connection->createCommand($sql);
     $command->bindParam(":datefrom", $datefrom);
     $command->bindParam(":dateto", $dateto);
     $command->bindParam(":roomid", $roomid);
     if ($reservation->getAttribute('id')) {
         $id = $reservation->getAttribute('id');
         $command->bindParam(":reservationid", $id);
     }
     $rows = $command->queryAll();
     if (empty($rows)) {
         return false;
     }
     /**
      * Make sure we get a count populated for all the days inbetween our search date.
      */
     $sql = "UPDATE tempreservationtable SET roomcount=roomcount+1 WHERE reserveddate=:reserveddate";
     $command = $this->_connection->createCommand($sql);
     foreach ($rows as $row) {
         $searchDate = $row['datefrom'];
         while (strtotime($searchDate) <= strtotime($row['dateto'])) {
             $command->bindParam(":reserveddate", $searchDate, PDO::PARAM_STR);
             $command->execute();
             $searchDate = strtotime('+1 day', strtotime($searchDate));
             $searchDate = date('Y-m-j', $searchDate);
         }
     }
 }