Use page-based online location
authorMatthias Schmidt <gravatronics@live.com>
Thu, 7 Apr 2016 10:08:19 +0000 (12:08 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 7 Apr 2016 10:08:19 +0000 (12:08 +0200)
12 files changed:
files/lib/data/conversation/ConversationList.class.php
files/lib/system/cache/runtime/ConversationRuntimeCache.class.php [new file with mode: 0644]
files/lib/system/cache/runtime/UserConversationRuntimeCache.class.php [new file with mode: 0644]
files/lib/system/page/handler/ConversationListPageHandler.class.php [new file with mode: 0644]
files/lib/system/page/handler/DefaultConversationRelatedPageHandler.class.php [new file with mode: 0644]
files/lib/system/page/handler/TConversationOnlineLocationPageHandler.class.php [new file with mode: 0644]
files/lib/system/user/online/location/ConversationLocation.class.php [deleted file]
language/de.xml
language/en.xml
objectType.xml
package.xml
page.xml [new file with mode: 0644]

index 910642ebe58d7b240099960ba9ff151a8cffca42..53027b182432ad443ef0e3f4df65b32b229228de 100644 (file)
@@ -6,7 +6,7 @@ use wcf\data\DatabaseObjectList;
  * Represents a list of conversations.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf.conversation
  * @subpackage data.conversation
@@ -14,7 +14,7 @@ use wcf\data\DatabaseObjectList;
  */
 class ConversationList extends DatabaseObjectList {
        /**
-        * @see \wcf\data\DatabaseObjectList::$className
+        * @inheritDoc
         */
-       public $className = 'wcf\data\conversation\Conversation';
+       public $className = Conversation::class;
 }
diff --git a/files/lib/system/cache/runtime/ConversationRuntimeCache.class.php b/files/lib/system/cache/runtime/ConversationRuntimeCache.class.php
new file mode 100644 (file)
index 0000000..1da8f20
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+namespace wcf\system\cache\runtime;
+use wcf\data\conversation\Conversation;
+use wcf\data\conversation\ConversationList;
+
+/**
+ * Runtime cache implementation for conversations.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.cache.runtime
+ * @category   Community Framework
+ * @since      2.2
+ *
+ * @method     Conversation            getObject($objectID)
+ * @method     Conversation[]          getObjects(array $objectIDs)
+ */
+class ConversationRuntimeCache extends AbstractRuntimeCache {
+       /**
+        * @inheritDoc
+        */
+       protected $listClassName = ConversationList::class;
+}
\ No newline at end of file
diff --git a/files/lib/system/cache/runtime/UserConversationRuntimeCache.class.php b/files/lib/system/cache/runtime/UserConversationRuntimeCache.class.php
new file mode 100644 (file)
index 0000000..26ce6e4
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+namespace wcf\system\cache\runtime;
+use wcf\data\conversation\Conversation;
+use wcf\data\conversation\UserConversationList;
+use wcf\system\WCF;
+
+/**
+ * Runtime cache implementation for conversation fetched using UserConversationList.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.cache.runtime
+ * @category   Community Framework
+ * @since      2.2
+ *
+ * @method     Conversation            getObject($objectID)
+ * @method     Conversation[]          getObjects(array $objectIDs)
+ */
+class UserConversationRuntimeCache extends AbstractRuntimeCache {
+       /**
+        * @inheritDoc
+        */
+       protected $listClassName = UserConversationList::class;
+       
+       /**
+        * @inheritDoc
+        */
+       protected function getObjectList() {
+               return new UserConversationList(WCF::getUser()->userID);
+       }
+}
diff --git a/files/lib/system/page/handler/ConversationListPageHandler.class.php b/files/lib/system/page/handler/ConversationListPageHandler.class.php
new file mode 100644 (file)
index 0000000..df85cd3
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+namespace wcf\system\page\handler;
+use wcf\system\conversation\ConversationHandler;
+use wcf\system\WCF;
+
+/**
+ * Page handler implementation for the conversation list.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.page.handler
+ * @category   Community Framework
+ * @since      2.2
+ */
+class ConversationListPageHandler extends AbstractMenuPageHandler {
+       /**
+        * @inheritDoc
+        */
+       public function getOutstandingItemCount($objectID = null) {
+               return ConversationHandler::getInstance()->getUnreadConversationCount();
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function isVisible($objectID = null) {
+               return WCF::getUser()->userID != 0;
+       }
+}
diff --git a/files/lib/system/page/handler/DefaultConversationRelatedPageHandler.class.php b/files/lib/system/page/handler/DefaultConversationRelatedPageHandler.class.php
new file mode 100644 (file)
index 0000000..d7144b8
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+namespace wcf\system\page\handler;
+
+/**
+ * Default implementation of a board-related page handler.
+ * 
+ * Only use this class when you need the online location handling for a board-related page.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.page.handler
+ * @category   Community Framework
+ * @since      2.2
+ */
+class DefaultConversationRelatedPageHandler extends AbstractMenuPageHandler implements IOnlineLocationPageHandler {
+       use TConversationOnlineLocationPageHandler;
+}
diff --git a/files/lib/system/page/handler/TConversationOnlineLocationPageHandler.class.php b/files/lib/system/page/handler/TConversationOnlineLocationPageHandler.class.php
new file mode 100644 (file)
index 0000000..75373d4
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+namespace wcf\system\page\handler;
+use wcf\data\page\Page;
+use wcf\data\user\online\UserOnline;
+use wcf\system\cache\runtime\UserConversationRuntimeCache;
+use wcf\system\WCF;
+
+/**
+ * Implementation of the online location-related page handler methods for conversations.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf.conversation
+ * @subpackage system.page.handler
+ * @category   Community Framework
+ * @since      2.2
+ */
+trait TConversationOnlineLocationPageHandler {
+       use TOnlineLocationPageHandler;
+       
+       /**
+        * @see IMenuPageHandler::getOnlineLocation()
+        */
+       public function getOnlineLocation(Page $page, UserOnline $user) {
+               if ($user->objectID === null) {
+                       return '';
+               }
+               
+               $conversation = UserConversationRuntimeCache::getInstance()->getObject($user->objectID);
+               if ($conversation === null || !$conversation->canRead()) {
+                       return '';
+               }
+               
+               return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['conversation' => $conversation]);
+       }
+       
+       /**
+        * @see IOnlineLocationPageHandler::prepareOnlineLocation()
+        */
+       public function prepareOnlineLocation(Page $page, UserOnline $user) {
+               if ($user->objectID !== null) {
+                       UserConversationRuntimeCache::getInstance()->cacheObjectID($user->objectID);
+               }
+       }
+}
diff --git a/files/lib/system/user/online/location/ConversationLocation.class.php b/files/lib/system/user/online/location/ConversationLocation.class.php
deleted file mode 100644 (file)
index 0b862dd..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-namespace wcf\system\user\online\location;
-use wcf\data\conversation\Conversation;
-use wcf\data\user\online\UserOnline;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\WCF;
-
-/**
- * Implementation of IUserOnlineLocation for the conversation page location.
- * 
- * @author     Marcel Werk
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf.conversation
- * @subpackage system.user.online.location
- * @category   Community Framework
- */
-class ConversationLocation implements IUserOnlineLocation {
-       /**
-        * conversation ids
-        * @var integer[]
-        */
-       protected $conversationIDs = array();
-       
-       /**
-        * list of conversations
-        * @var Conversation[]
-        */
-       protected $conversations = null;
-       
-       /**
-        * @see \wcf\system\user\online\location\IUserOnlineLocation::cache()
-        */
-       public function cache(UserOnline $user) {
-               if ($user->objectID) $this->conversationIDs[] = $user->objectID;
-       }
-       
-       /**
-        * @see \wcf\system\user\online\location\IUserOnlineLocation::get()
-        */
-       public function get(UserOnline $user, $languageVariable = '') {
-               if ($this->conversations === null) {
-                       $this->readConversations();
-               }
-               
-               if (!isset($this->conversations[$user->objectID])) {
-                       return '';
-               }
-               
-               return WCF::getLanguage()->getDynamicVariable($languageVariable, array('conversation' => $this->conversations[$user->objectID]));
-       }
-       
-       /**
-        * Loads the conversations.
-        */
-       protected function readConversations() {
-               $this->conversations = array();
-               
-               if (!WCF::getUser()->userID) return;
-               if (empty($this->conversationIDs)) return;
-               $this->conversationIDs = array_unique($this->conversationIDs);
-               
-               $conditionBuilder = new PreparedStatementConditionBuilder();
-               $conditionBuilder->add('conversation_to_user.participantID = ?', array(WCF::getUser()->userID));
-               $conditionBuilder->add('conversation_to_user.conversationID IN (?)', array($this->conversationIDs));
-               $conditionBuilder->add('conversation_to_user.hideConversation <> ?', array(Conversation::STATE_LEFT));
-               
-               $sql = "SELECT          conversation.*
-                       FROM            wcf".WCF_N."_conversation_to_user conversation_to_user
-                       LEFT JOIN       wcf".WCF_N."_conversation conversation
-                       ON              (conversation.conversationID = conversation_to_user.conversationID)
-                       ".$conditionBuilder;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute($conditionBuilder->getParameters());
-               while ($conversation = $statement->fetchObject('\wcf\data\conversation\Conversation')) {
-                       $this->conversations[$conversation->conversationID] = $conversation;
-               }
-       }
-}
index b53c9057afd856bf7e24ad1216bcff23a5951b3e..1b4567ad131af67d212486de3bd97d55fc5463b8 100644 (file)
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationMessageEditForm"><![CDATA[Konversationsnachricht bearbeiten]]></item>
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationListPage"><![CDATA[Konversationen]]></item>
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationPage"><![CDATA[Konversation]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationAdd"><![CDATA[Neue Konversation]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationList"><![CDATA[Konversationenliste]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationMessageAdd"><![CDATA[Antwort erstellen in Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationMessageEdit"><![CDATA[Nachricht bearbeiten in Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
        </category>
        
        <category name="wcf.search">
                <item name="wcf.user.option.conversationsPerPage"><![CDATA[Konversationen pro Seite]]></item>
                <item name="wcf.user.option.canSendConversation"><![CDATA[Kann Konversationen schreiben]]></item>
        </category>
-       
-       <category name="wcf.user.usersOnline">
-               <item name="wcf.user.usersOnline.location.ConversationAddForm"><![CDATA[Erstellt eine neue Konversation]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationListPage"><![CDATA[Betrachtet die Liste seiner Konversationen]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationMessageAddForm"><![CDATA[Schreibt eine Antwort auf die Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationMessageEditForm"><![CDATA[Bearbeitet eine Nachricht in der Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationPage"><![CDATA[Liest die Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-       </category>
 </language>
index 2613b1f2902439145384a7e8c33ca4a6afd04635..81a27d17fdf240ca2201980967158367e0e8e166 100644 (file)
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationMessageEditForm"><![CDATA[Edit Conversation Message]]></item>
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationListPage"><![CDATA[Conversations]]></item>
                <item name="wcf.page.com.woltlab.wcf.conversation.ConversationPage"><![CDATA[Conversation]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationAdd"><![CDATA[Create Conversation]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationList"><![CDATA[Conversation List]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationMessageAdd"><![CDATA[Reply to conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.ConversationMessageEdit"><![CDATA[Edit message in conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
        </category>
        
        <category name="wcf.search">
                <item name="wcf.user.option.conversationsPerPage"><![CDATA[Conversations Per Page]]></item>
                <item name="wcf.user.option.canSendConversation"><![CDATA[Can Add Me to Conversations]]></item>
        </category>
-       
-       <category name="wcf.user.usersOnline">
-               <item name="wcf.user.usersOnline.location.ConversationAddForm"><![CDATA[Creating a conversation]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationListPage"><![CDATA[Viewing list of conversations]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationMessageAddForm"><![CDATA[Writing a reply to conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationMessageEditForm"><![CDATA[Editing message in conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-               <item name="wcf.user.usersOnline.location.ConversationPage"><![CDATA[Reading conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
-       </category>
 </language>
index a37b38ec39bf6e360be3ef63650a36f3dcfad39d..2c3e2018384fc4df6bc623c7ae2165d4a4c3b686 100644 (file)
                </type>
                <!-- /Modification Log -->
                
-               <!-- user online locations -->
-               <type>
-                       <name>com.woltlab.wcf.conversation.ConversationListPage</name>
-                       <definitionname>com.woltlab.wcf.user.online.location</definitionname>
-                       <controller>wcf\page\ConversationListPage</controller>
-                       <languagevariable>wcf.user.usersOnline.location.ConversationListPage</languagevariable>
-               </type>
-               <type>
-                       <name>com.woltlab.wcf.conversation.ConversationAddForm</name>
-                       <definitionname>com.woltlab.wcf.user.online.location</definitionname>
-                       <controller>wcf\form\ConversationAddForm</controller>
-                       <languagevariable>wcf.user.usersOnline.location.ConversationAddForm</languagevariable>
-               </type>
-               <type>
-                       <name>com.woltlab.wcf.conversation.ConversationPage</name>
-                       <definitionname>com.woltlab.wcf.user.online.location</definitionname>
-                       <classname>wcf\system\user\online\location\ConversationLocation</classname>
-                       <controller>wcf\page\ConversationPage</controller>
-                       <languagevariable>wcf.user.usersOnline.location.ConversationPage</languagevariable>
-               </type>
-               <type>
-                       <name>com.woltlab.wcf.conversation.ConversationMessageAddForm</name>
-                       <definitionname>com.woltlab.wcf.user.online.location</definitionname>
-                       <classname>wcf\system\user\online\location\ConversationLocation</classname>
-                       <controller>wcf\form\ConversationMessageAddForm</controller>
-                       <languagevariable>wcf.user.usersOnline.location.ConversationMessageAddForm</languagevariable>
-               </type>
-               <type>
-                       <name>com.woltlab.wcf.conversation.ConversationMessageEditForm</name>
-                       <definitionname>com.woltlab.wcf.user.online.location</definitionname>
-                       <classname>wcf\system\user\online\location\ConversationLocation</classname>
-                       <controller>wcf\form\ConversationMessageEditForm</controller>
-                       <languagevariable>wcf.user.usersOnline.location.ConversationMessageEditForm</languagevariable>
-               </type>
-               <!-- /user online locations -->
-               
                <!-- importers -->
                <type>
                        <name>com.woltlab.wcf.conversation</name>
index 44b4cb59856f05b5714344ce2afe2a1713c3765c..fc5ba114a41e54bc366e190e8af309ec6b017785 100644 (file)
@@ -35,5 +35,6 @@
                <instruction type="userOption" />
                <instruction type="eventListener" />
                <instruction type="script">acp/install_com.woltlab.wcf.conversation.php</instruction>
+               <instruction type="page" />
        </instructions>
 </package>
diff --git a/page.xml b/page.xml
new file mode 100644 (file)
index 0000000..2d5aa63
--- /dev/null
+++ b/page.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/maelstrom/page.xsd">
+       <import>
+               <page identifier="com.woltlab.wcf.conversation.ConversationList">
+                       <controller>wcf\page\ConversationListPage</controller>
+                       <name language="de"><![CDATA[Konversationenliste]]></name>
+                       <name language="en"><![CDATA[Conversation List]]></name>
+                       <pagetype>system</pagetype>
+               </page>
+               <page identifier="com.woltlab.wcf.conversation.Conversation">
+                       <controller>wcf\page\ConversationPage</controller>
+                       <handler>wcf\system\page\handler\DefaultConversationRelatedPageHandler</handler>
+                       <name language="de"><![CDATA[Konversation]]></name>
+                       <name language="en"><![CDATA[Conversation]]></name>
+                       <pagetype>system</pagetype>
+               </page>
+               <page identifier="com.woltlab.wcf.conversation.ConversationAdd">
+                       <controller>wcf\form\ConversationAddForm</controller>
+                       <handler>wcf\system\page\handler\DefaultConversationRelatedPageHandler</handler>
+                       <name language="de"><![CDATA[Konversation starten]]></name>
+                       <name language="en"><![CDATA[New Conversation]]></name>
+                       <pagetype>system</pagetype>
+               </page>
+               <page identifier="com.woltlab.wcf.conversation.ConversationMessageAdd">
+                       <controller>wcf\form\ConversationMessageAddForm</controller>
+                       <handler>wcf\system\page\handler\DefaultConversationRelatedPageHandler</handler>
+                       <name language="de"><![CDATA[Antwort auf Konversation erstellen]]></name>
+                       <name language="en"><![CDATA[Reply to Conversation]]></name>
+                       <pagetype>system</pagetype>
+                       <requireObjectID>1</requireObjectID>
+               </page>
+               <page identifier="com.woltlab.wcf.conversation.ConversationMessageEdit">
+                       <controller>wcf\form\ConversationMessageEditForm</controller>
+                       <name language="de"><![CDATA[Antwort auf Konversation bearbeiten]]></name>
+                       <name language="en"><![CDATA[Edit Reply to Conversation]]></name>
+                       <pagetype>system</pagetype>
+                       <requireObjectID>1</requireObjectID>
+               </page>
+       </import>
+</data>