/** * Parse the input string and set our elements based on the contents of the * input string. Elements not found in the string will be null. * * @return void * @access private * @since 5/24/05 */ function parse() { $term = trim(strtolower($this->input)); if (in_array($term, $this->nowArray())) { $timespan = Timespan::current(); } else { if (in_array($term, $this->todayArray())) { $timespan = Date::today(); } else { if (in_array($term, $this->tomorrowArray())) { $timespan = Date::tomorrow(); } else { if (in_array($term, $this->yesterdayArray())) { $timespan = Date::yesterday(); } } } } $dateAndTime = $timespan->start(); $offset = $dateAndTime->offset(); $this->setYear($dateAndTime->year()); $this->setMonth($dateAndTime->month()); $this->setDay($dateAndTime->dayOfMonth()); $this->setHour($dateAndTime->hour()); $this->setMinute($dateAndTime->minute()); $this->setSecond($dateAndTime->second()); $this->setOffsetHour($offset->hours()); $this->setOffsetMinute($offset->minutes()); $this->setOffsetSecond($offset->seconds()); }
/** * Create a new object with given start and end DateAndTimes * * @param object DateAndTime $startDateAndTime * @param object DateAndTime $endDateAndTime * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Month * @access public * @since 5/11/05 * @static */ static function startingEnding($startDateAndTime, $endDateAndTime, $class = 'Month') { $obj = parent::startingEnding($startDateAndTime, $endDateAndTime, $class); return $obj; }
/** * Test Converting Methods * */ function test_converting() { // Converting $timespan = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10)); // asDate() $temp = $timespan->asDate(); $this->assertTrue($temp->isEqualTo(Date::withYearMonthDay(2005, 5, 4))); // asDateAndTime() $temp = $timespan->asDateAndTime(); $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 00, 00, 00))); // asDuration() $temp = $timespan->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withDays(365))); // asMonth() $temp = $timespan->asMonth(); $this->assertTrue($temp->isEqualTo(Month::withMonthYear(5, 2005))); // asTime() $temp = $timespan->asTime(); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0); $this->assertTrue($temp->isEqualTo($dateAndTime->asTime())); // asTimeStamp() $temp = $timespan->asTimeStamp(); $this->assertTrue($temp->isEqualTo(TimeStamp::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0))); // asWeek() $temp = $timespan->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::withYearMonthDay(2005, 5, 1)))); // asYear() $temp = $timespan->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::withYearMonthDay(2005, 5, 4)))); // to() $temp = $timespan->to(Date::withYearMonthDay(2005, 10, 1)); $comparison = Timespan::startingEnding(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0), Date::withYearMonthDay(2005, 10, 1)); $this->assertTrue($temp->isEqualTo($comparison)); }
/** * Answer a Timespan. anEnd conforms to protocol DateAndTime or protocol Timespan * * @param object DateAndTime $anEnd * @return object Timespan * @access public * @since 5/12/05 */ function to($anEnd) { $obj = Timespan::startingEnding($this, $anEnd->asDateAndTime()); return $obj; }
/** * Test converting methods * */ function test_converting() { $time = Time::withHourMinuteSecond(15, 25, 10); // asDate () $temp = $time->asDate(); $this->assertTrue($temp->isEqualTo(Date::today())); $this->assertEqual(strtolower(get_class($temp)), 'date'); // asDateAndTime () $temp = $time->asDateAndTime(); $comparison = DateAndTime::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'dateandtime'); // asDuration () $temp = $time->asDuration(); $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510))); $this->assertEqual(strtolower(get_class($temp)), 'duration'); // asMonth () $temp = $time->asMonth(); $this->assertTrue($temp->isEqualTo(Month::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'month'); // asSeconds () $this->assertEqual($time->asSeconds(), 55510); // asTime () $temp = $time->asTime(); $this->assertTrue($temp->isEqualTo($time)); $this->assertEqual(strtolower(get_class($temp)), 'time'); // asTimeStamp () $temp = $time->asTimeStamp(); $comparison = TimeStamp::midnight(); $comparison = $comparison->plus(Duration::withSeconds(55510)); $this->assertTrue($temp->isEqualTo($comparison)); $this->assertEqual(strtolower(get_class($temp)), 'timestamp'); // asWeek () $temp = $time->asWeek(); $this->assertTrue($temp->isEqualTo(Week::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'week'); // asYear () $temp = $time->asYear(); $this->assertTrue($temp->isEqualTo(Year::starting(Date::today()))); $this->assertEqual(strtolower(get_class($temp)), 'year'); // to () $today = DateAndTime::today(); $tomorrow = DateAndTime::tomorrow(); $result = $time->to($tomorrow); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50)))); $result = $time->to(Time::withHourMinuteSecond(23, 25, 10)); $this->assertEqual(strtolower(get_class($result)), 'timespan'); $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0)))); }
protected function generateXml() { $hotelRes = new \C2is\OTA\Model\HotelRes\HotelRes(); $hotelRes->setEchoToken($this->getParam('echo')); $hotelRes->setRequestorId($this->getParam('requestor.id')); $hotelRes->setRequestorType($this->getParam('requestor.type')); $hotelRes->setRequestorCompanyName($this->getParam('company_name')); $hotelRes->setVersion($this->getParam('ota.version')); $hotelRes->setXmlns($this->getParam('ota.namespace')); $hotelRes->setBookingType($this->getParam('booking.type')); $hotelRes->setBookingCompanyCode($this->getParam('booking.company_code')); $hotelRes->setBookingCompanyName($this->getParam('booking.company_name')); $hotelRes->setStatus($this->getParam('status')); foreach ($this->getParam('reservations') as $reservation) { $hotelRes->addReservation($hotelReservation = new HotelReservation()); if ($hotelRes->getStatus() == 'Initiate') { $hotelReservation->setCreateDateTime(new \DateTime()); } elseif ($hotelRes->getStatus() == 'Modify') { $hotelReservation->setLastModifyDateTime(new \DateTime()); } foreach ($reservation['room_stays'] as $roomStay) { $hotelReservation->addRoomStay($objRoomStay = new RoomStay()); foreach ($roomStay['room_types'] as $roomType) { $objRoomStay->addRoomType($objRoomType = new RoomType()); $objRoomType->setCode($roomType['code']); $objRoomType->setNumberOfUnits($roomType['number_of_units']); } foreach ($roomStay['room_rates'] as $roomRate) { $objRoomStay->addRoomRate($objRoomRate = new RoomRate()); $objRoomRate->setNumberOfUnits($roomRate['number_of_units']); if ($roomRate['rate_plan_category'] != 'RAC') { $objRoomRate->setCode($roomRate['rate_plan_code']); } $objRoomRate->setCategory($roomRate['rate_plan_category']); foreach ($roomRate['rates'] as $rate) { $objRoomRate->addRate($objRate = new Rate()); $objRate->setEffectiveDate($rate['start_date']); $objRate->setExpireDate($rate['end_date']); $objRate->setBase($objBase = new Base()); $base = $rate['base']; $objBase->setAmountAfterTax($base['after_tax']); $objBase->setAmountBeforeTax($base['before_tax']); $objBase->setCurrency($base['currency']); if (isset($rate['extensions'])) { $objBase->setExtensions($objExtensions = new Extensions()); $objExtensions->setRedeemedNights($objRedeemedNights = new RedeemedNights()); $extensions = $rate['extensions']; $objRedeemedNights->setProgramId($extensions['program_id']); foreach ($extensions['nights'] as $night) { $objRedeemedNights->addRedeemedNight($objRedeemedNight = new RedeemedNight()); $objRedeemedNight->setDate($night['date']); } } } } foreach ($roomStay['guest_counts'] as $guestCount) { $objRoomStay->addGuestCount($objGuestCount = new GuestCount()); $objGuestCount->setAge($guestCount['age']); $objGuestCount->setAgeCode($guestCount['age_code']); $objGuestCount->setCount($guestCount['count']); } if (isset($roomStay['timespan'])) { $objRoomStay->setTimespan($objTimespan = new Timespan()); $objTimespan->setStart($roomStay['timespan']['start']); $objTimespan->setEnd($roomStay['timespan']['end']); } if (isset($roomStay['total'])) { $objTotal = $objRoomStay->getTotal(); $objTotal->setBeforeTax($roomStay['total']['before_tax']); $objTotal->setAfterTax($roomStay['total']['after_tax']); $objTotal->setCurrency($roomStay['total']['currency']); foreach ($roomStay['total']['taxes'] as $tax) { $objTotal->addTax($objTax = new Tax()); $objTax->setAmount($tax['amount']); foreach ($tax['description'] as $taxDescription) { $objTax->addDescription($objDescription = new TaxDescription()); $objDescription->setDescription($taxDescription['description']); $objDescription->setLanguage($taxDescription['lang']); } } } if (isset($roomStay['hotel'])) { $objBasicPropertyInfo = $objRoomStay->getBasicPropertyInfo(); $objBasicPropertyInfo->setChainCode($roomStay['hotel']['chain_code']); $objBasicPropertyInfo->setHotelCode($roomStay['hotel']['code']); } if (isset($roomStay['services'])) { foreach ($roomStay['services'] as $service) { $objRoomStay->addServiceRph($objServiceRph = new ServiceRph()); $objServiceRph->setIsPerRoom($service['per_room']); $objServiceRph->setRph($service['rph']); } } } foreach ($reservation['services'] as $service) { $hotelReservation->addService($objService = new Service()); $objService->setRph($service['rph']); $objService->setInventoryCode($service['inventory_code']); $objService->setPricingType($service['pricing_type']); $objService->setQuantity($service['quantity']); $amount = $service['amount']; $objBase = $objService->getPrice()->getBase(); if (isset($amount['after_tax'])) { $objBase->setAfterTax($amount['after_tax']); } if (isset($amount['before_tax'])) { $objBase->setBeforeTax($amount['before_tax']); } if (isset($amount['currency'])) { $objBase->setCurrency($amount['currency']); } if (in_array($objService->getPricingType(), array(Service::PRICING_TYPE_PER_NIGHT, Service::PRICING_TYPE_PER_PERSON_PER_NIGHT)) and isset($service['details'])) { $details = $service['details']; if (isset($details['duration'])) { $objService->getDetails()->getTimespan()->setDuration($details['duration']); } } } foreach ($reservation['guests'] as $guest) { $hotelReservation->addGuest($objGuest = new Guest()); $objGuest->setRph($guest['rph']); $objGuest->addCustomer($objCustomer = new Guest\Customer()); $objCustomer->setEmail($guest['email']); $objCustomer->setCurrency($guest['currency']); $objCustomer->setGender($guest['gender']); if (isset($guest['person_name'])) { $objCustomer->setPersonName($objPersonName = new Guest\PersonName()); $objPersonName->setGivenName($guest['person_name']['given_name']); $objPersonName->setSurName($guest['person_name']['surname']); } if (isset($guest['address'])) { $objCustomer->setAddress($objAddress = new Guest\Address()); $objAddress->setLine($guest['address']['line']); $objAddress->setCity($guest['address']['city']); $objAddress->setPostalCode($guest['address']['postal_code']); if (isset($guest['address']['country'])) { $objAddress->setCountryName($guest['address']['country']['name']); $objAddress->setCountryCode($guest['address']['country']['code']); } } if (isset($guest['telephone'])) { $objCustomer->setTelephone($objTelephone = new Guest\Telephone()); $objTelephone->setCountryAccessCode($guest['telephone']['country_access_code']); $objTelephone->setNumber($guest['telephone']['number']); } if (isset($guest['loyalty'])) { $objCustomer->setLoyalty($objLoyalty = new Guest\Loyalty()); $objLoyalty->setMembershipId($guest['loyalty']['membership_id']); $objLoyalty->setProgramId($guest['loyalty']['program_id']); } if (isset($guest['comments'])) { foreach ($guest['comments'] as $comment) { if (isset($comment['message'])) { $objGuest->addComment($objComment = new Comment()); $objComment->addText($objText = new Text()); $objText->setValue($comment['message']); if (isset($comment['lang'])) { $objText->setLang($comment['lang']); } if (isset($comment['originator_code'])) { $objComment->setOriginatorCode($comment['originator_code']); } if (isset($comment['viewable'])) { $objComment->setGuestViewable($comment['viewable']); } } } } } } if ($globalInfo = $this->getParam('global_info')) { $hotelReservation->setGlobalInfo($objGlobalInfo = new GlobalInfo()); if (isset($globalInfo['guarantee'])) { $objGlobalInfo->setGuarantee($objGuarantee = new Guarantee()); if (isset($globalInfo['guarantee']['guarantees_accepted'])) { foreach ($globalInfo['guarantee']['guarantees_accepted'] as $guaranteeAccepted) { $objGuarantee->addPaymentCard($objPaymentCard = new PaymentCard()); $objPaymentCard->setCardHolderName($guaranteeAccepted['card_holder_name']); $objPaymentCard->setCardNumber($guaranteeAccepted['card_number']); $objPaymentCard->setCardType($guaranteeAccepted['card_type']); $objPaymentCard->setExpireDate($guaranteeAccepted['card_expire_date']); $objPaymentCard->setSeriesCode($guaranteeAccepted['card_series_code']); } } } if (isset($globalInfo['total'])) { $objGlobalInfo->setTotal($objTotal = new Total()); $objTotal->setAfterTax($globalInfo['total']['after_tax']); $objTotal->setBeforeTax($globalInfo['total']['before_tax']); if (isset($globalInfo['total']['currency'])) { $objTotal->setCurrency($globalInfo['total']['currency']); } if (isset($globalInfo['total']['taxes'])) { foreach ($globalInfo['total']['taxes'] as $tax) { $objTotal->addTax($objTax = new Tax()); $objTax->setAmount($tax['amount']); $objTax->setPercent($tax['percent']); } } } if (isset($globalInfo['hotel_reservation_ids'])) { foreach ($globalInfo['hotel_reservation_ids'] as $hotelReservationId) { $objGlobalInfo->addHotelReservationId($objHotelReservationId = new HotelReservationId()); $objHotelReservationId->setSource($hotelReservationId['source']); $objHotelReservationId->setValue($hotelReservationId['value']); } } if (isset($globalInfo['comments'])) { foreach ($globalInfo['comments'] as $comment) { if (isset($comment['message'])) { $objGlobalInfo->addComment($objComment = new Comment()); $objComment->addText($objText = new Text()); $objText->setValue($comment['message']); if (isset($comment['lang'])) { $objText->setLang($comment['lang']); } if (isset($comment['originator_code'])) { $objComment->setOriginatorCode($comment['originator_code']); } if (isset($comment['viewable'])) { $objComment->setGuestViewable($comment['viewable']); } } } } } $serializer = \JMS\Serializer\SerializerBuilder::create()->build(); return $serializer->serialize($hotelRes, 'xml'); }
/** * Create a new object starting now, with a given duration. * Override - as each Week has a defined duration * * @param object DateAndTime $aDateAndTime * @param object Duration $aDuration * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Week * @access public * @since 5/5/05 * @static */ static function startingDuration($aDateAndTime, $aDuration, $class = 'Week') { // Validate our passed class name. if (!(strtolower($class) == strtolower('Week') || is_subclass_of(new $class(), 'Week'))) { die("Class, '{$class}', is not a subclass of 'Week'."); } $asDateAndTime = $aDateAndTime->asDateAndTime(); $midnight = $asDateAndTime->atMidnight(); $dayNames = ChronologyConstants::DayNames(); $temp = $midnight->dayOfWeek() + 7 - array_search(Week::startDay(), $dayNames); $delta = abs($temp - intval($temp / 7) * 7); $adjusted = $midnight->minus(Duration::withDays($delta)); $obj = parent::startingDuration($adjusted, Duration::withWeeks(1), $class); return $obj; }
/** * Create a new object starting now, with a given duration. * * @param object DateAndTime $aDateAndTime * @param object Duration $aDuration * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Schedule * @access public * @since 5/5/05 * @static */ static function startingDuration($aDateAndTime, $aDuration, $class = 'Schedule') { $obj = parent::startingDuration($aDateAndTime, $aDuration, $class); return $obj; }