Skip to content

Commit

Permalink
III-1913: Add ageTo support
Browse files Browse the repository at this point in the history
  • Loading branch information
bramcordie committed Mar 27, 2017
1 parent dc30258 commit f68239f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion lib/CultureFeed/Cdb/Item/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class CultureFeed_Cdb_Item_Event extends CultureFeed_Cdb_Item_Base implements Cu
*/
protected $ageFrom;

/**
* Maximum age for the event.
* @var int|null
*/
protected $ageTo;

/**
* Booking period for this event.
* @var CultureFeed_Cdb_Data_Calendar_BookingPeriod
Expand Down Expand Up @@ -150,6 +156,10 @@ public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
$event->setAgeFrom((int) $xmlElement->agefrom);
}

if (isset($xmlElement->ageto)) {
$event->setAgeTo((int) $xmlElement->ageto);
}

// Set calendar information.
$calendar_type = key($xmlElement->calendar);
if ($calendar_type == 'permanentopeningtimes') {
Expand Down Expand Up @@ -323,12 +333,29 @@ public function getAgeFrom()
public function setAgeFrom($age = null)
{
if (!is_numeric($age) && !is_null($age)) {
throw new UnexpectedValueException('Invalid age: ' . $age);
throw new UnexpectedValueException('Invalid minimum age: ' . $age);
}

$this->ageFrom = $age;
}

/**
* Set the maximum age for this event.
*
* @param int|null $age
* Maximum age.
*
* @throws UnexpectedValueException
*/
public function setAgeTo($age = null)
{
if (!is_numeric($age) && !is_null($age)) {
throw new UnexpectedValueException('Invalid maximum age: ' . $age);
}

$this->ageTo = $age;
}

/**
* Get the calendar from this event.
*/
Expand Down Expand Up @@ -506,6 +533,12 @@ public function appendToDOM(DOMElement $element, $cdbScheme = '3.2')
);
}

if (isset($this->ageTo)) {
$eventElement->appendChild(
$dom->createElement('ageto', $this->ageTo)
);
}

if (isset($this->isParent)) {
$eventElement->setAttribute(
'isparent',
Expand Down

0 comments on commit f68239f

Please sign in to comment.