Added method to retrieve the current page id
authorAlexander Ebert <ebert@woltlab.com>
Fri, 8 Apr 2016 10:30:59 +0000 (12:30 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 8 Apr 2016 10:52:49 +0000 (12:52 +0200)
wcfsetup/install/files/lib/system/request/Request.class.php

index 1634c80d056a3018adf09b31ea97ddb532b1bbf5..31436fd3f603cdc953a680f38e1a13519bba060d 100644 (file)
@@ -1,11 +1,12 @@
 <?php
 namespace wcf\system\request;
+use wcf\data\page\PageCache;
 
 /**
  * Represents a page request.
  * 
  * @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
  * @subpackage system.request
@@ -29,6 +30,12 @@ class Request {
         */
        protected $metaData;
        
+       /**
+        * current page id
+        * @var integer
+        */
+       protected $pageID;
+       
        /**
         * page name
         * @var string
@@ -155,4 +162,28 @@ class Request {
                
                return false;
        }
+       
+       /**
+        * Returns the current page id.
+        * 
+        * @return      integer         current page id or `0` if unknown
+        */
+       public function getPageID() {
+               if ($this->pageID === null) {
+                       if (isset($this->metaData['cms'])) {
+                               $this->pageID = $this->metaData['cms']['pageID'];
+                       }
+                       else {
+                               $page = PageCache::getInstance()->getPageByController($this->className);
+                               if ($page !== null) {
+                                       $this->pageID = $page->pageID;
+                               }
+                               else {
+                                       $this->pageID = 0;
+                               }
+                       }
+               }
+               
+               return $this->pageID;
+       }
 }