/** * Goes through the booking resources and updates the 'unpaid' flag to true * where a reservation exists for the given date and a "paid" status on a * previous date for the same allocation. * $selectedDate : DateTime of date to check */ function markUnpaidResources($selectedDate) { $resourceIds = ResourceDBO::fetchResourceIdsPastDue($selectedDate); if (sizeof($resourceIds) > 0) { foreach ($this->bookingResources as $br) { $br->markUnpaidResources($resourceIds); } } }
function AllocationAvailability($resourceId, $numF, $numM, $numX, $reqRoomType, $bookingDates, $resourceProps, &$existingAllocationRows, &$newAllocationRows, $resourceMap = null) { $this->resourceId = $resourceId; $this->numF = $numF; $this->numM = $numM; $this->numX = $numX; $this->reqRoomType = $reqRoomType; $this->bookingDates = $bookingDates; $this->resourceProps = $resourceProps; $this->existingAllocationRows = $existingAllocationRows; $this->newAllocationRows = $newAllocationRows; $this->resourceMap = $resourceMap == null ? ResourceDBO::getAllResources() : $resourceMap; }
/** * Default constructor. * $name : guest name * $gender : guest gender * $resourceId : resource to assign to guest * $reqRoomSize : requested room size (e.g. 8, 10, 10+, P, etc..) * $reqRoomType : requested room type (M/F/X) * $status : current status of allocation (default: reserved) * $resourceMap : array() of resource id -> resource recordset (if not specified, query db for all resources) */ function AllocationRow($name, $gender, $resourceId, $reqRoomSize, $reqRoomType, $resourceMap = null) { $this->rowid = null; $this->id = 0; $this->name = $name; $this->gender = $gender; $this->resourceId = $resourceId; $this->reqRoomSize = $reqRoomSize; $this->reqRoomType = $reqRoomType; $this->isAvailable = true; if ($resourceMap == null) { $this->resourceMap = ResourceDBO::getAllResources(); } else { $this->resourceMap = $resourceMap; } }
/** * Adds this allocation table to the DOMDocument/XMLElement specified. * See toXml() for details. * $domtree : DOM document root * $parentElement : DOM element where this row will be added */ function addSelfToDocument($domtree, $parentElement) { // create the root element for this class and append it to our parent $xmlRoot = $parentElement->appendChild($domtree->createElement('resources')); // if we are editing, then we create a new element if ($this->editResourceId != '') { $xmlRoot->appendChild($domtree->createElement('editResource', $this->editResourceId)); } foreach (ResourceDBO::getAllResources() as $res) { $resourceRow = $domtree->createElement('resource'); $resourceRow->appendChild($domtree->createElement('resources_url', home_url() . "/" . get_option('hbo_resources_url'))); $resourceRow->appendChild($domtree->createElement('id', $res->resource_id)); $resourceRow->appendChild($domtree->createElement('name', $res->name)); $resourceRow->appendChild($domtree->createElement('path', $res->path)); $resourceRow->appendChild($domtree->createElement('level', $res->level)); $resourceRow->appendChild($domtree->createElement('numberChildren', $res->number_children)); $resourceRow->appendChild($domtree->createElement('type', $res->resource_type)); $resourceRow->appendChild($domtree->createElement('roomType', $res->room_type)); $xmlRoot->appendChild($resourceRow); } }
/** * Adds this resource page to the DOMDocument/XMLElement specified. * See toXml() for details. * $domtree : DOM document root * $parentElement : DOM element where this row will be added */ function addSelfToDocument($domtree, $parentElement) { // create the root element for this class and append it to our parent $xmlRoot = $parentElement->appendChild($domtree->createElement('view')); $xmlRoot->appendChild($domtree->createElement('resources_url', home_url() . "/" . get_option('hbo_resources_url'))); if ($this->isSaved) { $xmlRoot->appendChild($domtree->createElement('saved', 'true')); } $resource = ResourceDBO::fetchResourceById($this->resourceId); $xmlRoot->appendChild($domtree->createElement('resourceId', $this->resourceId)); $xmlRoot->appendChild($domtree->createElement('resourceName', $resource->name)); $propertiesElem = $xmlRoot->appendChild($domtree->createElement('properties')); foreach (ResourceDBO::getPropertiesForResource($this->resourceId) as $prop) { $propRow = $domtree->createElement('property'); if ($prop->selected_yn == 'Y') { $attrSelected = $domtree->createAttribute('selected'); $attrSelected->value = 'true'; $propRow->appendChild($attrSelected); } $propRow->appendChild($domtree->createElement('id', $prop->property_id)); $propRow->appendChild($domtree->createElement('value', $prop->description)); $propertiesElem->appendChild($propRow); } }
/** * Write the contents of the booking resources page. */ function content_of_resources_page() { if (isset($_GET['editResourceId'])) { $rpp = new ResourcePropertyPage($_GET['editResourceId']); // TODO: move to ResourcePropertyPage // SAVE button was pressed on the edit resource property page if ($_SERVER['REQUEST_METHOD'] == 'POST') { $propertyIds = isset($_POST['resource_property']) ? $_POST['resource_property'] : array(); ResourceDBO::updateResourceProperties($_GET['editResourceId'], $propertyIds); $rpp->isSaved = true; } error_log($rpp->toXml()); echo $rpp->toHtml(); } else { $resources = new Resources(); try { // TODO: move to Resources page // if the user has just submitted an "Add new resource" request if (isset($_POST['resource_name_new']) && $_POST['resource_name_new'] != '') { ResourceDBO::insertResource($_POST['resource_name_new'], $_POST['resource_capacity_new'], $_POST['resource_parent_new'] == 0 ? null : $_POST['resource_parent_new'], $_POST['resource_type_new']); } } catch (DatabaseException $de) { $resources->errorMessage = $de->getMessage(); } echo $resources->toHtml(); } }
/** * Updates the data required for the given date. */ function doSummaryUpdate() { $this->dailySummaryResources = ResourceDBO::fetchDailySummaryResources($this->selectionDate); $this->allocationView->doSearch(); $this->allocationView->markUnpaidResources($this->selectionDate); }
/** * Saves the selected resource row. */ function wpdev_save_resource() { $resourceId = $_POST['resource_id']; $resourceName = $_POST['resource_name']; error_log("wpdev_save_resource {$resourceId} {$resourceName}"); if ($resourceName != '') { try { ResourceDBO::editResource($resourceId, $resourceName); } catch (DatabaseException $de) { $msg = $de->getMessage(); } } $resources = new Resources(); if (isset($msg)) { $resources->errorMessage = $msg; } ?> <script type="text/javascript"> document.getElementById('wpdev-bookingresources-content').innerHTML = <?php echo json_encode($resources->toHtml()); ?> ; </script> <?php }
/** * Returns a new BookingSummary object for the given booking id. * $bookingId : id of booking to get * Returns non-null object. Throws DatabaseException if not found. */ static function fetchBookingSummaryForId($bookingId) { global $wpdb; $resultset = $wpdb->get_results($wpdb->prepare("SELECT bk.booking_id, bk.firstname, bk.lastname, bk.referrer, bk.created_by, bk.created_date\r\n FROM " . $wpdb->prefix . "booking bk\r\n WHERE bk.booking_id = %d", $bookingId)); if ($wpdb->last_error) { error_log("Failed to execute query " . $wpdb->last_query); throw new DatabaseException($wpdb->last_error); } foreach ($resultset as $res) { $summary = new BookingSummary($res->booking_id, $res->firstname, $res->lastname, $res->referrer, $res->created_by, new DateTime($res->created_date)); $summary->guests = AllocationDBO::fetchGuestNamesForBookingId($res->booking_id); $summary->statuses = AllocationDBO::fetchStatusesForBookingId($res->booking_id); $summary->resources = ResourceDBO::fetchResourcesForBookingId($res->booking_id); $summary->comments = self::fetchBookingComments($res->booking_id, BookingComment::COMMENT_TYPE_USER); $summary->bookingDates = AllocationDBO::fetchDatesForBookingId($res->booking_id); $summary->isCheckoutAllowed = AllocationDBO::isCheckoutAllowedForBookingId($res->booking_id); return $summary; } throw new DatabaseException("Booking ID {$bookingId} not found!"); }
/** * This will fetch all allocations for the given booking. * $bookingId : existing booking id * $resourceMap : map of resource id => resource recordset; if null, load all resources * $loadBookingDates : true to load booking dates, false to leave uninitialised (default true) * Returns array() of AllocationRow for booking id indexed by id */ static function fetchAllocationRowsForBookingId($bookingId, $resourceMap = null, $loadBookingDates = true) { global $wpdb; $resourceMap = $resourceMap == null ? ResourceDBO::getAllResources() : $resourceMap; $resultset = $wpdb->get_results($wpdb->prepare("SELECT a.allocation_id, a.guest_name, a.gender, a.resource_id, a.req_room_size, IFNULL(a.req_room_type, 'X') AS req_room_type\r\n FROM " . $wpdb->prefix . "allocation a\r\n WHERE a.booking_id = %d\r\n ORDER BY a.resource_id, a.guest_name", $bookingId)); if ($wpdb->last_error) { throw new DatabaseException($wpdb->last_error); } $return_val = array(); foreach ($resultset as $res) { $ar = new AllocationRow($res->guest_name, $res->gender, $res->resource_id, $res->req_room_size, $res->req_room_type, $resourceMap); $ar->id = $res->allocation_id; if ($loadBookingDates) { $ar->bookingDates = self::fetchBookingDates($res->allocation_id); } $return_val[$ar->id] = $ar; $ar->rowid = $ar->id; } return $return_val; }
/** * Default constructor. * $resourceMap : (optional) map of resource id -> resource recordset * if not set, all resources will be fetched from dbo */ function AllocationTable($resourceMap = null) { $this->resourceMap = $resourceMap == null ? ResourceDBO::getAllResources() : $resourceMap; $this->allocationStrategy = new AllocationStrategy($this->resourceMap); }
/** * Default constructor. * $resourceMap : (optional) map of resource id -> resource recordset * if not set, all resources will be fetched from dbo */ function AllocationStrategy($resourceMap = null) { $this->resourceMap = $resourceMap == null ? ResourceDBO::getAllResources() : $resourceMap; }
/** Generates the following xml: <editbooking> <id>25</id> <firstname>Megan</firstname> <lastname>Fox</lastname> <referrer>telephone</referrer> <depositpaid>10.70</depositpaid> <amounttopay>91.35</amounttopay> <allocations> <bookingName>Megan-1</bookingName> ... </allocations> <comments> <comment>...<comment> ... </comments> <properties> <property>...</property> </properties> </editbooking> */ function toXml() { // create a dom document with encoding utf8 $domtree = new DOMDocument('1.0', 'UTF-8'); // create the root element of the xml tree $xmlRoot = $domtree->createElement('editbooking'); $xmlRoot = $domtree->appendChild($xmlRoot); $xmlRoot->appendChild($domtree->createElement('homeurl', home_url())); $xmlRoot->appendChild($domtree->createElement('id', $this->id)); $xmlRoot->appendChild($domtree->createElement('firstname', $this->firstname)); $xmlRoot->appendChild($domtree->createElement('lastname', $this->lastname)); $xmlRoot->appendChild($domtree->createElement('referrer', $this->referrer)); $xmlRoot->appendChild($domtree->createElement('depositpaid', number_format($this->depositPaid, 2, '.', ''))); $xmlRoot->appendChild($domtree->createElement('amounttopay', number_format($this->amountToPay, 2, '.', ''))); // add current allocations $this->allocationTable->addSelfToDocument($domtree, $xmlRoot); // add comments $this->commentLog->addSelfToDocument($domtree, $xmlRoot); $propRoot = $xmlRoot->appendChild($domtree->createElement('properties')); foreach (ResourceDBO::getPropertiesForResource() as $prop) { $propRow = $domtree->createElement('property'); $propRow->appendChild($domtree->createElement('id', $prop->property_id)); $propRow->appendChild($domtree->createElement('value', $prop->description)); $propRoot->appendChild($propRow); } error_log($domtree->saveXML()); return $domtree->saveXML(); }