Update code of third part of tutorial series
[GitHub/WoltLab/woltlab.github.io.git] / snippets / tutorial / tutorial-series / part-3 / files / lib / system / page / handler / PersonPageHandler.class.php
index 58819b63f0b34ce3044b7a252c9d067c23ea2d28..353900bba59d04953a7acf00e97d0228b6ca595e 100644 (file)
@@ -1,5 +1,7 @@
 <?php
+
 namespace wcf\system\page\handler;
+
 use wcf\data\page\Page;
 use wcf\data\person\PersonList;
 use wcf\data\user\online\UserOnline;
@@ -9,88 +11,94 @@ use wcf\system\WCF;
 
 /**
  * Page handler implementation for person page.
- * 
- * @author     Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\System\Page\Handler
+ *
+ * @author  Matthias Schmidt
+ * @copyright   2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Page\Handler
  */
-class PersonPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler {
-       use TOnlineLocationPageHandler;
-       
-       /**
-        * @inheritDoc
-        */
-       public function getLink($objectID) {
-               return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink();
-       }
-       
-       /**
-        * Returns the textual description if a user is currently online viewing this page.
-        *
-        * @see IOnlineLocationPageHandler::getOnlineLocation()
-        *
-        * @param       Page            $page           visited page
-        * @param       UserOnline      $user           user online object with request data
-        * @return      string
-        */
-       public function getOnlineLocation(Page $page, UserOnline $user) {
-               if ($user->pageObjectID === null) {
-                       return '';
-               }
-               
-               $person = PersonRuntimeCache::getInstance()->getObject($user->pageObjectID);
-               if ($person === null) {
-                       return '';
-               }
-               
-               return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['person' => $person]);
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function isValid($objectID = null) {
-               return PersonRuntimeCache::getInstance()->getObject($objectID) !== null;
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function lookup($searchString) {
-               $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR');
-               $conditionBuilder->add('person.firstName LIKE ?', ['%' . $searchString . '%']);
-               $conditionBuilder->add('person.lastName LIKE ?', ['%' . $searchString . '%']);
-               
-               $personList = new PersonList();
-               $personList->getConditionBuilder()->add($conditionBuilder, $conditionBuilder->getParameters());
-               $personList->readObjects();
-               
-               $results = [];
-               foreach ($personList as $person) {
-                       $results[] = [
-                               'image' => 'fa-user',
-                               'link' => $person->getLink(),
-                               'objectID' => $person->personID,
-                               'title' => $person->getTitle()
-                       ];
-               }
-               
-               return $results;
-       }
-       
-       /**
-        * Prepares fetching all necessary data for the textual description if a user is currently online
-        * viewing this page.
-        * 
-        * @see IOnlineLocationPageHandler::prepareOnlineLocation()
-        *
-        * @param       Page            $page           visited page
-        * @param       UserOnline      $user           user online object with request data
-        */
-       public function prepareOnlineLocation(/** @noinspection PhpUnusedParameterInspection */Page $page, UserOnline $user) {
-               if ($user->pageObjectID !== null) {
-                       PersonRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID);
-               }
-       }
+class PersonPageHandler extends AbstractLookupPageHandler implements IOnlineLocationPageHandler
+{
+    use TOnlineLocationPageHandler;
+
+    /**
+     * @inheritDoc
+     */
+    public function getLink($objectID)
+    {
+        return PersonRuntimeCache::getInstance()->getObject($objectID)->getLink();
+    }
+
+    /**
+     * Returns the textual description if a user is currently online viewing this page.
+     *
+     * @see IOnlineLocationPageHandler::getOnlineLocation()
+     *
+     * @param   Page        $page       visited page
+     * @param   UserOnline  $user       user online object with request data
+     * @return  string
+     */
+    public function getOnlineLocation(Page $page, UserOnline $user)
+    {
+        if ($user->pageObjectID === null) {
+            return '';
+        }
+
+        $person = PersonRuntimeCache::getInstance()->getObject($user->pageObjectID);
+        if ($person === null) {
+            return '';
+        }
+
+        return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.' . $page->identifier, ['person' => $person]);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function isValid($objectID = null)
+    {
+        return PersonRuntimeCache::getInstance()->getObject($objectID) !== null;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function lookup($searchString)
+    {
+        $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR');
+        $conditionBuilder->add('person.firstName LIKE ?', ['%' . $searchString . '%']);
+        $conditionBuilder->add('person.lastName LIKE ?', ['%' . $searchString . '%']);
+
+        $personList = new PersonList();
+        $personList->getConditionBuilder()->add($conditionBuilder, $conditionBuilder->getParameters());
+        $personList->readObjects();
+
+        $results = [];
+        foreach ($personList as $person) {
+            $results[] = [
+                'image' => 'fa-user',
+                'link' => $person->getLink(),
+                'objectID' => $person->personID,
+                'title' => $person->getTitle(),
+            ];
+        }
+
+        return $results;
+    }
+
+    /**
+     * Prepares fetching all necessary data for the textual description if a user is currently online
+     * viewing this page.
+     *
+     * @see IOnlineLocationPageHandler::prepareOnlineLocation()
+     *
+     * @param   Page        $page       visited page
+     * @param   UserOnline  $user       user online object with request data
+     */
+    public function prepareOnlineLocation(Page $page, UserOnline $user)
+    {
+        if ($user->pageObjectID !== null) {
+            PersonRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID);
+        }
+    }
 }