From aa6fcadfbbc75a3833c351410ebda04627189ef8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 20 Jun 2014 16:44:28 +0200 Subject: [PATCH] Grouping notifications by date --- com.woltlab.wcf/objectType.xml | 2 + .../templates/notificationList.tpl | 22 ++++++++-- .../AbstractUserNotificationEvent.class.php | 40 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 5 +++ wcfsetup/install/lang/en.xml | 5 +++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index eceb72f287..fb60484a92 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -160,6 +160,7 @@ + com.woltlab.wcf.user.profileComment com.woltlab.wcf.comment.commentableContent @@ -202,6 +203,7 @@ com.woltlab.wcf.user + diff --git a/com.woltlab.wcf/templates/notificationList.tpl b/com.woltlab.wcf/templates/notificationList.tpl index 5b0f6787c3..5bf55adc74 100644 --- a/com.woltlab.wcf/templates/notificationList.tpl +++ b/com.woltlab.wcf/templates/notificationList.tpl @@ -46,9 +46,23 @@ {if $notifications[notifications]} -
-
    - {foreach from=$notifications[notifications] item=$notification} + {assign var=lastPeriod value=''} + + {foreach from=$notifications[notifications] item=$notification} + {if $notification[event]->getPeriod() != $lastPeriod} + {if $lastPeriod} +
+
+ {/if} + {assign var=lastPeriod value=$notification[event]->getPeriod()} + +
+

{$lastPeriod}

+
+ +
+
    + {/if}
  • {if $notification[authors] < 2} @@ -114,7 +128,7 @@ {/if}
  • - {/foreach} + {/foreach}
diff --git a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php index 20a5a68d47..cbd2245277 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php @@ -6,6 +6,7 @@ use wcf\data\user\UserProfile; use wcf\data\DatabaseObjectDecorator; use wcf\system\user\notification\object\IUserNotificationObject; use wcf\system\WCF; +use wcf\util\DateUtil; /** * Provides default a implementation for user notification events. @@ -65,6 +66,12 @@ abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator imp */ protected $language = null; + /** + * list of point of times for each period's end + * @var array + */ + protected static $periods = array(); + /** * notification trigger count * @var integer @@ -185,4 +192,37 @@ abstract class AbstractUserNotificationEvent extends DatabaseObjectDecorator imp public function isStackable() { return $this->stackable; } + + /** + * Returns the readable period matching this notification. + * + * @return string + */ + public function getPeriod() { + if (empty(self::$periods)) { + $date = DateUtil::getDateTimeByTimestamp(TIME_NOW); + $date->setTimezone(WCF::getUser()->getTimeZone()); + $date->setTime(0, 0, 0); + + self::$periods[$date->getTimestamp()] = WCF::getLanguage()->get('wcf.date.period.today'); + + // 1 day back + $date->modify('-1 day'); + self::$periods[$date->getTimestamp()] = WCF::getLanguage()->get('wcf.date.period.yesterday'); + + // 2-6 days back + for ($i = 0; $i < 6; $i++) { + $date->modify('-1 day'); + self::$periods[$date->getTimestamp()] = DateUtil::format($date, 'l'); + } + } + + foreach (self::$periods as $time => $period) { + if ($this->notification->time >= $time) { + return $period; + } + } + + return WCF::getLanguage()->get('wcf.date.period.older'); + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 535a14b8e7..ae2aa6ae0a 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1771,6 +1771,11 @@ Fehler sind beispielsweise: 1}{#$weeks} Wochen{else}einer Woche{/if}]]> 1}{#$years} Jahren{else}einem Jahr{/if}]]> + + + + + 1}{#$minutes} Minuten{else}einer Minute{/if}{/literal}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index dee5ef8f39..ca69f9967e 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1740,6 +1740,11 @@ Errors are: 1}{#$weeks} weeks{else}A week{/if}]]> 1}{#$years} years{else}A year{/if}]]> + + + + + 1}{#$minutes} minutes{else}A minute{/if} ago{/literal}]]> -- 2.20.1