Merge pull request #3476 from eileenmcnaughton/CRM-14838
[civicrm-core.git] / CRM / Utils / Pager.php
index c25a719f9984623cd199723d8242974daa9fa9cb..db8f3f4148c47d7d36c0c69086e5660993051488 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -274,7 +274,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
    */
   function getPerPageLink($perPage) {
     if ($perPage != $this->_perPage) {
-      $href = CRM_Utils_System::makeURL(self::PAGE_ROWCOUNT) . $perPage;
+      $href = $this->makeURL(self::PAGE_ROWCOUNT, $perPage);
       $link = sprintf('<a href="%s" %s>%s</a>',
         $href,
         $this->_classString,
@@ -293,7 +293,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
       return '';
     }
 
-    $href = CRM_Utils_System::makeURL(self::PAGE_ID) . 1;
+    $href = $this->makeURL(self::PAGE_ID, 1);
     return sprintf('<a href="%s" title="%s">%s</a>',
       $href,
       str_replace('%d', 1, $this->_altFirst),
@@ -306,7 +306,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
       return '';
     }
 
-    $href = CRM_Utils_System::makeURL(self::PAGE_ID) . $this->_totalPages;
+    $href = $this->makeURL(self::PAGE_ID, $this->_totalPages);
     return sprintf('<a href="%s" title="%s">%s</a>',
       $href,
       str_replace('%d', $this->_totalPages, $this->_altLast),
@@ -316,7 +316,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
 
   function getBackPageLink() {
     if ($this->_currentPage > 1) {
-      $href = CRM_Utils_System::makeURL(self::PAGE_ID) . $this->getPreviousPageID();
+      $href = $this->makeURL(self::PAGE_ID, $this->getPreviousPageID());
       return sprintf('<a href="%s" title="%s">%s</a>',
         $href,
         $this->_altPrev, $this->_prevImg
@@ -327,7 +327,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
 
   function getNextPageLink() {
     if ($this->_currentPage < $this->_totalPages) {
-      $href = CRM_Utils_System::makeURL(self::PAGE_ID) . $this->getNextPageID();
+      $href = $this->makeURL(self::PAGE_ID, $this->getNextPageID());
       return $this->_spacesAfter . sprintf('<a href="%s" title="%s">%s</a>',
         $href,
         $this->_altNext, $this->_nextImg
@@ -335,5 +335,17 @@ class CRM_Utils_Pager extends Pager_Sliding {
     }
     return '';
   }
+
+  /**
+   * Build a url for pager links
+   */
+  function makeURL($key, $value) {
+    $href = CRM_Utils_System::makeURL($key);
+    // CRM-12212 Remove alpha sort param
+    if (strpos($href, '&amp;sortByCharacter=')) {
+      $href = preg_replace('#(.*)\&amp;sortByCharacter=[^&]*(.*)#', '\1\2', $href);
+    }
+    return $href . $value;
+  }
 }