This add function is really wierd & blocking writing an api for pcp - this will get past issues in #7878
* 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);
// 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();
--- /dev/null
+<?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;
+ }
+
+}
$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,
$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();
}
$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']);
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.');
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.');
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.');