From f6bc51fd3b2a14e1e7fa9ecdaa088d210dffcd8f Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 14 Jul 2016 00:25:10 +1200 Subject: [PATCH] CRM-18191 CRM-19064 refactor bizareness from PCP create to enable api fn. This add function is really wierd & blocking writing an api for pcp - this will get past issues in #7878 --- CRM/PCP/BAO/PCP.php | 16 ++------- CRM/PCP/BAO/PCPBlock.php | 49 +++++++++++++++++++++++++++ CRM/PCP/Form/Campaign.php | 2 +- CRM/PCP/Form/Contribute.php | 2 +- CRM/PCP/Form/Event.php | 2 +- tests/phpunit/CRM/PCP/BAO/PCPTest.php | 10 +++--- 6 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 CRM/PCP/BAO/PCPBlock.php diff --git a/CRM/PCP/BAO/PCP.php b/CRM/PCP/BAO/PCP.php index c4e9eacf60..1f15ae9df2 100644 --- a/CRM/PCP/BAO/PCP.php +++ b/CRM/PCP/BAO/PCP.php @@ -50,20 +50,11 @@ class CRM_PCP_BAO_PCP extends CRM_PCP_DAO_PCP { * Add or update either a Personal Campaign Page OR a PCP Block. * * @param array $params - * Reference array contains the values submitted by the form. - * @param bool $pcpBlock - * If true, create or update PCPBlock, else PCP. + * Values to create the pcp. * * @return object */ - public static function add(&$params, $pcpBlock = TRUE) { - if ($pcpBlock) { - // action is taken depending upon the mode - $dao = new CRM_PCP_DAO_PCPBlock(); - $dao->copyValues($params); - $dao->save(); - return $dao; - } + public static function create($params) { $dao = new CRM_PCP_DAO_PCP(); $dao->copyValues($params); @@ -76,8 +67,7 @@ class CRM_PCP_BAO_PCP extends CRM_PCP_DAO_PCP { // set currency for CRM-1496 if (!isset($dao->currency)) { - $config = &CRM_Core_Config::singleton(); - $dao->currency = $config->defaultCurrency; + $dao->currency = CRM_Core_Config::singleton()->defaultCurrency; } $dao->save(); diff --git a/CRM/PCP/BAO/PCPBlock.php b/CRM/PCP/BAO/PCPBlock.php new file mode 100644 index 0000000000..c3ed984873 --- /dev/null +++ b/CRM/PCP/BAO/PCPBlock.php @@ -0,0 +1,49 @@ +copyValues($params); + $dao->save(); + return $dao; + } + +} diff --git a/CRM/PCP/Form/Campaign.php b/CRM/PCP/Form/Campaign.php index 8754d02517..2e8a98aa4b 100644 --- a/CRM/PCP/Form/Campaign.php +++ b/CRM/PCP/Form/Campaign.php @@ -242,7 +242,7 @@ class CRM_PCP_Form_Campaign extends CRM_Core_Form { $params['id'] = $this->_pageId; - $pcp = CRM_PCP_BAO_PCP::add($params, FALSE); + $pcp = CRM_PCP_BAO_PCP::create($params); // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, diff --git a/CRM/PCP/Form/Contribute.php b/CRM/PCP/Form/Contribute.php index fbae456f0c..70c6504e45 100644 --- a/CRM/PCP/Form/Contribute.php +++ b/CRM/PCP/Form/Contribute.php @@ -167,7 +167,7 @@ class CRM_PCP_Form_Contribute extends CRM_Contribute_Form_ContributionPage { $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE); $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE); - $dao = CRM_PCP_BAO_PCP::add($params); + CRM_PCP_BAO_PCPBlock::create($params); parent::endPostProcess(); } diff --git a/CRM/PCP/Form/Event.php b/CRM/PCP/Form/Event.php index 0c93711d32..af1644163d 100644 --- a/CRM/PCP/Form/Event.php +++ b/CRM/PCP/Form/Event.php @@ -206,7 +206,7 @@ class CRM_PCP_Form_Event extends CRM_Event_Form_ManageEvent { $params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE); $params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE); - $dao = CRM_PCP_BAO_PCP::add($params); + CRM_PCP_BAO_PCPBlock::create($params); // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = !empty($params['is_active']); diff --git a/tests/phpunit/CRM/PCP/BAO/PCPTest.php b/tests/phpunit/CRM/PCP/BAO/PCPTest.php index 887ff81453..e6327d4687 100644 --- a/tests/phpunit/CRM/PCP/BAO/PCPTest.php +++ b/tests/phpunit/CRM/PCP/BAO/PCPTest.php @@ -44,7 +44,7 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { public function testAddPCPBlock() { $params = $this->pcpBlockParams(); - $pcpBlock = CRM_PCP_BAO_PCP::add($params, TRUE); + $pcpBlock = CRM_PCP_BAO_PCPBlock::create($params); $this->assertInstanceOf('CRM_PCP_DAO_PCPBlock', $pcpBlock, 'Check for created object'); $this->assertEquals($params['entity_table'], $pcpBlock->entity_table, 'Check for entity table.'); @@ -63,12 +63,12 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { public function testAddPCP() { $blockParams = $this->pcpBlockParams(); - $pcpBlock = CRM_PCP_BAO_PCP::add($blockParams, TRUE); + $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams); $params = $this->pcpParams(); $params['pcp_block_id'] = $pcpBlock->id; - $pcp = CRM_PCP_BAO_PCP::add($params, FALSE); + $pcp = CRM_PCP_BAO_PCP::create($params); $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object'); $this->assertEquals($params['contact_id'], $pcp->contact_id, 'Check for entity table.'); @@ -90,13 +90,13 @@ class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase { public function testAddPCPNoStatus() { $blockParams = $this->pcpBlockParams(); - $pcpBlock = CRM_PCP_BAO_PCP::add($blockParams, TRUE); + $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams, TRUE); $params = $this->pcpParams(); $params['pcp_block_id'] = $pcpBlock->id; unset($params['status_id']); - $pcp = CRM_PCP_BAO_PCP::add($params, FALSE); + $pcp = CRM_PCP_BAO_PCP::create($params); $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object'); $this->assertEquals($params['contact_id'], $pcp->contact_id, 'Check for entity table.'); -- 2.25.1