/** * @param IDisplayableItem[] $displayableItems * @param \DateTime $period * @return array */ public function generateEntireTable(array $displayableItems, \DateTime $period) { $year = $period->format('Y'); $month = $period->format('n'); $daysInMonth = TimeUtils::getNumberOfDaysInMonth($year, $month); $list = []; for ($day = 1; $day <= $daysInMonth; $day++) { if (array_key_exists($day, $displayableItems)) { if (!$displayableItems[$day] instanceof IDisplayableItem) { throw new InvalidArgumentException('Only instances of ' . IDisplayableItem::class . ' can pass.'); } $list[$day] = $displayableItems[$day]; } else { $list[$day] = new FillingItem(TimeUtils::getDateTimeFromParameters($year, $month, $day)); } } return $list; }
/** * @return int */ public function getNumberOfDaysInMonth() { if (!isset($this->numberOfDaysInListingMonth)) { $this->numberOfDaysInListingMonth = TimeUtils::getNumberOfDaysInMonth($this->period->format('Y'), $this->period->format('n')); } return $this->numberOfDaysInListingMonth; }