INFRA-132 - CRM/ - PHPStorm cleanup
[civicrm-core.git] / CRM / Utils / Pager.php
index cc92c5b397dfbe389327cb3f3cc8d503e492ed25..d69f822d461d5bccdb22e2f890a54ba736baa81f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -51,12 +51,12 @@ require_once 'Pager/Sliding.php';
 class CRM_Utils_Pager extends Pager_Sliding {
 
   /**
-   * constants for static parameters of the pager
+   * Constants for static parameters of the pager
    */
-  CONST ROWCOUNT = 50, PAGE_ID = 'crmPID', PAGE_ID_TOP = 'crmPID', PAGE_ID_BOTTOM = 'crmPID_B', PAGE_ROWCOUNT = 'crmRowCount';
+  const ROWCOUNT = 50, PAGE_ID = 'crmPID', PAGE_ID_TOP = 'crmPID', PAGE_ID_BOTTOM = 'crmPID_B', PAGE_ROWCOUNT = 'crmRowCount';
 
   /**
-   * the output of the pager. This is a name/value array with various keys
+   * The output of the pager. This is a name/value array with various keys
    * that an application could use to display the pager
    * @var array
    */
@@ -68,7 +68,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
    * We have embedded some html in this class. Need to figure out how to export this
    * to the top level at some point in time
    *
-   * @param $params
+   * @param array $params
    *
    * @internal param \total $int the total count of items to be displayed
    * @internal param \currentPage $int the page currently being displayed
@@ -78,9 +78,10 @@ class CRM_Utils_Pager extends Pager_Sliding {
    * @internal param \csvString $string the title of the link to be displayed for the export
    * @internal param \perPage $int the number of items displayed per page
    *
-   * @return \CRM_Utils_Pager the newly created and initialized pager object@access public
+   * @return \CRM_Utils_Pager the newly created and initialized pager object
+   * @access public
    */
-  function __construct($params) {
+  public function __construct($params) {
     if ($params['status'] === NULL) {
       $params['status'] = ts('Contacts %%StatusMessage%%');
     }
@@ -124,23 +125,28 @@ class CRM_Utils_Pager extends Pager_Sliding {
      * page variable, but a different form element for one at the bottom
      *
      */
-    $this->_response['titleTop'] = ts('Page %1 of %2', array(1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID . '" type="text" value="' . $this->_response['currentPage'] . '" />', 2 => $this->_response['numPages']));
-    $this->_response['titleBottom'] = ts('Page %1 of %2', array(1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID_BOTTOM . '" type="text" value="' . $this->_response['currentPage'] . '" />', 2 => $this->_response['numPages']));
+    $this->_response['titleTop'] = ts('Page %1 of %2', array(
+        1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID . '" type="text" value="' . $this->_response['currentPage'] . '" />',
+        2 => $this->_response['numPages']
+      ));
+    $this->_response['titleBottom'] = ts('Page %1 of %2', array(
+        1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID_BOTTOM . '" type="text" value="' . $this->_response['currentPage'] . '" />',
+        2 => $this->_response['numPages']
+      ));
   }
 
   /**
-   * helper function to assign remaining pager options as good default
+   * Helper function to assign remaining pager options as good default
    * values
    *
-   * @param array   $params      the set of options needed to initialize the parent
+   * @param array $params
+   *   The set of options needed to initialize the parent.
    *                             constructor
    *
-   * @access public
    *
    * @return void
-   *
    */
-  function initialize(&$params) {
+  public function initialize(&$params) {
     /* set the mode for the pager to Sliding */
 
     $params['mode'] = 'Sliding';
@@ -165,7 +171,6 @@ class CRM_Utils_Pager extends Pager_Sliding {
     $params['prevImg'] = ' ' . ts('&lt; Previous');
     $params['nextImg'] = ts('Next &gt;') . ' ';
 
-
     // set first and last text fragments
     $params['firstPagePre'] = '';
     $params['firstPageText'] = ' ' . ts('&lt;&lt; First');
@@ -190,33 +195,34 @@ class CRM_Utils_Pager extends Pager_Sliding {
    * POST over-rides a GET, a POST at the top overrides
    * a POST at the bottom (of the page)
    *
-   * @param int $defaultPageId defaultPageId   current pageId
+   * @param int $defaultPageId
+   *   DefaultPageId current pageId.
    *
-   * @param $params
+   * @param array $params
    *
-   * @return int                new pageId to display to the user
-   * @access public
+   * @return int
+   *   new pageId to display to the user
    */
-  function getPageID($defaultPageId = 1, &$params) {
+  public function getPageID($defaultPageId = 1, &$params) {
     // POST has higher priority than GET vars
     // else if a value is set that has higher priority and finally the GET var
     $currentPage = $defaultPageId;
     if (!empty($_POST)) {
       if (isset($_POST[CRM_Utils_Array::value('buttonTop', $params)]) && isset($_POST[self::PAGE_ID])) {
-        $currentPage = max((int )@$_POST[self::PAGE_ID], 1);
+        $currentPage = max((int ) @$_POST[self::PAGE_ID], 1);
       }
       elseif (isset($_POST[$params['buttonBottom']]) && isset($_POST[self::PAGE_ID_BOTTOM])) {
-        $currentPage = max((int )@$_POST[self::PAGE_ID_BOTTOM], 1);
+        $currentPage = max((int ) @$_POST[self::PAGE_ID_BOTTOM], 1);
       }
       elseif (isset($_POST[self::PAGE_ID])) {
-        $currentPage = max((int )@$_POST[self::PAGE_ID], 1);
+        $currentPage = max((int ) @$_POST[self::PAGE_ID], 1);
       }
       elseif (isset($_POST[self::PAGE_ID_BOTTOM])) {
-        $currentPage = max((int )@$_POST[self::PAGE_ID_BOTTOM]);
+        $currentPage = max((int ) @$_POST[self::PAGE_ID_BOTTOM]);
       }
     }
     elseif (isset($_GET[self::PAGE_ID])) {
-      $currentPage = max((int )@$_GET[self::PAGE_ID], 1);
+      $currentPage = max((int ) @$_GET[self::PAGE_ID], 1);
     }
     return $currentPage;
   }
@@ -224,19 +230,19 @@ class CRM_Utils_Pager extends Pager_Sliding {
   /**
    * Get the number of rows to display from either a GET / POST variable
    *
-   * @param int $defaultPageRowCount the default value if not set
-   *
-   * @return int                     the rowCount value to use
-   * @access public
+   * @param int $defaultPageRowCount
+   *   The default value if not set.
    *
+   * @return int
+   *   the rowCount value to use
    */
-  function getPageRowCount($defaultPageRowCount = self::ROWCOUNT) {
+  public function getPageRowCount($defaultPageRowCount = self::ROWCOUNT) {
     // POST has higher priority than GET vars
     if (isset($_POST[self::PAGE_ROWCOUNT])) {
-      $rowCount = max((int )@$_POST[self::PAGE_ROWCOUNT], 1);
+      $rowCount = max((int ) @$_POST[self::PAGE_ROWCOUNT], 1);
     }
     elseif (isset($_GET[self::PAGE_ROWCOUNT])) {
-      $rowCount = max((int )@$_GET[self::PAGE_ROWCOUNT], 1);
+      $rowCount = max((int ) @$_GET[self::PAGE_ROWCOUNT], 1);
     }
     else {
       $rowCount = $defaultPageRowCount;
@@ -249,12 +255,10 @@ class CRM_Utils_Pager extends Pager_Sliding {
    *
    * @param void
    *
-   * @return array: an array of the pageID and offset
-   *
-   * @access public
-   *
+   * @return array
+   *   an array of the pageID and offset
    */
-  function getOffsetAndRowCount() {
+  public function getOffsetAndRowCount() {
     $pageId = $this->getCurrentPageID();
     if (!$pageId) {
       $pageId = 1;
@@ -268,7 +272,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
   /**
    * @return string
    */
-  function getCurrentLocation() {
+  public function getCurrentLocation() {
     $config = CRM_Core_Config::singleton();
     $path = CRM_Utils_Array::value($config->userFrameworkURLVar, $_GET);
     return CRM_Utils_System::url($path, CRM_Utils_System::getLinksUrl(self::PAGE_ID, FALSE, TRUE), FALSE, NULL, FALSE) . $this->getCurrentPageID();
@@ -277,45 +281,33 @@ class CRM_Utils_Pager extends Pager_Sliding {
   /**
    * @return string
    */
-  function getFirstPageLink() {
+  public function getFirstPageLink() {
     if ($this->isFirstPage()) {
       return '';
     }
-
     $href = $this->makeURL(self::PAGE_ID, 1);
-    return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
-      $href,
-      str_replace('%d', 1, $this->_altFirst),
-      $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
-    ) . $this->_spacesBefore . $this->_spacesAfter;
+    return $this->formatLink($href, str_replace('%d', 1, $this->_altFirst), $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost) .
+    $this->_spacesBefore . $this->_spacesAfter;
   }
 
   /**
    * @return string
    */
-  function getLastPageLink() {
+  public function getLastPageLink() {
     if ($this->isLastPage()) {
       return '';
     }
-
     $href = $this->makeURL(self::PAGE_ID, $this->_totalPages);
-    return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
-      $href,
-      str_replace('%d', $this->_totalPages, $this->_altLast),
-      $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
-    );
+    return $this->formatLink($href, str_replace('%d', $this->_totalPages, $this->_altLast), $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost);
   }
 
   /**
    * @return string
    */
-  function getBackPageLink() {
+  public function getBackPageLink() {
     if ($this->_currentPage > 1) {
       $href = $this->makeURL(self::PAGE_ID, $this->getPreviousPageID());
-      return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
-        $href,
-        $this->_altPrev, $this->_prevImg
-      ) . $this->_spacesBefore . $this->_spacesAfter;
+      return $this->formatLink($href, $this->_altPrev, $this->_prevImg) . $this->_spacesBefore . $this->_spacesAfter;
     }
     return '';
   }
@@ -323,13 +315,12 @@ class CRM_Utils_Pager extends Pager_Sliding {
   /**
    * @return string
    */
-  function getNextPageLink() {
+  public function getNextPageLink() {
     if ($this->_currentPage < $this->_totalPages) {
       $href = $this->makeURL(self::PAGE_ID, $this->getNextPageID());
-      return $this->_spacesAfter . sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
-        $href,
-        $this->_altNext, $this->_nextImg
-      ) . $this->_spacesBefore . $this->_spacesAfter;
+      return $this->_spacesAfter .
+      $this->formatLink($href, $this->_altNext, $this->_nextImg) .
+      $this->_spacesBefore . $this->_spacesAfter;
     }
     return '';
   }
@@ -337,13 +328,23 @@ class CRM_Utils_Pager extends Pager_Sliding {
   /**
    * Build a url for pager links
    */
-  function makeURL($key, $value) {
-    $href = CRM_Utils_System::makeURL($key);
+  public function makeURL($key, $value) {
+    $href = CRM_Utils_System::makeURL($key, TRUE);
     // CRM-12212 Remove alpha sort param
     if (strpos($href, '&amp;sortByCharacter=')) {
       $href = preg_replace('#(.*)\&amp;sortByCharacter=[^&]*(.*)#', '\1\2', $href);
     }
     return $href . $value;
   }
-}
 
+  /**
+   * Output the html pager link
+   * @param string $href
+   * @param string $title
+   * @param string $image
+   * @return string
+   */
+  private function formatLink($href, $title, $image) {
+    return sprintf('<a class="crm-pager-link action-item crm-hover-button" href="%s" title="%s">%s</a>', $href, $title, $image);
+  }
+}