From: Alexander Ebert Date: Fri, 20 Jun 2014 14:44:28 +0000 (+0200) Subject: Grouping notifications by date X-Git-Tag: 2.1.0_Alpha_1~669^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=aa6fcadfbbc75a3833c351410ebda04627189ef8;p=GitHub%2FWoltLab%2FWCF.git Grouping notifications by date --- 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}]]>