INFRA-132 - CRM/Contribute - phpcbf
[civicrm-core.git] / CRM / Contribute / Page / ContributionPage.php
index 64452f5332b9a390cbe7e3e62a63cc0e275bf86b..ae80cd90df544c092958e64ca430826685cc3a60 100644 (file)
@@ -56,9 +56,6 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page {
   private static $_configureActionLinks;
   private static $_onlineContributionLinks;
 
-  // @todo Unused private field can be safely removed.
-  private static $_links = NULL;
-
   /**
    * @var CRM_Utils_Pager
    */
@@ -291,7 +288,8 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page {
     );
 
     // set breadcrumb to append to 2nd layer pages
-    $breadCrumb = array(array('title' => ts('Manage Contribution Pages'),
+    $breadCrumb = array(array(
+    'title' => ts('Manage Contribution Pages'),
         'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(),
           'reset=1'
         ),
@@ -322,6 +320,8 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page {
     }
     elseif ($action & CRM_Core_Action::COPY) {
       // @todo Unused local variable can be safely removed.
+      // But are there any side effects of CRM_Core_Session::singleton() that we
+      // need to preserve?
       $session = CRM_Core_Session::singleton();
       CRM_Core_Session::setStatus(ts('A copy of the contribution page has been created'), ts('Successfully Copied'), 'success');
       $this->copy();
@@ -398,6 +398,8 @@ AND         cp.page_type = 'contribute'
       $this
     );
     // @todo Unused local variable can be safely removed.
+    // But are there any side effects of CRM_Utils_Request::retrieve() that we
+    // need to preserve?
     $createdId = CRM_Utils_Request::retrieve('cid', 'Positive',
       $this, FALSE, 0
     );
@@ -470,15 +472,15 @@ ORDER BY title asc
       $action += array_sum(array_keys(self::contributionLinks()));
 
       if ($dao->is_active) {
-        $action -= (int)CRM_Core_Action::ENABLE;
+        $action -= (int) CRM_Core_Action::ENABLE;
       }
       else {
-        $action -= (int)CRM_Core_Action::DISABLE;
+        $action -= (int) CRM_Core_Action::DISABLE;
       }
 
       //CRM-4418
       if (!$allowToDelete) {
-        $action -= (int)CRM_Core_Action::DELETE;
+        $action -= (int) CRM_Core_Action::DELETE;
       }
 
       //build the configure links.
@@ -536,8 +538,7 @@ ORDER BY title asc
   }
 
   public function search() {
-    if (isset($this->_action) &
-      (CRM_Core_Action::ADD |
+    if (isset($this->_action) & (CRM_Core_Action::ADD |
         CRM_Core_Action::UPDATE |
         CRM_Core_Action::DELETE
       )
@@ -581,7 +582,7 @@ ORDER BY title asc
       }
     }
 
-        $value = $this->get( 'financial_type_id' );
+    $value = $this->get( 'financial_type_id' );
     $val = array();
     if ($value) {
       if (is_array($value)) {
@@ -593,23 +594,16 @@ ORDER BY title asc
         $type = implode(',', $val);
       }
       // @todo Variable 'type' might not have been defined.
-             $clauses[] = "financial_type_id IN ({$type})";
+      $clauses[] = "financial_type_id IN ({$type})";
     }
 
-    if ($sortBy &&
-      $this->_sortByCharacter !== NULL
-    ) {
+    if ($sortBy && $this->_sortByCharacter !== NULL) {
       $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'";
     }
 
-    // @todo Fatal typo: $campainIds vs $campaignIds.
-    $campainIds = $this->get('campaign_id');
-    if (!CRM_Utils_System::isNull($campainIds)) {
-      if (!is_array($campainIds)) {
-        // @todo Undefined variable $campaignIds, due to fatal typo above.
-        $campaignIds = array($campaignIds);
-      }
-      $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
+    $campaignIds = $this->getCampaignIds();
+    if (count($campaignIds) >= 1) {
+      $clauses[] = '( campaign_id IN ( ' . implode(' , ', $campaignIds) . ' ) )';
     }
 
     if (empty($clauses)) {
@@ -624,11 +618,28 @@ ORDER BY title asc
     return implode(' AND ', $clauses);
   }
 
+  /**
+   * Gets the campaign ids from the session.
+   *
+   * @return int[]
+   */
+  function getCampaignIds() {
+    // The unfiltered value from the session cannot be trusted, it needs to be
+    // processed to get a clean array of positive integers.
+    $ids = array();
+    foreach ((array) $this->get('campaign_id') as $id) {
+      if ((string) (int) $id === (string) $id && $id > 0) {
+        $ids[] = $id;
+      }
+    }
+    return $ids;
+  }
+
   /**
    * @param $whereClause
    * @param array $whereParams
    */
-  public function pager($whereClause, $whereParams) {
+  function pager($whereClause, $whereParams) {
 
     $params['status'] = ts('Contribution %%StatusMessage%%');
     $params['csvString'] = NULL;
@@ -641,8 +652,8 @@ ORDER BY title asc
 
     $query = "
 SELECT count(id)
-  FROM civicrm_contribution_page
- WHERE $whereClause";
+FROM civicrm_contribution_page
+WHERE $whereClause";
 
     $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams);
 
@@ -657,10 +668,10 @@ SELECT count(id)
   public function pagerAtoZ($whereClause, $whereParams) {
 
     $query = "
-   SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
-     FROM civicrm_contribution_page
-    WHERE $whereClause
- ORDER BY LEFT(title, 1)
+SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
+FROM civicrm_contribution_page
+WHERE $whereClause
+ORDER BY LEFT(title, 1)
 ";
     $dao = CRM_Core_DAO::executeQuery($query, $whereParams);
 
@@ -669,12 +680,12 @@ SELECT count(id)
   }
 
   /**
-   * @param $sectionsInfo
+   * @param array $sectionsInfo
    *
    * @return array
    */
   public function formatConfigureLinks($sectionsInfo) {
-    //build the formatted configure links.
+    // build the formatted configure links.
     $formattedConfLinks = self::configureActionLinks();
     foreach ($formattedConfLinks as $act => & $link) {
       $sectionName = CRM_Utils_Array::value('uniqueName', $link);
@@ -682,12 +693,6 @@ SELECT count(id)
         continue;
       }
 
-      // @todo Unused local variable can be safely removed.
-      $classes = array();
-      if (isset($link['class'])) {
-        $classes = $link['class'];
-      }
-
       if (empty($sectionsInfo[$sectionName])) {
         $classes = array();
         if (isset($link['class'])) {