Permalink
Browse files

ENHANCEMENT Using ->request in LeftAndMain->currentPageID()

MINOR Documentation in LeftAndMain

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92760 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 23bac6e commit c65800aa5791124747a9996463e8bb807132cbf8 @chillu chillu committed Nov 21, 2009
Showing with 36 additions and 6 deletions.
  1. +36 −6 code/LeftAndMain.php
View
42 code/LeftAndMain.php
@@ -846,28 +846,58 @@ public function printable() {
);
}
+ /**
+ * Identifier for the currently shown record,
+ * in most cases a database ID. Inspects the following
+ * sources (in this order):
+ * - GET/POST parameter named 'ID'
+ * - URL parameter named 'ID'
+ * - Session value namespaced by classname, e.g. "CMSMain.currentPage"
+ *
+ * @return int
+ */
public function currentPageID() {
- if(isset($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) {
- return $_REQUEST['ID'];
- } elseif (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
- return $this->urlParams['ID'];
+ if($this->request->getVar('ID')) {
+ return $this->request->getVar('ID');
+ } elseif ($this->request->param('ID')) {
+ return $this->request->param('ID');
} elseif(Session::get("{$this->class}.currentPage")) {
return Session::get("{$this->class}.currentPage");
} else {
return null;
}
}
+ /**
+ * Forces the current page to be set in session,
+ * which can be retrieved later through {@link currentPageID()}.
+ * Keep in mind that setting an ID through GET/POST or
+ * as a URL parameter will overrule this value.
+ *
+ * @param int $id
+ */
public function setCurrentPageID($id) {
Session::set("{$this->class}.currentPage", $id);
}
+ /**
+ * Uses {@link getRecord()} and {@link currentPageID()}
+ * to get the currently selected record.
+ *
+ * @return DataObject
+ */
public function currentPage() {
return $this->getRecord($this->currentPageID());
}
- public function isCurrentPage(DataObject $page) {
- return $page->ID == Session::get("{$this->class}.currentPage");
+ /**
+ * Compares a given record to the currently selected one (if any).
+ * Used for marking the current tree node.
+ *
+ * @return boolean
+ */
+ public function isCurrentPage(DataObject $record) {
+ return ($record->ID == $this->currentPageID());
}
/**

0 comments on commit c65800a

Please sign in to comment.