/** * Creates a new ArrayObjects and fills is with the provided data * * @param array $data The data to fill the ArrayObject with * * @return ArrayObject The ArrayObject filled with the data */ public static function createFromArray(array $data) { $ao = new ArrayObject(); foreach ($data as $item) { $ao->append($item); } return $ao; }
/** * Returns the first open Period after $now * * @param DateTime $now The date context for the Periods. default: current datetime * @return Period The next open period or null if no period has been found */ public function getNextOpenPeriod(DateTime $now = null) { $periods = $this->periods; if ($now != null) { $periods = new ArrayObject(); foreach ($this->periods as $period) { $periods->append($period->getCopyInDateContext($now)); } } $periods->uksort(array('\\OpeningHours\\Entity\\Period', 'sortStrategy')); if (count($this->periods) < 1) { return null; } foreach ($this->periods as $period) { if ($period->willBeOpen($this->getId())) { return $period; } } for ($weekOffset = 1; true; $weekOffset++) { if ($weekOffset > 52) { return null; } $timeDifference = new DateInterval('P' . 7 * $weekOffset . 'D'); foreach ($this->periods as $period) { $newPeriod = clone $period; $newPeriod->getTimeStart()->add($timeDifference); $newPeriod->getTimeEnd()->add($timeDifference); if ($newPeriod->willBeOpen($this)) { return $newPeriod; } } } return null; }