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

Update CampaignStat.php #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
70 changes: 64 additions & 6 deletions api/v3/CampaignStat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,53 @@
| written permission from the original author(s). |
+--------------------------------------------------------*/

// Using CRM_CampaignManager_ExtensionUtil namespace for translations (E::ts)
use CRM_CampaignManager_ExtensionUtil as E;

// Include the required class for campaign tree operations
require_once 'CRM/CampaignManager/CampaignTree/Tree.php';

/**
* Define API parameters for the campaign stat activity counter function.
* This function sets up the parameters expected by the API.
*
* @param array $params The parameters array
*/
function _civicrm_api3_campaign_stat_activity_counter(&$params) {
// Define the 'id' parameter with metadata
$params['id'] = array(
'name' => 'id',
'title' => E::ts('Campaign ID'),
'description' => E::ts('ID of parent campaign'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 1,
'api.default' => 0,
'type' => CRM_Utils_Type::T_INT, // Integer type
'api.required' => 1, // Required parameter
'api.default' => 0, // Default value
);
}

/**
* Fetch and return activity statistics for a given campaign and its children.
*
* @param array $params The input parameters from the API request
* @return array The result of the campaign activity counter
*/
function civicrm_api3_campaign_stat_activity_counter($params) {
try {
// Get the campaign ID from the parameters
$campaignId = $params['id'];

// Retrieve the IDs of the campaign and its child campaigns
$campaigns = CRM_CampaignManager_CampaignTree_Tree::getCampaignIds($campaignId, 99);
$children = $campaigns['children'];

// Call the KPI activity counter function
$stat = CRM_CampaignManager_KPIActivity::activityCounter($campaignId, $children);

// Return the result in a successful API response
return civicrm_api3_create_success($stat, $params);
}
catch (Exception $exception) {
// Handle any exceptions and return an error response
$data = array(
'params' => $params,
'exception' => array(
Expand All @@ -51,26 +74,46 @@ function civicrm_api3_campaign_stat_activity_counter($params) {
}
}

/**
* Define API parameters for the campaign stat activity report function.
*
* @param array $params The parameters array
*/
function _civicrm_api3_campaign_stat_activity_report(&$params) {
// Define the 'id' parameter with metadata
$params['id'] = array(
'name' => 'id',
'title' => E::ts('Campaign ID'),
'description' => E::ts('ID of parent campaign'),
'type' => CRM_Utils_Type::T_INT,
'api.required' => 1,
'api.default' => 0,
'type' => CRM_Utils_Type::T_INT, // Integer type
'api.required' => 1, // Required parameter
'api.default' => 0, // Default value
);
}

/**
* Fetch and return an activity report for a given campaign and its children.
*
* @param array $params The input parameters from the API request
* @return array The result of the campaign activity report
*/
function civicrm_api3_campaign_stat_activity_report($params) {
try {
// Get the campaign ID from the parameters
$campaignId = $params['id'];

// Retrieve the IDs of the campaign and its child campaigns
$campaigns = CRM_CampaignManager_CampaignTree_Tree::getCampaignIds($campaignId, 99);
$children = $campaigns['children'];

// Call the KPI activity report function
$stat = CRM_CampaignManager_KPIActivity::activityReport($campaignId, $children);

// Return the result in a successful API response
return civicrm_api3_create_success($stat, $params);
}
catch (Exception $exception) {
// Handle any exceptions and return an error response
$data = array(
'params' => $params,
'exception' => array(
Expand All @@ -84,14 +127,29 @@ function civicrm_api3_campaign_stat_activity_report($params) {
}
}

/**
* Define API parameters for the campaign stat activity sequence function.
* This function does not currently define any parameters.
*
* @param array $params The parameters array
*/
function _civicrm_api3_campaign_stat_activity_sequence(&$params) {
// Currently no parameters are required for this API.
}

/**
* Fetch and return the sequence of campaign activities.
*
* @param array $params The input parameters from the API request
* @return array The result of the campaign activity sequence
*/
function civicrm_api3_campaign_stat_activity_sequence($params) {
try {
// Call the KPI activity sequence function and return the result
return civicrm_api3_create_success(CRM_CampaignManager_KPIActivity::sequence(), $params);
}
catch (Exception $exception) {
// Handle any exceptions and return an error response
$data = array(
'params' => $params,
'exception' => array(
Expand Down