public static function getPcpDashboardInfo($contactId) {
$links = self::pcpLinks();
- $query = "
+ $query = '
SELECT pcp.*, block.is_tellfriend_enabled FROM civicrm_pcp pcp
LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id
WHERE pcp.is_active = 1
AND pcp.contact_id = %1
-ORDER BY page_type, page_id";
+ORDER BY page_type, page_id';
$params = [1 => [$contactId, 'Integer']];
$hide = $mask = array_sum(array_keys($links['all']));
$contactPCPPages = [];
- $event = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
- $contribute = CRM_Contribute_PseudoConstant::contributionPage();
- $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
- $approved = CRM_Utils_Array::key('Approved', $pcpStatus);
+ $approved = CRM_Core_PseudoConstant::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
while ($pcpInfoDao->fetch()) {
$mask = $hide;
}
$action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'),
FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id);
- $component = $pcpInfoDao->page_type;
- $pageTitle = CRM_Utils_Array::value($pcpInfoDao->page_id, $$component);
+
+ $pageTitle = self::getPcpTitle($pcpInfoDao->page_type, (int) $pcpInfoDao->page_id);
$pcpInfo[] = [
'pageTitle' => $pageTitle,
'pcpId' => $pcpInfoDao->id,
'pcpTitle' => $pcpInfoDao->title,
- 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id],
+ 'pcpStatus' => CRM_Core_PseudoConstant::getLabel('CRM_PCP_BAO_PCP', 'status_id', $pcpInfoDao->status_id),
'action' => $action,
'class' => $class,
];
$pcpLink = $links['add'];
$action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'),
FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id);
- $component = $pcpBlockDao->target_entity_type;
- if ($pageTitle = CRM_Utils_Array::value($pcpBlockDao->target_entity_id, $$component)) {
+ $pageTitle = self::getPcpTitle($pcpBlockDao->target_entity_type, (int) $pcpBlockDao->target_entity_id);
+ if ($pageTitle) {
$pcpBlock[] = [
'pageId' => $pcpBlockDao->target_entity_id,
'pageTitle' => $pageTitle,
}
}
+ /**
+ * Get the title of the pcp.
+ *
+ * @param string $component
+ * @param int $id
+ *
+ * @return bool|string|null
+ */
+ protected static function getPcpTitle(string $component, int $id) {
+ if ($component === 'contribute') {
+ return CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_page_id', $id);
+ }
+ return CRM_Core_PseudoConstant::getLabel('CRM_Event_BAO_Participant', 'event_id', $id);
+ }
+
}
use CRMTraits_PCP_PCPTestTrait;
/**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
+ * Clean up after test.
+ *
+ * @throws \CRM_Core_Exception
*/
- protected function setUp() {
- parent::setUp();
+ public function tearDown() {
+ $this->quickCleanUpFinancialEntities();
+ parent::tearDown();
}
public function testAddPCPBlock() {
$this->assertEquals($params['tellfriend_limit'], $pcpBlock->tellfriend_limit, 'Check for tell friend limit .');
$this->assertEquals($params['link_text'], $pcpBlock->link_text, 'Check for link text.');
$this->assertEquals($params['is_active'], $pcpBlock->is_active, 'Check for is_active.');
- // Delete our test object
- $delParams = ['id' => $pcpBlock->id];
- // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
- // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCPBlock', $delParams );
}
public function testAddPCP() {
$this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll, 'Check for is_honor_roll.');
$this->assertEquals($params['goal_amount'], $pcp->goal_amount, 'Check for goal_amount.');
$this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
-
- // Delete our test object
- $delParams = ['id' => $pcp->id];
- // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
- // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
}
public function testAddPCPNoStatus() {
$blockParams = $this->pcpBlockParams();
- $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams, TRUE);
+ $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams);
$params = $this->pcpParams();
$params['pcp_block_id'] = $pcpBlock->id;
$this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll, 'Check for is_honor_roll.');
$this->assertEquals($params['goal_amount'], $pcp->goal_amount, 'Check for goal_amount.');
$this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
-
- // Delete our test object
- $delParams = ['id' => $pcp->id];
- // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
- // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
}
public function testDeletePCP() {
$pcp = CRM_Core_DAO::createTestObject('CRM_PCP_DAO_PCP');
$pcpId = $pcp->id;
- $del = CRM_PCP_BAO_PCP::deleteById($pcpId);
- $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId,
- 'Database check PCP deleted successfully.'
- );
+ CRM_PCP_BAO_PCP::deleteById($pcpId);
+ $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId, 'Database check PCP deleted successfully.');
}
/**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
+ * Get getPCPDashboard info function.
+ *
+ * @throws \CRM_Core_Exception
*/
- protected function tearDown() {
+ public function testGetPcpDashboardInfo() {
+ $block = CRM_PCP_BAO_PCPBlock::create($this->pcpBlockParams());
+ $contactID = $this->individualCreate();
+ $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([
+ [],
+ [
+ [
+ 'pageTitle' => $contributionPage['title'],
+ 'action' => '<span><a href="/index.php?q=civicrm/pcp/info&action=update&reset=1&id=' . $contributionPage['id'] . '&component=contribute" class="action-item crm-hover-button" title=\'Configure\' >Edit Your Page</a><a href="/index.php?q=civicrm/friend&eid=1&blockId=1&reset=1&pcomponent=pcp&component=contribute" class="action-item crm-hover-button" title=\'Tell Friends\' >Tell Friends</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/pcp/info&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'URL for this Page\' >URL for this Page</a></li><li><a href="/index.php?q=civicrm/pcp/info&action=browse&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'Update Contact Information\' >Update Contact Information</a></li><li><a href="/index.php?q=civicrm/pcp&action=disable&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'Disable\' >Disable</a></li><li><a href="/index.php?q=civicrm/pcp&action=delete&reset=1&id=1&component=contribute" class="action-item crm-hover-button small-popup" title=\'Delete\' onclick = "return confirm(\'Are you sure you want to delete this Personal Campaign Page?\nThis action cannot be undone.\');">Delete</a></li></ul></span>',
+ 'pcpId' => 1,
+ 'pcpTitle' => 'pcp',
+ 'pcpStatus' => 'Approved',
+ 'class' => '',
+ ],
+ ],
+ ], CRM_PCP_BAO_PCP::getPcpDashboardInfo($contactID));
}
}