Skip to content

Commit

Permalink
CiviCampaign - Delete old dashboard code
Browse files Browse the repository at this point in the history
No longer needed as Campaign dashboard now uses SearchKit
  • Loading branch information
colemanw committed Sep 22, 2023
1 parent a8fb0f1 commit 50a6565
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 2,391 deletions.
154 changes: 0 additions & 154 deletions CRM/Campaign/BAO/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,160 +278,6 @@ public static function isCampaignEnable(): bool {
return self::isComponentEnabled();
}

/**
* Retrieve campaigns for dashboard.
*
* @param array $params
* @param bool $onlyCount
*
* @return array|int
*/
public static function getCampaignSummary($params = [], $onlyCount = FALSE) {
$campaigns = [];

//build the limit and order clause.
$limitClause = $orderByClause = $lookupTableJoins = NULL;
if (!$onlyCount) {
$sortParams = [
'sort' => 'start_date',
'offset' => 0,
'rowCount' => 10,
'sortOrder' => 'desc',
];
foreach ($sortParams as $name => $default) {
if (!empty($params[$name])) {
$sortParams[$name] = $params[$name];
}
}

//need to lookup tables.
$orderOnCampaignTable = TRUE;
if ($sortParams['sort'] === 'status') {
$orderOnCampaignTable = FALSE;
$lookupTableJoins = "
LEFT JOIN civicrm_option_value status ON ( status.value = campaign.status_id OR campaign.status_id IS NULL )
INNER JOIN civicrm_option_group grp ON ( status.option_group_id = grp.id AND grp.name = 'campaign_status' )";
$orderByClause = "ORDER BY status.label {$sortParams['sortOrder']}";
}
elseif ($sortParams['sort'] === 'campaign_type') {
$orderOnCampaignTable = FALSE;
$lookupTableJoins = "
LEFT JOIN civicrm_option_value campaign_type ON ( campaign_type.value = campaign.campaign_type_id
OR campaign.campaign_type_id IS NULL )
INNER JOIN civicrm_option_group grp ON ( campaign_type.option_group_id = grp.id AND grp.name = 'campaign_type' )";
$orderByClause = "ORDER BY campaign_type.label {$sortParams['sortOrder']}";
}
elseif ($sortParams['sort'] === 'isActive') {
$sortParams['sort'] = 'is_active';
}
if ($orderOnCampaignTable) {
$orderByClause = "ORDER BY campaign.{$sortParams['sort']} {$sortParams['sortOrder']}";
}
$orderByClause = ($orderByClause) ? $orderByClause . ", campaign.id {$sortParams['sortOrder']}" : $orderByClause;
$limitClause = "LIMIT {$sortParams['offset']}, {$sortParams['rowCount']}";
}

//build the where clause.
$queryParams = $where = [];
if (!empty($params['id'])) {
$where[] = "( campaign.id = %1 )";
$queryParams[1] = [$params['id'], 'Positive'];
}
if (!empty($params['name'])) {
$where[] = "( campaign.name LIKE %2 )";
$queryParams[2] = ['%' . trim($params['name']) . '%', 'String'];
}
if (!empty($params['title'])) {
$where[] = "( campaign.title LIKE %3 )";
$queryParams[3] = ['%' . trim($params['title']) . '%', 'String'];
}
if (!empty($params['start_date'])) {
$startDate = CRM_Utils_Date::processDate($params['start_date']);
$where[] = "( campaign.start_date >= %4 OR campaign.start_date IS NULL )";
$queryParams[4] = [$startDate, 'String'];
}
if (!empty($params['end_date'])) {
$endDate = CRM_Utils_Date::processDate($params['end_date'], '235959');
$where[] = "( campaign.end_date <= %5 OR campaign.end_date IS NULL )";
$queryParams[5] = [$endDate, 'String'];
}
if (!empty($params['description'])) {
$where[] = "( campaign.description LIKE %6 )";
$queryParams[6] = ['%' . trim($params['description']) . '%', 'String'];
}
if (!empty($params['campaign_type_id'])) {
$where[] = "( campaign.campaign_type_id IN ( %7 ) )";
$queryParams[7] = [implode(',', (array) $params['campaign_type_id']), 'CommaSeparatedIntegers'];
}
if (!empty($params['status_id'])) {
$where[] = "( campaign.status_id IN ( %8 ) )";
$queryParams[8] = [implode(',', (array) $params['status_id']), 'CommaSeparatedIntegers'];
}
if (array_key_exists('is_active', $params)) {
$active = "( campaign.is_active = 1 )";
if (!empty($params['is_active'])) {
$active = "campaign.is_active = 0";
}
$where[] = $active;
}
$whereClause = NULL;
if (!empty($where)) {
$whereClause = ' WHERE ' . implode(" \nAND ", $where);
}

$properties = [
'id',
'name',
'title',
'start_date',
'end_date',
'status_id',
'is_active',
'description',
'campaign_type_id',
];

$selectClause = '
SELECT campaign.id as id,
campaign.name as name,
campaign.title as title,
campaign.is_active as is_active,
campaign.status_id as status_id,
campaign.end_date as end_date,
campaign.start_date as start_date,
campaign.description as description,
campaign.campaign_type_id as campaign_type_id';
if ($onlyCount) {
$selectClause = 'SELECT COUNT(*)';
}
$fromClause = 'FROM civicrm_campaign campaign';

$query = "{$selectClause} {$fromClause} {$lookupTableJoins} {$whereClause} {$orderByClause} {$limitClause}";

//in case of only count.
if ($onlyCount) {
return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
}

$campaign = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($campaign->fetch()) {
foreach ($properties as $property) {
$campaigns[$campaign->id][$property] = $campaign->$property;
}
}

return $campaigns;
}

/**
* Get the campaign count.
*
* @return int
*/
public static function getCampaignCount(): int {
return (int) CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_campaign');
}

/**
* Get Campaigns groups.
*
Expand Down
130 changes: 0 additions & 130 deletions CRM/Campaign/BAO/Petition.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,136 +34,6 @@ public function __construct() {
$this->cookieExpire = (1 * 60 * 60 * 24);
}

/**
* Get Petition Details for dashboard.
*
* @param array $params
* @param bool $onlyCount
*
* @return array|int
*/
public static function getPetitionSummary($params = [], $onlyCount = FALSE) {
//build the limit and order clause.
$limitClause = $orderByClause = $lookupTableJoins = NULL;
if (!$onlyCount) {
$sortParams = [
'sort' => 'created_date',
'offset' => 0,
'rowCount' => 10,
'sortOrder' => 'desc',
];
foreach ($sortParams as $name => $default) {
if (!empty($params[$name])) {
$sortParams[$name] = $params[$name];
}
}

//need to lookup tables.
$orderOnPetitionTable = TRUE;
if ($sortParams['sort'] == 'campaign') {
$orderOnPetitionTable = FALSE;
$lookupTableJoins = '
LEFT JOIN civicrm_campaign campaign ON ( campaign.id = petition.campaign_id )';
$orderByClause = "ORDER BY campaign.title {$sortParams['sortOrder']}";
}
elseif ($sortParams['sort'] == 'activity_type') {
$orderOnPetitionTable = FALSE;
$lookupTableJoins = "
LEFT JOIN civicrm_option_value activity_type ON ( activity_type.value = petition.activity_type_id
OR petition.activity_type_id IS NULL )
INNER JOIN civicrm_option_group grp ON ( activity_type.option_group_id = grp.id AND grp.name = 'activity_type' )";
$orderByClause = "ORDER BY activity_type.label {$sortParams['sortOrder']}";
}
elseif ($sortParams['sort'] == 'isActive') {
$sortParams['sort'] = 'is_active';
}
if ($orderOnPetitionTable) {
$orderByClause = "ORDER BY petition.{$sortParams['sort']} {$sortParams['sortOrder']}";
}
$limitClause = "LIMIT {$sortParams['offset']}, {$sortParams['rowCount']}";
}

//build the where clause.
$queryParams = $where = [];

//we only have activity type as a
//difference between survey and petition.
$petitionTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Petition');
if ($petitionTypeID) {
$where[] = "( petition.activity_type_id = %1 )";
$queryParams[1] = [$petitionTypeID, 'Positive'];
}
if (!empty($params['title'])) {
$where[] = "( petition.title LIKE %2 )";
$queryParams[2] = ['%' . trim($params['title']) . '%', 'String'];
}
if (!empty($params['campaign_id'])) {
$where[] = '( petition.campaign_id = %3 )';
$queryParams[3] = [$params['campaign_id'], 'Positive'];
}
$whereClause = NULL;
if (!empty($where)) {
$whereClause = ' WHERE ' . implode(" \nAND ", $where);
}

$selectClause = '
SELECT petition.id as id,
petition.title as title,
petition.is_active as is_active,
petition.result_id as result_id,
petition.is_default as is_default,
petition.campaign_id as campaign_id,
petition.activity_type_id as activity_type_id';

if ($onlyCount) {
$selectClause = 'SELECT COUNT(*)';
}
$fromClause = 'FROM civicrm_survey petition';

$query = "{$selectClause} {$fromClause} {$whereClause} {$orderByClause} {$limitClause}";

if ($onlyCount) {
return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
}

$petitions = [];
$properties = [
'id',
'title',
'campaign_id',
'is_active',
'is_default',
'result_id',
'activity_type_id',
];

$petition = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($petition->fetch()) {
foreach ($properties as $property) {
$petitions[$petition->id][$property] = $petition->$property;
}
}

return $petitions;
}

/**
* Get the petition count.
*
*/
public static function getPetitionCount() {
$whereClause = 'WHERE ( 1 )';
$queryParams = [];
$petitionTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Petition');
if ($petitionTypeID) {
$whereClause = "WHERE ( petition.activity_type_id = %1 )";
$queryParams[1] = [$petitionTypeID, 'Positive'];
}
$query = "SELECT COUNT(*) FROM civicrm_survey petition {$whereClause}";

return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
}

/**
* Takes an associative array and creates a petition signature activity.
*
Expand Down
Loading

0 comments on commit 50a6565

Please sign in to comment.