-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Notifications\Widget\Calendar; | ||
|
||
use DateInterval; | ||
use DateTime; | ||
use ipl\Html\Attributes; | ||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\Text; | ||
use Traversable; | ||
|
||
class DayGrid extends BaseGrid | ||
{ | ||
protected $mode = 'day'; | ||
|
||
public function setGridStart(DateTime $start): BaseGrid | ||
{ | ||
return parent::setGridStart($start); | ||
} | ||
|
||
protected function calculateGridEnd(): DateTime | ||
{ | ||
return (clone $this->getGridStart())->add(new DateInterval('P1D')); | ||
} | ||
|
||
protected function getNoOfVisuallyConnectedHours(): int | ||
{ | ||
return 24; | ||
} | ||
|
||
protected function getGridArea(int $rowStart, int $rowEnd, int $colStart, int $colEnd): array | ||
{ | ||
return [$colStart, $rowStart, $colEnd, $rowEnd]; | ||
} | ||
|
||
protected function createGridSteps(): Traversable | ||
{ | ||
$interval = new DateInterval('P1D'); | ||
$hourStartsAt = clone $this->getGridStart(); | ||
for ($i = 0; $i < 24; $i++) { | ||
yield $hourStartsAt; | ||
|
||
$hourStartsAt->add($interval); | ||
} | ||
} | ||
|
||
protected function createHeader(): BaseHtmlElement | ||
{ | ||
$header = new HtmlElement('div', Attributes::create(['class' => 'header'])); | ||
|
||
$currentDay = clone $this->getGridStart(); | ||
$interval = new DateInterval('P1D'); | ||
$header->addHtml(new HtmlElement( | ||
'div', | ||
Attributes::create(['class' => 'column-title']), | ||
new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'day-name']), | ||
Text::create($this->getGridStart()->format('D')) | ||
), | ||
new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'day-number']), | ||
Text::create($currentDay->format('d')) | ||
) | ||
)); | ||
|
||
$currentDay->add($interval); | ||
|
||
return $header; | ||
} | ||
|
||
protected function createSidebar(): BaseHtmlElement | ||
{ | ||
$sidebar = new HtmlElement('div', Attributes::create(['class' => 'sidebar'])); | ||
|
||
$time = (new DateTime())->setTime(0, 0); | ||
$interval = new DateInterval('PT1H'); | ||
for ($i = 0; $i < 24; $i++) { | ||
$sidebar->addHtml(new HtmlElement( | ||
'div', | ||
Attributes::create(['class' => 'row-title']), | ||
new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'hour']), | ||
Text::create($time->format('H:i')) | ||
) | ||
)); | ||
|
||
$time->add($interval); | ||
} | ||
|
||
return $sidebar; | ||
} | ||
|
||
protected function assemble() | ||
{ | ||
$this->getAttributes()->add('class', 'day'); | ||
|
||
$this->addHtml( | ||
$this->createHeader(), | ||
$this->createSidebar(), | ||
$this->createGrid(), | ||
$this->createGridOverlay() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters