2626use Recurr \Rule ;
2727use Recurr \Transformer \ArrayTransformer ;
2828use TYPO3 \CMS \Core \Configuration \ExtensionConfiguration ;
29- use TYPO3 \CMS \Core \Utility \GeneralUtility ;
3029use Xima \XimaTypo3InternalNews \Configuration ;
3130use Xima \XimaTypo3InternalNews \Domain \Model \Date ;
3231use Xima \XimaTypo3InternalNews \Domain \Model \News ;
3332
3433class DateService
3534{
36- public static function getNextDate (News $ news ): ?array
35+ public function __construct (
36+ private readonly ExtensionConfiguration $ extensionConfiguration
37+ ) {}
38+ public function getNextDate (News $ news ): ?array
3739 {
3840 $ nextDate = null ;
3941 foreach ($ news ->getDates () as $ date ) {
40- $ nextDateArray = self :: getDates ($ news , $ date , true , true );
42+ $ nextDateArray = $ this -> getDates ($ news , $ date , true , true );
4143 if (isset ($ nextDateArray [0 ])) {
4244 $ nextDate = $ nextDateArray [0 ];
4345 }
@@ -46,25 +48,25 @@ public static function getNextDate(News $news): ?array
4648 return $ nextDate ;
4749 }
4850
49- public static function getNextDates (News $ news ): array
51+ public function getNextDates (News $ news ): array
5052 {
5153 $ nextDates = [];
5254 foreach ($ news ->getDates () as $ date ) {
5355 // merge arrays
54- $ nextDates = array_merge ($ nextDates , self :: getDates ($ news , $ date , true ));
56+ $ nextDates = array_merge ($ nextDates , $ this -> getDates ($ news , $ date , true ));
5557 }
5658 usort ($ nextDates , function (array $ a , array $ b ) {
5759 return $ a ['date ' ] <=> $ b ['date ' ];
5860 });
5961 return $ nextDates ;
6062 }
6163
62- public static function getNotifyDatesByNewsList (array $ newsList ): array
64+ public function getNotifyDatesByNewsList (array $ newsList ): array
6365 {
6466 $ notifyDates = [];
6567 foreach ($ newsList as $ news ) {
6668 foreach ($ news ->getDates () as $ date ) {
67- $ notifyDates = array_merge ($ notifyDates , self :: getDates ($ news , $ date , true , true ));
69+ $ notifyDates = array_merge ($ notifyDates , $ this -> getDates ($ news , $ date , true , true ));
6870 }
6971 }
7072 usort ($ notifyDates , function (array $ a , array $ b ) {
@@ -73,13 +75,13 @@ public static function getNotifyDatesByNewsList(array $newsList): array
7375 return $ notifyDates ;
7476 }
7577
76- public static function getDates (News $ news , Date $ date , bool $ respectNotify = false , bool $ forceNotify = false , bool $ onlyNextDate = false ): array
78+ public function getDates (News $ news , Date $ date , bool $ respectNotify = false , bool $ forceNotify = false , bool $ onlyNextDate = false ): array
7779 {
7880 $ dates = [];
7981 switch ($ date ->getType ()) {
8082 case 'single_date ' :
81- if ($ date ->getSingleDate () > new \DateTime () && (!$ forceNotify || self :: checkNotifyIsReached ($ date ->getSingleDate ()))) {
82- $ dates [] = self :: createDateEntry ($ news , $ date , $ date ->getSingleDate (), $ respectNotify );
83+ if ($ date ->getSingleDate () > new \DateTime () && (!$ forceNotify || $ this -> checkNotifyIsReached ($ date ->getSingleDate ()))) {
84+ $ dates [] = $ this -> createDateEntry ($ news , $ date , $ date ->getSingleDate (), $ respectNotify );
8385 if ($ onlyNextDate ) {
8486 break ;
8587 }
@@ -89,8 +91,8 @@ public static function getDates(News $news, Date $date, bool $respectNotify = fa
8991 $ transformer = new ArrayTransformer ();
9092 $ rule = new Rule ($ date ->getRecurrence (), $ date ->getSingleDate (), null , (new \DateTimeZone ('Europe/Berlin ' ))->getName ());
9193 foreach ($ transformer ->transform ($ rule ) as $ recurrence ) {
92- if ($ recurrence ->getStart () > new \DateTime () && (!$ forceNotify || self :: checkNotifyIsReached ($ recurrence ->getStart ()))) {
93- $ dates [] = self :: createDateEntry ($ news , $ date , $ recurrence ->getStart (), $ respectNotify );
94+ if ($ recurrence ->getStart () > new \DateTime () && (!$ forceNotify || $ this -> checkNotifyIsReached ($ recurrence ->getStart ()))) {
95+ $ dates [] = $ this -> createDateEntry ($ news , $ date , $ recurrence ->getStart (), $ respectNotify );
9496 if ($ onlyNextDate ) {
9597 break 2 ;
9698 }
@@ -101,7 +103,7 @@ public static function getDates(News $news, Date $date, bool $respectNotify = fa
101103 return $ dates ;
102104 }
103105
104- private static function createDateEntry (News $ news , Date $ date , \DateTimeInterface $ startDate , bool $ respectNotify ): array
106+ private function createDateEntry (News $ news , Date $ date , \DateTimeInterface $ startDate , bool $ respectNotify ): array
105107 {
106108 $ newDate = [
107109 'id ' => $ date ->getUid (),
@@ -110,17 +112,17 @@ private static function createDateEntry(News $news, Date $date, \DateTimeInterfa
110112 'type ' => $ date ->getType (),
111113 'newsId ' => $ news ->getUid (),
112114 ];
113- if ($ respectNotify && $ date ->isNotify () && self :: checkNotifyIsReached ($ startDate )) {
115+ if ($ respectNotify && $ date ->isNotify () && $ this -> checkNotifyIsReached ($ startDate )) {
114116 $ newDate ['notify ' ] = true ;
115117 $ newDate ['notifyType ' ] = ($ date ->getNotifyType () !== '' ) ? $ date ->getNotifyType () : 'info ' ;
116118 $ newDate ['notifyMessage ' ] = (($ date ->getNotifyMessage () !== '' ) ? $ date ->getNotifyMessage () : $ GLOBALS ['LANG ' ]->sL ('LLL:EXT:xima_typo3_internal_news/Resources/Private/Language/locallang.xlf:internal_news_notify_note ' )) . ' ( ' . $ startDate ->format ('d.m.Y H:i ' ) . ') ' ;
117119 }
118120 return $ newDate ;
119121 }
120122
121- private static function checkNotifyIsReached (\DateTimeInterface $ date ): bool
123+ private function checkNotifyIsReached (\DateTimeInterface $ date ): bool
122124 {
123- $ extensionConfiguration = (GeneralUtility:: makeInstance (ExtensionConfiguration::class)) ->get (Configuration::EXT_KEY );
125+ $ extensionConfiguration = $ this -> extensionConfiguration ->get (Configuration::EXT_KEY );
124126 $ threshold = $ extensionConfiguration ['notifyTimeThreshold ' ];
125127
126128 $ thresholdDate = clone $ date ;
0 commit comments