X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FPage%2FContributionPage.php;h=d432da34a8be4d31605f90648904cd78e2560a77;hb=1633df8c26f4f5f0d52eb3fa3a0a72aaa4f29bc7;hp=67b6c8639b0114da90cdea8466d90864920f6389;hpb=a3379cc1fcfcbee4f6acca9330d96af6beb2fc55;p=civicrm-core.git diff --git a/CRM/Contribute/Page/ContributionPage.php b/CRM/Contribute/Page/ContributionPage.php index 67b6c8639b..d432da34a8 100644 --- a/CRM/Contribute/Page/ContributionPage.php +++ b/CRM/Contribute/Page/ContributionPage.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @@ -56,10 +56,14 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { private static $_configureActionLinks; private static $_onlineContributionLinks; - private static $_links = NULL; - + /** + * @var CRM_Utils_Pager + */ protected $_pager = NULL; + /** + * @var string + */ protected $_sortByCharacter; /** @@ -67,7 +71,7 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { * * @return array */ - function &actionLinks() { + public function &actionLinks() { // check if variable _actionsLinks is populated if (!isset(self::$_actionLinks)) { // helper variable for nicer formatting @@ -268,7 +272,7 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { * type of action and executes that action. * Finally it calls the parent's run method. * - * @return void + * @return mixed */ public function run() { // get the requested action @@ -284,18 +288,21 @@ 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' ), - )); + ), + ); // what action to take ? if ($action & CRM_Core_Action::ADD) { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), - 'action=browse&reset=1' - )); + 'action=browse&reset=1' + )); $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action); CRM_Utils_System::setTitle(ts('Manage Contribution Page')); @@ -314,6 +321,9 @@ 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(); @@ -323,8 +333,8 @@ class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), - 'reset=1&action=browse' - )); + 'reset=1&action=browse' + )); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0 @@ -362,7 +372,7 @@ AND cp.page_type = 'contribute' } /** - * This function is to make a copy of a contribution page, including + * make a copy of a contribution page, including * all the fields in the page * * @return void @@ -380,16 +390,17 @@ AND cp.page_type = 'contribute' /** * Browse all contribution pages * - * @param null $action - * - * @return void - * @static + * @param mixed $action + * Unused parameter. */ public function browse($action = NULL) { $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $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 ); @@ -462,15 +473,15 @@ ORDER BY title asc $action += array_sum(array_keys(self::contributionLinks())); if ($dao->is_active) { - $action -= CRM_Core_Action::ENABLE; + $action -= (int) CRM_Core_Action::ENABLE; } else { - $action -= CRM_Core_Action::DISABLE; + $action -= (int) CRM_Core_Action::DISABLE; } //CRM-4418 if (!$allowToDelete) { - $action -= CRM_Core_Action::DELETE; + $action -= (int) CRM_Core_Action::DELETE; } //build the configure links. @@ -528,8 +539,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 ) @@ -554,8 +564,9 @@ ORDER BY title asc * @return int|string */ public function whereClause(&$params, $sortBy = TRUE) { - $values = $clauses = array(); - $title = $this->get('title'); + // @todo Unused local variable can be safely removed. + $values = $clauses = array(); + $title = $this->get('title'); $createdId = $this->get('cid'); if ($createdId) { @@ -572,7 +583,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)) { @@ -583,22 +594,17 @@ ORDER BY title asc } $type = implode(',', $val); } - - $clauses[] = "financial_type_id IN ({$type})"; + // @todo Variable 'type' might not have been defined. + $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)) . "%'"; } - $campainIds = $this->get('campaign_id'); - if (!CRM_Utils_System::isNull($campainIds)) { - if (!is_array($campainIds)) { - $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)) { @@ -613,6 +619,23 @@ ORDER BY title asc return implode(' AND ', $clauses); } + /** + * Gets the campaign ids from the session. + * + * @return int[] + */ + public 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 @@ -630,8 +653,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); @@ -646,10 +669,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); @@ -658,12 +681,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); @@ -671,11 +694,6 @@ SELECT count(id) continue; } - $classes = array(); - if (isset($link['class'])) { - $classes = $link['class']; - } - if (empty($sectionsInfo[$sectionName])) { $classes = array(); if (isset($link['class'])) { @@ -687,4 +705,5 @@ SELECT count(id) return $formattedConfLinks; } + }