From c3d127137e0af0daecfd179f3d5edf47c6532f58 Mon Sep 17 00:00:00 2001 From: Herb v/d Dool Date: Thu, 26 Aug 2021 10:50:00 -0400 Subject: [PATCH] dev/core#899 filter PCPs where events/contrib pages are disabled --- CRM/PCP/BAO/PCP.php | 22 +++++++++++++++---- .../CRM/Contribute/Page/PcpUserDashboard.tpl | 6 ++--- tests/phpunit/CRM/PCP/BAO/PCPTest.php | 10 ++++++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CRM/PCP/BAO/PCP.php b/CRM/PCP/BAO/PCP.php index 9b6afa3dc5..2c539decbd 100644 --- a/CRM/PCP/BAO/PCP.php +++ b/CRM/PCP/BAO/PCP.php @@ -89,8 +89,12 @@ WHERE civicrm_pcp.contact_id = civicrm_contact.id */ public static function getPcpDashboardInfo($contactId) { $query = ' -SELECT pcp.*, block.is_tellfriend_enabled FROM civicrm_pcp pcp +SELECT pcp.*, block.is_tellfriend_enabled, +COALESCE(cp.end_date, event.end_date) as end_date +FROM civicrm_pcp pcp LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id +LEFT OUTER JOIN civicrm_contribution_page cp ON (cp.id = pcp.page_id AND pcp.page_type = "contribute") +LEFT OUTER JOIN civicrm_event event ON (event.id = pcp.page_id AND pcp.page_type = "event") WHERE pcp.is_active = 1 AND pcp.contact_id = %1 ORDER BY page_type, page_id'; @@ -140,6 +144,7 @@ ORDER BY page_type, page_id'; 'pcpId' => $pcpInfoDao->id, 'pcpTitle' => $pcpInfoDao->title, 'pcpStatus' => CRM_Core_PseudoConstant::getLabel('CRM_PCP_BAO_PCP', 'status_id', $pcpInfoDao->status_id), + 'end_date' => $pcpInfoDao->end_date, 'action' => $action, 'class' => $class, ]; @@ -158,12 +163,19 @@ AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )"; } $query = " -SELECT * +SELECT block.*, +COALESCE(cp.end_date, event.end_date) as end_date FROM civicrm_pcp_block block -LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id +LEFT OUTER JOIN civicrm_contribution_page cp ON (cp.id = block.target_entity_id AND block.target_entity_type = 'contribute') +LEFT OUTER JOIN civicrm_event event ON (event.id = block.target_entity_id AND block.target_entity_type = 'event') WHERE block.is_active = 1 {$clause} -GROUP BY block.id, pcp.id + AND (cp.is_active = 1 OR event.is_active = 1) + AND ( + (block.target_entity_type = 'contribute' AND (cp.end_date >= DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') OR cp.end_date IS NULL)) + OR + (block.target_entity_type = 'event' AND (event.end_date >= DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') OR event.end_date IS NULL))) +GROUP BY block.id, block.target_entity_id ORDER BY target_entity_type, target_entity_id "; $pcpBlockDao = CRM_Core_DAO::executeQuery($query); @@ -184,7 +196,9 @@ ORDER BY target_entity_type, target_entity_id if ($pageTitle) { $pcpBlock[] = [ 'pageId' => $pcpBlockDao->target_entity_id, + 'pageComponent' => $pcpBlockDao->target_entity_type, 'pageTitle' => $pageTitle, + 'end_date' => $pcpBlockDao->end_date, 'action' => $action, ]; } diff --git a/templates/CRM/Contribute/Page/PcpUserDashboard.tpl b/templates/CRM/Contribute/Page/PcpUserDashboard.tpl index 23c59e8283..551af64483 100644 --- a/templates/CRM/Contribute/Page/PcpUserDashboard.tpl +++ b/templates/CRM/Contribute/Page/PcpUserDashboard.tpl @@ -49,10 +49,10 @@ {strip} {if $pcpInfo} {* Change layout and text if they already have a PCP. *}
-
+
{ts}Create a Personal Campaign Page for another campaign:{/ts}
{else} -
+
{ts}Become a supporter by creating a Personal Campaign Page:{/ts}
{/if} @@ -64,7 +64,7 @@ {foreach from=$pcpBlock item=row} - + diff --git a/tests/phpunit/CRM/PCP/BAO/PCPTest.php b/tests/phpunit/CRM/PCP/BAO/PCPTest.php index 798647f467..aac73bb4af 100644 --- a/tests/phpunit/CRM/PCP/BAO/PCPTest.php +++ b/tests/phpunit/CRM/PCP/BAO/PCPTest.php @@ -95,6 +95,13 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { public function testGetPcpDashboardInfo() { $block = CRM_PCP_BAO_PCPBlock::create($this->pcpBlockParams()); $contactID = $this->individualCreate(); + $submitParams = [ + 'id' => 1, + 'financial_type_id' => 1, + 'start_date' => date('Y-m-d 00:00:00'), + 'end_date' => date('Y-m-d 00:00:00', strtotime('+8 weeks')), + ]; + $contributionUpdate = $this->callAPISuccess('ContributionPage', 'create', $submitParams); $contributionPage = $this->callAPISuccessGetSingle('ContributionPage', []); $this->callAPISuccess('Pcp', 'create', ['contact_id' => $contactID, 'title' => 'pcp', 'page_id' => $contributionPage['id'], 'pcp_block_id' => $block->id, 'is_active' => TRUE, 'status_id' => 'Approved']); $this->assertEquals([ @@ -103,10 +110,11 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { [ 'pageTitle' => $contributionPage['title'], 'action' => 'Edit Your PageTell Friendsmore', - 'pcpId' => 1, + 'pcpId' => '1', 'pcpTitle' => 'pcp', 'pcpStatus' => 'Approved', 'class' => '', + 'end_date' => date('Y-m-d 00:00:00', strtotime('+8 weeks')), ], ], ], CRM_PCP_BAO_PCP::getPcpDashboardInfo($contactID)); -- 2.25.1
{if $row.component eq 'contribute'}{else}{/if}{$row.pageTitle}{if $row.pageComponent eq 'contribute'}{else}{/if}{$row.pageTitle} {if $row.end_date}{$row.end_date|truncate:10:''|crmDate}{else}({ts}ongoing{/ts}){/if} {$row.action|replace:'xx':$row.pageId}