コード例 #1
0
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
コード例 #2
0
function bookingManager($bookingData = array())
{
    try {
        $bookingManager = BookingManager::getInstance();
        $bookingManager->setBookingData($bookingData);
        return $bookingManager;
    } catch (Exception $e) {
        print "<strong>The BookingManager plugin threw an error</strong><br>" . $e->getMessage();
    }
}
コード例 #3
0
function __autoload($className)
{
    include_once "./" . $className . ".class.php";
}
$room = new SingleRoom(1408, 99);
$guest = new Guest("Svetlin", "Nakov", 8003224277);
$startDate = strtotime("24.10.2014");
$endDate = strtotime("26.10.2014");
$reservation = new Reservation($startDate, $endDate, $guest);
BookingManager::bookRoom($room, $reservation);
echo $room;
echo $reservation;
$rooms = [new Bedroom(11, 1100), new SingleRoom(12, 59), new Apartment(13, 599), new Bedroom(14, 250), new Apartment(15, 3432), new SingleRoom(16, 23.66), new Apartment(17, 120)];
BookingManager::bookRoom($rooms[0], $reservation);
BookingManager::bookRoom($rooms[0], $reservation);
BookingManager::bookRoom($rooms[1], $reservation);
// Filter the array by bedrooms and apartments with a price less or equal to 250.00
$filteredByTypeAndPrice = array_filter($rooms, function (Room $room) {
    if ($room->getPrice() <= 250 && ($room instanceof Bedroom || $room instanceof Apartment)) {
        return true;
    }
    return false;
});
echo "</br><strong>Bedrooms and apartments with price of 250 or less:</strong></br>";
foreach ($filteredByTypeAndPrice as $room) {
    echo $room . "</br>";
}
// Filter the array by all rooms with a balcony
$roomsWithBalcony = array_filter($rooms, function (Room $room) {
    if ($room->getHasBalcony() === true) {
        return true;
コード例 #4
0
$room = new SingleRoom(1408, 99);
$guest = new Guest("Svetlin", "Nakov", "8003224277");
$startDate = "24.10.2014";
$endDate = "26.10.2014";
$reservation = new Reservation($guest, $startDate, $endDate);
BookingManager::bookRoom($room, $reservation);
echo PHP_EOL;
$gosho = new Guest("Gosho", "Goshev", "3224277");
$reservation1 = new Reservation($gosho, "25.10.2014", "28.10.2014");
try {
    // throws EReservationException
    BookingManager::bookRoom($room, $reservation1);
} catch (EReservationException $ex) {
    echo $ex->getMessage() . PHP_EOL;
}
BookingManager::bookRoom($apartment, $reservation1);
echo PHP_EOL . PHP_EOL;
$roomsArray = [$apartment, $room, new Bedroom(155, 60), new Apartment(102, 120), new SingleRoom(666, 400), new Bedroom(9999, 350)];
$cheapBedroomAndApartments = array_filter($roomsArray, function ($room) {
    return (get_class($room) == "Bedroom" || get_class($room) == "Apartment") && $room->getRoomInfo()->getPrice() <= 250;
});
//print_r($cheapBedroomAndApartments);
$roomsWithBalcony = array_filter($roomsArray, function ($room) {
    return $room->getRoomInfo()->getHasBalcony();
});
//print_r($roomsWithBalcony);
$roomsWithBathtub = array_filter($roomsArray, function ($room) {
    return strpos($room->getRoomInfo()->getExtras(), 'bathtub') !== false;
});
//print_r($roomsWithBathtub);
$freeApartments = array_filter($roomsArray, function ($room) {
    echo $value['title'];
    ?>


      </option>
      <?php 
}
?>
    </select>
    <!-- The Description of our products are shown if a product is selected -->
    <div id="description_container">
      <?php 
foreach ($product_array as $key => $value) {
    ?>
      <div id="product_<?php 
    echo BookingManager::seoUrl($value['title']);
    ?>
" style="display: none;">
        <p><?php 
    echo $value['description'];
    ?>
</p>
        <p>Price: <?php 
    echo number_format($value['price'], 2, '.', ' ');
    ?>
 <?php 
    echo $page->currency()->text();
    ?>
</p>
      </div>
      <?php 
コード例 #6
0
 $guests[1] = new Guest("Svetlin", "Nakov", 8003224277.0);
 $guests[2] = new Guest("Ivan", "Ivanov", 8003221111.0);
 $guests[3] = new Guest("Petar", "Petrov", 1234567890);
 $reservations[1] = new Reservation(date_create("24.10.2014"), date_create("26.10.2014"), $guests[1]);
 $reservations[2] = new Reservation(date_create("01.02.2015"), date_create("05.02.2015"), $guests[2]);
 $reservations[3] = new Reservation(date_create("16.07.2010"), date_create("22.07.2010"), $guests[1]);
 $reservations[4] = new Reservation(date_create("13.12.2013"), date_create("29.12.2013"), $guests[3]);
 $rooms[101] = new SingleRoom(101, 25);
 $rooms[113] = new SingleRoom(113, 42.1);
 $rooms[306] = new Bedroom(306, 104.2);
 $rooms[333] = new Bedroom(333, 93.09999999999999);
 $rooms[501] = new Apartment(501, 1343.12);
 $rooms[505] = new Apartment(505, 930);
 BookingManager::bookRoom($rooms[101], $reservations[1]);
 BookingManager::bookRoom($rooms[505], $reservations[2]);
 BookingManager::bookRoom($rooms[501], $reservations[4]);
 $priceFilter = array_filter($rooms, function (Room $room) {
     if (($room instanceof Bedroom || $room instanceof Apartment) && $room->getPrice() <= 250.0) {
         return true;
     }
     return false;
 });
 $balconyFilter = array_filter($rooms, function (Room $room) {
     if ($room->getHasBalcony() == true) {
         return true;
     }
     return false;
 });
 $bathtubFilter = array_filter($rooms, function (Room $room) {
     if (in_array(Extra::BATHTUB, $room->getExtras())) {
         return true;
コード例 #7
0
ファイル: Test.php プロジェクト: savin94/SoftUni-Projects
<?php

spl_autoload_register("load_hotel_classes");
date_default_timezone_set('Europe/Sofia');
$room = new SingleRoom(1408, 99);
$guest = new Guest("Svetlin", "Nakov", 8003224277);
$startDate = new DateTime("24.10.2014");
$endDate = new DateTime("26.10.2014");
$reservation = new Reservation($startDate, $endDate, $guest);
BookingManager::bookRoom($room, $reservation);
$startDate2 = new DateTime("25.10.2014");
$endDate2 = new DateTime("27.10.2014");
$reservation2 = new Reservation($startDate2, $endDate2, $guest);
BookingManager::bookRoom($room, $reservation2);
$room2 = new Bedroom(140, 199);
$room3 = new Apartment(1400, 399);
$rooms = array($room, $room2, $room3);
$filteredRooms = array_filter($rooms, function ($v) {
    return $v->getHasBalcony() == TRUE;
});
echo "<br\\>";
foreach ($filteredRooms as $key => $room) {
    echo $room->toString();
}
$filteredRooms = array_filter($rooms, function ($v) {
    return in_array("bathtub", $v->getExtras());
});
echo "<br\\>";
echo "<br\\>";
foreach ($filteredRooms as $key => $room) {
    echo $room->toString();
});
echo "</br>Rooms With Balcony</br></br>";
echo implode("</br>", $roomsWithBalconies);
$roomsWithBathTub = array_filter($array, function ($n) {
    return in_array("Bathtub", $n->getExtras());
});
$roomNumbers = array_map(function ($v) {
    return $v->getRoomNumber();
}, $roomsWithBathTub);
echo "</br>Room Numbers of Rooms With Bathtub</br></br>";
echo implode("</br>", $roomNumbers);
$startDatePeriod = "17-02-2014";
$endDatePeriod = "20-02-2014";
$reservation = new Reservation($startDatePeriod, $endDatePeriod, new Guest("Petar", "Ivanov", 2));
echo "</br></br>";
BookingManager::bookRoom($array[1], $reservation);
$roomsNotBookedInPeriod = array_filter($array, function ($r) use($startDatePeriod, $endDatePeriod) {
    $isApartment = get_class($r) == "Apartment";
    $isNotBookedInPeriod = true;
    for ($index = 0; $index < count($r->getReservations()); $index++) {
        $currentReservationStartDate = strtotime($r->getReservations()[$index]->getStartDate());
        $currentReservationEndDate = strtotime($r->getReservations()[$index]->getEndDate());
        $startDate = strtotime($startDatePeriod);
        $endDate = strtotime($endDatePeriod);
        if ($currentReservationStartDate >= $startDate && $currentReservationStartDate <= $endDate || $currentReservationEndDate >= $startDate && $currentReservationEndDate <= $endDate) {
            $isNotBookedInPeriod = false;
            break;
        }
    }
    return $isApartment && $isNotBookedInPeriod;
});