Grouping notifications by date
authorAlexander Ebert <ebert@woltlab.com>
Fri, 20 Jun 2014 14:44:28 +0000 (16:44 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 20 Jun 2014 14:44:28 +0000 (16:44 +0200)
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/templates/notificationList.tpl
wcfsetup/install/files/lib/system/user/notification/event/AbstractUserNotificationEvent.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index eceb72f287eccf3646361287fd49fa77780fa7db..fb60484a924fbc59d29ff91bc8acbab612990e17 100644 (file)
                </type>
                <!-- /activity points -->
                
+               <!-- comments -->
                <type>
                        <name>com.woltlab.wcf.user.profileComment</name>
                        <definitionname>com.woltlab.wcf.comment.commentableContent</definitionname>
                        <classname><![CDATA[wcf\system\user\notification\object\type\UserProfileCommentResponseUserNotificationObjectType]]></classname>
                        <category>com.woltlab.wcf.user</category>
                </type>
+               <!-- /comments -->
                
                <!-- moderation -->
                <type>
index 5b0f6787c336020f9ef3f756df4205ffff68cb85..5bf55adc748e66ef9e5b7ca83d2cbc3678a1cc45 100644 (file)
 </div>
 
 {if $notifications[notifications]}
-       <div class="container marginTop">
-               <ul class="containerList" id="userNotificationItemList">
-                       {foreach from=$notifications[notifications] item=$notification}
+       {assign var=lastPeriod value=''}
+       
+       {foreach from=$notifications[notifications] item=$notification}
+               {if $notification[event]->getPeriod() != $lastPeriod}
+                       {if $lastPeriod}
+                                       </ul>
+                               </div>
+                       {/if}
+                       {assign var=lastPeriod value=$notification[event]->getPeriod()}
+                       
+                       <header class="boxHeadline boxSubHeadline">
+                               <h2>{$lastPeriod}</h2>
+                       </header>
+                       
+                       <div class="container marginTop">
+                               <ul class="containerList"{* id="userNotificationItemList"*}>
+               {/if}
                                <li class="jsNotificationItem{if $notification[authors] > 1} groupedNotificationItem{/if}" data-notification-id="{@$notification[notificationID]}" data-link="{$notification[event]->getLink()}" data-is-grouped="{if $notification[authors] > 1}true{else}false{/if}">
                                        <div class="box48">
                                                {if $notification[authors] < 2}
                                                {/if}
                                        </div>
                                </li>
-                       {/foreach}
+       {/foreach}
                </ul>
        </div>
        
index 20a5a68d47d20b4314442f1f416619bb391348cc..cbd224527741cff18b2c76da500dd727b50635cd 100644 (file)
@@ -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<string>
+        */
+       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');
+       }
 }
index 535a14b8e74f856c103c987ea37d881c8d10b2a2..ae2aa6ae0aaade01669e1ae395be9dd4a15d94c9 100644 (file)
@@ -1771,6 +1771,11 @@ Fehler sind beispielsweise:
                <item name="wcf.date.interval.weeks.future"><![CDATA[In {if $weeks > 1}{#$weeks} Wochen{else}einer Woche{/if}]]></item>
                <item name="wcf.date.interval.years.future"><![CDATA[In {if $years > 1}{#$years} Jahren{else}einem Jahr{/if}]]></item>
                
+               <!-- variables for time periods -->
+               <item name="wcf.date.period.older"><![CDATA[Älter]]></item>
+               <item name="wcf.date.period.today"><![CDATA[Heute]]></item>
+               <item name="wcf.date.period.yesterday"><![CDATA[Gestern]]></item>
+               
                <!-- variables for dynamic javascript datetime -->
                <item name="wcf.date.relative.now"><![CDATA[Vor einem Moment]]></item>
                <item name="wcf.date.relative.minutes"><![CDATA[{literal}Vor {if $minutes > 1}{#$minutes} Minuten{else}einer Minute{/if}{/literal}]]></item>
index dee5ef8f39e0ea2fd3a3ac770ffe590e3c6c7bbf..ca69f9967e8c3157283e902103cd07bea9be2860 100644 (file)
@@ -1740,6 +1740,11 @@ Errors are:
                <item name="wcf.date.interval.weeks.future"><![CDATA[In {if $weeks > 1}{#$weeks} weeks{else}A week{/if}]]></item>
                <item name="wcf.date.interval.years.future"><![CDATA[In {if $years > 1}{#$years} years{else}A year{/if}]]></item>
                
+               <!-- variables for time periods -->
+               <item name="wcf.date.period.older"><![CDATA[Older]]></item>
+               <item name="wcf.date.period.today"><![CDATA[Today]]></item>
+               <item name="wcf.date.period.yesterday"><![CDATA[Yesterday]]></item>
+               
                <!-- variables for dynamic javascript datetime -->
                <item name="wcf.date.relative.now"><![CDATA[A moment ago]]></item>
                <item name="wcf.date.relative.minutes"><![CDATA[{literal}{if $minutes > 1}{#$minutes} minutes{else}A minute{/if} ago{/literal}]]></item>