Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-18191 CRM-19064 refactor bizareness from PCP create to enable api… #8697

Merged
merged 2 commits into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions CRM/PCP/BAO/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,11 @@ public function __construct() {
* 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);
Expand All @@ -76,8 +67,7 @@ public static function add(&$params, $pcpBlock = TRUE) {

// 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();
Expand Down
49 changes: 49 additions & 0 deletions CRM/PCP/BAO/PCPBlock.php
Original file line number Diff line number Diff line change
@@ -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;
}

}
2 changes: 1 addition & 1 deletion CRM/PCP/Form/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function postProcess() {

$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,
Expand Down
2 changes: 1 addition & 1 deletion CRM/PCP/Form/Contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function postProcess() {
$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();
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/PCP/Form/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function postProcess() {
$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']);
Expand Down
3 changes: 3 additions & 0 deletions api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ function _civicrm_api_get_entity_name_from_camel($entity) {
if (!$entity || $entity === strtolower($entity)) {
return $entity;
}
elseif ($entity == 'PCP') {
return 'pcp';
}
else {
$entity = ltrim(strtolower(str_replace('U_F',
'uf',
Expand Down
2 changes: 1 addition & 1 deletion api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function _civicrm_api3_get_DAO($name) {
return 'CRM_SMS_DAO_Provider';
}
// FIXME: DAO names should follow CamelCase convention
if ($name == 'Im' || $name == 'Acl') {
if ($name == 'Im' || $name == 'Acl' || $name == 'Pcp') {
$name = strtoupper($name);
}
$dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/CRM/PCP/BAO/PCPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp() {
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.');
Expand All @@ -63,12 +63,12 @@ public function testAddPCPBlock() {

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.');
Expand All @@ -90,13 +90,13 @@ public function testAddPCP() {

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.');
Expand Down