@@ -1796,25 +1796,25 @@ public function renderOrderShipment(OrderShipment $shipment) : string
17961796 return (string )$ table ;
17971797 }
17981798
1799- public function renderCalendar (\DateTime $ date , string $ view = 'month ' ): string
1799+ public function renderCalendar (\DateTime $ date , string $ view = 'month ' , array $ cellsContent = [] ): string
18001800 {
18011801 switch ($ view ) {
18021802 case 'day ' :
1803- return $ this ->renderDayView ($ date );
1803+ return $ this ->renderDayView ($ date, cellsContent: $ cellsContent );
18041804 case 'week ' :
1805- return $ this ->renderWeekView ($ date );
1805+ return $ this ->renderWeekView ($ date, cellsContent: $ cellsContent );
18061806 case 'month ' :
18071807 default :
1808- return $ this ->renderMonthView ($ date );
1808+ return $ this ->renderMonthView ($ date, cellsContent: $ cellsContent );
18091809 }
18101810 }
18111811
1812- protected function renderMonthView (\DateTime $ date ): string
1812+ protected function renderMonthView (\DateTime $ date, array $ cellsContent = [] ): string
18131813 {
18141814 $ start = (clone $ date )->modify ('first day of this month ' );
18151815 $ end = (clone $ date )->modify ('last day of this month ' );
18161816
1817- $ startWeekDay = (int )$ start ->format ('N ' ); // 1 = lun , 7 = dom
1817+ $ startWeekDay = (int )$ start ->format ('N ' ); // 1 = mon , 7 = sun
18181818 $ daysInMonth = (int )$ date ->format ('t ' );
18191819
18201820 $ table = $ this ->containerMake (
@@ -1845,15 +1845,16 @@ protected function renderMonthView(\DateTime $date): string
18451845 TagElement::class,
18461846 ['options ' => [
18471847 'tag ' => 'tr ' ,
1848+ 'attributes ' => ['class ' => 'thead-dark ' ],
18481849 ]]
18491850 );
1850- foreach (['Mon ' ,'Tue ' ,'Wed ' ,'Thu ' ,'Fri ' ,'Sat ' ,'Sun ' ] as $ d ) {
1851+ foreach (['Monday ' ,'Tuesday ' ,'Wednesday ' ,'Thursday ' ,'Friday ' ,'Saturday ' ,'Sunday ' ] as $ d ) {
18511852 $ row ->addChild (
18521853 $ this ->containerMake (
18531854 TagElement::class,
18541855 ['options ' => [
18551856 'tag ' => 'th ' ,
1856- 'text ' => $ this ->getUtils ()->translate ($ d ),
1857+ 'text ' => substr ( $ this ->getUtils ()->translate ($ d), 0 , 3 ),
18571858 ]]
18581859 )
18591860 );
@@ -1884,23 +1885,21 @@ protected function renderMonthView(\DateTime $date): string
18841885
18851886 while ($ currentDay <= $ daysInMonth ) {
18861887 $ current = (clone $ start )->setDate ($ start ->format ('Y ' ), $ start ->format ('m ' ), $ currentDay );
1887- $ isToday = $ current ->format ('Y-m-d ' ) === date ('Y-m-d ' );
18881888
1889- $ class = $ isToday ? ' table-primary fw-bold ' : '' ;
1889+ $ class = $ this -> getCalendarDayClasses ( $ current ) ;
18901890
18911891 $ currentRow ->addChild (
18921892 $ this ->containerMake (
18931893 TagElement::class,
18941894 ['options ' => [
18951895 'tag ' => 'td ' ,
1896- 'text ' => (string )$ currentDay ,
1896+ 'text ' => ' <div> ' . (string )$ currentDay . ' </div><div> ' . (( string )( $ cellsContent [ $ current -> format ( ' Y-m-d ' )] ?? '' )) . ' </div> ' ,
18971897 'attributes ' => ['class ' => $ class ],
18981898 ]]
18991899 )
19001900 );
19011901
19021902 if ($ current ->format ('N ' ) == 7 ) {
1903- $ tbody ->addChild ($ currentRow );
19041903 $ currentRow = $ this ->containerMake (
19051904 TagElement::class,
19061905 ['options ' => [
@@ -1916,7 +1915,7 @@ protected function renderMonthView(\DateTime $date): string
19161915 return (string )$ table ;
19171916 }
19181917
1919- protected function renderWeekView (\DateTime $ date , string $ formatDate = 'D d/m ' ): string
1918+ protected function renderWeekView (\DateTime $ date , string $ formatDate = 'D d/m ' , array $ cellsContent = [] ): string
19201919 {
19211920 $ startOfWeek = (clone $ date )->modify ('monday this week ' );
19221921
@@ -1932,6 +1931,7 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19321931 TagElement::class,
19331932 ['options ' => [
19341933 'tag ' => 'thead ' ,
1934+ 'attributes ' => ['class ' => 'thead-dark ' ],
19351935 ]]
19361936 );
19371937 $ tbody = $ this ->containerMake (
@@ -1971,14 +1971,13 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19711971 );
19721972 for ($ i =0 ; $ i <7 ; $ i ++) {
19731973 $ d = (clone $ startOfWeek )->modify ("+ $ i day " );
1974- $ isToday = $ d ->format ('Y-m-d ' ) === date ('Y-m-d ' );
1975- $ class = $ isToday ? 'table-primary fw-bold ' : '' ;
1974+ $ class = $ this ->getCalendarDayClasses ($ d );
19761975 $ row ->addChild (
19771976 $ this ->containerMake (
19781977 TagElement::class,
19791978 ['options ' => [
19801979 'tag ' => 'td ' ,
1981- 'text ' => '' ,
1980+ 'text ' => ( string )( $ cellsContent [ $ d -> format ( ' Y-m-d ' )] ?? '' ) ,
19821981 'attributes ' => ['class ' => $ class , 'style ' => 'height:100px ' ],
19831982 ]]
19841983 )
@@ -1988,7 +1987,7 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19881987 return (string )$ table ;
19891988 }
19901989
1991- protected function renderDayView (\DateTime $ date , string $ formatDate = 'l d F Y ' ): string
1990+ protected function renderDayView (\DateTime $ date , string $ formatDate = 'l d F Y ' , array $ cellsContent = [] ): string
19921991 {
19931992 $ table = $ this ->containerMake (
19941993 TagElement::class,
@@ -2020,6 +2019,7 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20202019 TagElement::class,
20212020 ['options ' => [
20222021 'tag ' => 'tr ' ,
2022+ 'attributes ' => ['class ' => 'thead-dark ' ],
20232023 'children ' => [
20242024 $ this ->containerMake (TagElement::class, ['options ' => [
20252025 'tag ' => 'th ' ,
@@ -2046,7 +2046,7 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20462046 ]]),
20472047 $ this ->containerMake (TagElement::class, ['options ' => [
20482048 'tag ' => 'td ' ,
2049- 'text ' => '' ,
2049+ 'text ' => ( string )( $ cellsContent [ $ h ] ?? '' ) ,
20502050 'attributes ' => ['style ' => 'height:40px; ' ],
20512051 ]]),
20522052 ]
@@ -2057,4 +2057,13 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20572057
20582058 return (string )$ table ;
20592059 }
2060+
2061+ private function getCalendarDayClasses ($ current ) : string
2062+ {
2063+ $ classes = [$ current ->format ('Y-m-d ' )];
2064+ if ($ current ->format ('Y-m-d ' ) === date ('Y-m-d ' )) {
2065+ $ classes [] = 'table-primary fw-bold ' ;
2066+ }
2067+ return implode (' ' , $ classes );
2068+ }
20602069}
0 commit comments