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

New Entity Personals Campaign API using CiviCRM core methods PCP examples included #9017

Closed
wants to merge 1 commit into from
Closed
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
97 changes: 97 additions & 0 deletions api/v3/Personalcampaign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* Not implemented yet
*/
function civicrm_api3_personalcampaign_create($params) {
//return civicrm_api3_create_success($personalsArray, $params, 'Entity', 'get', $personalsBAO);
}

/**
* Gets a Personalcampaign data according to ID PCP.
*
* @param array $params
* Array per getfields documentation.
*
* @return array API result array
* API result array
*/
function civicrm_api3_personalcampaign_get($params) {
//Getting the User id currently
if (!empty($params['contact_id'])) {
//System core PCP
$pcp = new CRM_PCP_BAO_PCP();
global $base_url;

/* Getting pcp by user */
$personalCamp = $pcp->getPcpDashboardInfo($params['contact_id']);

//Formating data to show later
$datapcp = array();
$n = 0;
foreach ($personalCamp[1] as $pcpdata) {
/* Getting pcp info */
$prms = array('id' => $pcpdata["pcpId"]);
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);

$datapcp[$n]["pcpId"] = $pcpdata["pcpId"];
$datapcp[$n]["pageTitle"] = $pcpdata["pageTitle"];
$datapcp[$n]["pcpTitle"] = $pcpdata["pcpTitle"];
$datapcp[$n]["pcpStatus"] = $pcpdata["pcpStatus"];
$datapcp[$n]["pcpGoalAmount"] = $pcpInfo["goal_amount"];
$datapcp[$n]["pcpAmount"] = $pcp->thermoMeter($pcpdata["pcpId"]);
$datapcp[$n]["pcpLink"] = $base_url."/index.php?q=civicrm/pcp/info&reset=1&id=".$pcpdata["pcpId"];
$datapcp[$n]["pcpEditLink"] = $base_url."/index.php?q=civicrm/pcp/info&action=update&reset=1&id=".$pcpdata["pcpId"]."&context=dashboard";
$datapcp[$n]["contribPage"] = $pcp->getPcpPageTitle($pcpdata["pcpId"], "contribute");
$datapcp[$n]["eventPage"] = $pcp->getPcpPageTitle($pcpdata["pcpId"], "event");
$datapcp[$n]["idscontributions"] = array();
foreach ($pcp->honorRoll($pcpdata["pcpId"]) as $coontrid => $contribs){
$urlcontrib = $base_url."/index.php?q=civicrm/contact/view/contribution&reset=1&id=".$coontrid."&cid=34&action=view&context=search&selectedChild=contribute";
$datapcp[$n]["idscontributions"][] = "<a target='_blank' href='".$urlcontrib."'>".$contribs["total_amount"]." ".$contribs["nickname"]."</a>";
}

/* If not found contributions, show notification */
if (empty($datapcp[$n]["idscontributions"])) {
$datapcp[$n]["idscontributions"][] = "Not Found Contributions";
}

$datapcp[$n]["noContribs"] = count($pcp->honorRoll($pcpdata["pcpId"]));
$n++;
}
}else{
throw new API_Exception(ts("Unable to return list, contact_id not exist."));
}

//legacy custom data get - so previous formatted response is still returned too
return civicrm_api3_create_success($datapcp, $params, 'Personalcampaign', 'get');
}

/**
* Delete the PCP.
*
* @param int $pcpId
* PCP pcpId.
*/

function civicrm_api3_personalcampaign_delete($params) {

if (!empty($params["id"]) and isset($params["id"]) and is_numeric($params["id"])) {
$pcp = new CRM_PCP_DAO_PCP();

//$pcp = new CRM_PCP_BAO_PCP();
/* Avoid possible error deleting pcp */
try {
//$pcp->deleteById($params["pcpId"]);
$pcp->id = $params["id"];
$pcp->delete();

return civicrm_api3_create_success(1, $params, 'Personalcampaign', 'delete');

} catch (Exception $e) {
/* possible error catchable */
throw new API_Exception('Could not delete PCP, error during the deletion');
}
}else {
throw new API_Exception('Could not delete PCP, params id incorrect or null'.$params["id"]);
}
}
89 changes: 89 additions & 0 deletions api/v3/examples/Personalcampaign/Personalcampaign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Test Generated example demonstrating the Personalcampaign.get API.
*
* @return array
* API result array
*/
function personalcampaign_get_example() {

try{
$result = civicrm_api3('Personalcampaign', 'get', array(
'sequential' => 1,
'contact_id' => 202,
));
}
catch (CiviCRM_API3_Exception $e) {
// Handle error here.
$errorMessage = $e->getMessage();
$errorCode = $e->getErrorCode();
$errorData = $e->getExtraParams();
return array(
'error' => $errorMessage,
'error_code' => $errorCode,
'error_data' => $errorData,
);
}

return $result;
}

/**
* Test Generated example demonstrating the Personalcampaign.delete API.
*/
function personalcampaign_delete_example() {

try{
$result = civicrm_api3('Personalcampaign', 'delete', array(
'sequential' => 1,
'id' => 12,
));
}
catch (CiviCRM_API3_Exception $e) {
// Handle error here.
$errorMessage = $e->getMessage();
$errorCode = $e->getErrorCode();
$errorData = $e->getExtraParams();
return array(
'error' => $errorMessage,
'error_code' => $errorCode,
'error_data' => $errorData,
);
}

return $result;
}
/**
* Function returns array of result expected from previous function.
*
* @return array
* API result array
*/
function personalcampaign_get_expectedresult() {
$expectedResult = array(
'is_error' => 0,
'version' => 3,
'count' => 1,
'id' => 1,
"values" => array(
'0' => array(
"pcpId" => "1",
"pageTitle" => "Help Support CiviCRM!",
"pcpTitle" => "My Personal Civi Fundraiser",
"pcpStatus" => "Approved",
"pcpGoalAmount" => "5000.00",
"pcpAmount" => "260.00",
"pcpLink" => "http =>//xxxxxxxxxxxxxxxxxxx.com/index.php?q=civicrm/pcp/info&reset=1&id=1",
"pcpEditLink" => "xxxxxxxxxxxxxx/index.php?q=civicrm/pcp/info&action=update&reset=1&id=1&context=dashboard",
"contribPage" => "Help Support CiviCRM!",
"eventPage" => "Fall Fundraiser Dinner",
"idscontributions" => array(
"$ 10.00 Jones Family",
"$ 250.00 Annie And The Kids"
),
"noContribs" => "2"
)
);

return $expectedResult;
}