/** * render calendar called in view via helper * @param mixed $date * @param Array $options */ public function render($date = null, $options = array()) { $calendar = $this->parsed($date); $this->buildConfig($options); $container = new DomBuilder('div', array('id' => $this->style['div'])); for ($month = 0; $month < $this->displayedMonth; $month++) { $monthDays = cal_days_in_month(CAL_GREGORIAN, $calendar->format('n'), $calendar->format('Y')); if ($calendar->format('j') != 1) { $calendar->sub(new \DateInterval("P{$calendar->format('j')}D"))->add(new \DateInterval("P1D")); } $firstDay = $calendar->format('N'); $weeks = ceil(($monthDays + $firstDay) / 7); $table = new DomBuilder('table', array('class' => $this->style['table'])); $th = $table->addChild('thead')->addChild('tr', array('class' => $this->style['title']))->addChild('th', array('colspan' => 7, 'class' => $this->style['title'])); $th->content = $calendar->format('F Y'); $days = $table->get('thead')->addChild('tr'); for ($day = 0; $day < 7; $day++) { $cell = $days->addChild('th'); $cell->content = $this->abbreviate ? jddayofweek($day, 2) : jddayofweek($day, 1); } for ($week = 0; $week < $weeks; $week++) { $weekdate = $table->addChild('tr'); for ($day = 0; $day < 7; $day++) { $cellNumber = $week * 7 + $day; $class = $calendar->format('d-m-Y') == date('d-m-Y') ? $this->style['current'] : null; $cell = $weekdate->addChild('td', array('class' => $class)); if ($cellNumber + 1 >= $firstDay && $cellNumber + 1 < $monthDays + $firstDay) { $cell->content = $this->renderCell($calendar); $calendar->add(new \DateInterval("P1D")); } } } $container->addChild($table); } return $container->render(); }