CRM-18191 CRM-19064 refactor bizareness from PCP create to enable api fn.
authoreileen <emcnaughton@wikimedia.org>
Wed, 13 Jul 2016 12:25:10 +0000 (00:25 +1200)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 15 Sep 2016 11:13:49 +0000 (21:13 +1000)
This add function is really wierd & blocking writing an api for pcp - this will get past issues in #7878

CRM/PCP/BAO/PCP.php
CRM/PCP/BAO/PCPBlock.php [new file with mode: 0644]
CRM/PCP/Form/Campaign.php
CRM/PCP/Form/Contribute.php
CRM/PCP/Form/Event.php
tests/phpunit/CRM/PCP/BAO/PCPTest.php

index c4e9eacf604fa7e1c4d9a52adfa21283ad729e9e..1f15ae9df21bac5675cf6c4fe860625d87b0d810 100644 (file)
@@ -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 (file)
index 0000000..c3ed984
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2016
+ */
+class CRM_PCP_BAO_PCPBlock extends CRM_PCP_DAO_PCPBlock {
+
+  /**
+   * Create or update either a Personal Campaign Page OR a PCP Block.
+   *
+   * @param array $params
+   *
+   * @return CRM_PCP_DAO_PCPBlock
+   */
+  public static function create($params) {
+    $dao = new CRM_PCP_DAO_PCPBlock();
+    $dao->copyValues($params);
+    $dao->save();
+    return $dao;
+  }
+
+}
index 8754d025173e19629a38b1c2d1c1e32e111690a9..2e8a98aa4ba472a4a813e798428b87a24d055168 100644 (file)
@@ -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,
index fbae456f0cd33cfbb6d4486a021dc002973cbd0b..70c6504e459baa56b3a9f307cf7ba038ea793c62 100644 (file)
@@ -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();
   }
index 0c93711d324f0d3ae4b386669676ffba5debfeaa..af1644163df9631fdb3f7ab829aebca9b782070f 100644 (file)
@@ -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']);
index 887ff81453d275af04659af9ab69decc4082ddec..e6327d4687d9ffa1ea488dff45c577674f570eb7 100644 (file)
@@ -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.');