First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
710
sites/all/modules/civicrm/CRM/Campaign/BAO/Campaign.php
Normal file
710
sites/all/modules/civicrm/CRM/Campaign/BAO/Campaign.php
Normal file
|
@ -0,0 +1,710 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
|
||||
|
||||
/**
|
||||
* Takes an associative array and creates a campaign object.
|
||||
*
|
||||
* the function extract all the params it needs to initialize the create a
|
||||
* contact object. the params array could contain additional unused name/value
|
||||
* pairs
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return CRM_Campaign_DAO_Campaign
|
||||
*/
|
||||
public static function create(&$params) {
|
||||
if (empty($params)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(CRM_Utils_Array::value('id', $params))) {
|
||||
|
||||
if (!(CRM_Utils_Array::value('created_id', $params))) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$params['created_id'] = $session->get('userID');
|
||||
}
|
||||
|
||||
if (!(CRM_Utils_Array::value('created_date', $params))) {
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
|
||||
if (!(CRM_Utils_Array::value('name', $params))) {
|
||||
$params['name'] = CRM_Utils_String::titleToVar($params['title'], 64);
|
||||
}
|
||||
|
||||
CRM_Utils_Hook::pre('create', 'Campaign', NULL, $params);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_Hook::pre('edit', 'Campaign', $params['id'], $params);
|
||||
}
|
||||
|
||||
$campaign = new CRM_Campaign_DAO_Campaign();
|
||||
$campaign->copyValues($params);
|
||||
$campaign->save();
|
||||
|
||||
if (!empty($params['id'])) {
|
||||
CRM_Utils_Hook::post('edit', 'Campaign', $campaign->id, $campaign);
|
||||
}
|
||||
else {
|
||||
CRM_Utils_Hook::post('create', 'Campaign', $campaign->id, $campaign);
|
||||
}
|
||||
|
||||
/* Create the campaign group record */
|
||||
|
||||
$groupTableName = CRM_Contact_BAO_Group::getTableName();
|
||||
|
||||
if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) {
|
||||
foreach ($params['groups']['include'] as $entityId) {
|
||||
$dao = new CRM_Campaign_DAO_CampaignGroup();
|
||||
$dao->campaign_id = $campaign->id;
|
||||
$dao->entity_table = $groupTableName;
|
||||
$dao->entity_id = $entityId;
|
||||
$dao->group_type = 'Include';
|
||||
$dao->save();
|
||||
$dao->free();
|
||||
}
|
||||
}
|
||||
|
||||
//store custom data
|
||||
if (!empty($params['custom']) &&
|
||||
is_array($params['custom'])
|
||||
) {
|
||||
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_campaign', $campaign->id);
|
||||
}
|
||||
|
||||
return $campaign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the campaign.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the campaign.
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function del($id) {
|
||||
if (!$id) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
$dao = new CRM_Campaign_DAO_Campaign();
|
||||
$dao->id = $id;
|
||||
$result = $dao->delete();
|
||||
|
||||
CRM_Utils_Hook::post('delete', 'Campaign', $id, $dao);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve DB object based on input parameters.
|
||||
*
|
||||
* It also stores all the retrieved values in the default array.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
* @param array $defaults
|
||||
* (reference ) an assoc array to hold the flattened values.
|
||||
*
|
||||
* @return \CRM_Campaign_DAO_Campaign|null
|
||||
*/
|
||||
public static function retrieve(&$params, &$defaults) {
|
||||
$campaign = new CRM_Campaign_DAO_Campaign();
|
||||
|
||||
$campaign->copyValues($params);
|
||||
|
||||
if ($campaign->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($campaign, $defaults);
|
||||
return $campaign;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the all eligible campaigns w/ cache.
|
||||
*
|
||||
* @param int $includeId
|
||||
* Lets inlcude this campaign by force.
|
||||
* @param int $excludeId
|
||||
* Do not include this campaign.
|
||||
* @param bool $onlyActive
|
||||
* Consider only active campaigns.
|
||||
*
|
||||
* @param bool $onlyCurrent
|
||||
* @param bool $appendDatesToTitle
|
||||
* @param bool $forceAll
|
||||
*
|
||||
* @return mixed
|
||||
* $campaigns a set of campaigns.
|
||||
*/
|
||||
public static function getCampaigns(
|
||||
$includeId = NULL,
|
||||
$excludeId = NULL,
|
||||
$onlyActive = TRUE,
|
||||
$onlyCurrent = TRUE,
|
||||
$appendDatesToTitle = FALSE,
|
||||
$forceAll = FALSE
|
||||
) {
|
||||
static $campaigns;
|
||||
$cacheKey = 0;
|
||||
$cacheKeyParams = array(
|
||||
'includeId',
|
||||
'excludeId',
|
||||
'onlyActive',
|
||||
'onlyCurrent',
|
||||
'appendDatesToTitle',
|
||||
'forceAll',
|
||||
);
|
||||
foreach ($cacheKeyParams as $param) {
|
||||
$cacheParam = $$param;
|
||||
if (!$cacheParam) {
|
||||
$cacheParam = 0;
|
||||
}
|
||||
$cacheKey .= '_' . $cacheParam;
|
||||
}
|
||||
|
||||
if (!isset($campaigns[$cacheKey])) {
|
||||
$where = array('( camp.title IS NOT NULL )');
|
||||
if ($excludeId) {
|
||||
$where[] = "( camp.id != $excludeId )";
|
||||
}
|
||||
if ($onlyActive) {
|
||||
$where[] = '( camp.is_active = 1 )';
|
||||
}
|
||||
if ($onlyCurrent) {
|
||||
$where[] = '( camp.end_date IS NULL OR camp.end_date >= NOW() )';
|
||||
}
|
||||
$whereClause = implode(' AND ', $where);
|
||||
if ($includeId) {
|
||||
$whereClause .= " OR ( camp.id = $includeId )";
|
||||
}
|
||||
|
||||
//lets force all.
|
||||
if ($forceAll) {
|
||||
$whereClause = '( 1 )';
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT camp.id,
|
||||
camp.title,
|
||||
camp.start_date,
|
||||
camp.end_date
|
||||
FROM civicrm_campaign camp
|
||||
WHERE {$whereClause}
|
||||
Order By camp.title";
|
||||
|
||||
$campaign = CRM_Core_DAO::executeQuery($query);
|
||||
$campaigns[$cacheKey] = array();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
while ($campaign->fetch()) {
|
||||
$title = $campaign->title;
|
||||
if ($appendDatesToTitle) {
|
||||
$dates = array();
|
||||
foreach (array('start_date', 'end_date') as $date) {
|
||||
if ($campaign->$date) {
|
||||
$dates[] = CRM_Utils_Date::customFormat($campaign->$date, $config->dateformatFull);
|
||||
}
|
||||
}
|
||||
if (!empty($dates)) {
|
||||
$title .= ' (' . implode('-', $dates) . ')';
|
||||
}
|
||||
}
|
||||
$campaigns[$cacheKey][$campaign->id] = $title;
|
||||
}
|
||||
}
|
||||
|
||||
return $campaigns[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to self::getCampaigns( )
|
||||
* w/ permissions and component check.
|
||||
*
|
||||
* @param int $includeId
|
||||
* @param int $excludeId
|
||||
* @param bool $onlyActive
|
||||
* @param bool $onlyCurrent
|
||||
* @param bool $appendDatesToTitle
|
||||
* @param bool $forceAll
|
||||
* @param bool $doCheckForComponent
|
||||
* @param bool $doCheckForPermissions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getPermissionedCampaigns(
|
||||
$includeId = NULL,
|
||||
$excludeId = NULL,
|
||||
$onlyActive = TRUE,
|
||||
$onlyCurrent = TRUE,
|
||||
$appendDatesToTitle = FALSE,
|
||||
$forceAll = FALSE,
|
||||
$doCheckForComponent = TRUE,
|
||||
$doCheckForPermissions = TRUE
|
||||
) {
|
||||
$cacheKey = 0;
|
||||
$cachekeyParams = array(
|
||||
'includeId',
|
||||
'excludeId',
|
||||
'onlyActive',
|
||||
'onlyCurrent',
|
||||
'appendDatesToTitle',
|
||||
'doCheckForComponent',
|
||||
'doCheckForPermissions',
|
||||
'forceAll',
|
||||
);
|
||||
foreach ($cachekeyParams as $param) {
|
||||
$cacheKeyParam = $$param;
|
||||
if (!$cacheKeyParam) {
|
||||
$cacheKeyParam = 0;
|
||||
}
|
||||
$cacheKey .= '_' . $cacheKeyParam;
|
||||
}
|
||||
|
||||
static $validCampaigns;
|
||||
if (!isset($validCampaigns[$cacheKey])) {
|
||||
$isValid = TRUE;
|
||||
$campaigns = array(
|
||||
'campaigns' => array(),
|
||||
'hasAccessCampaign' => FALSE,
|
||||
'isCampaignEnabled' => FALSE,
|
||||
);
|
||||
|
||||
//do check for component.
|
||||
if ($doCheckForComponent) {
|
||||
$campaigns['isCampaignEnabled'] = $isValid = self::isCampaignEnable();
|
||||
}
|
||||
|
||||
//do check for permissions.
|
||||
if ($doCheckForPermissions) {
|
||||
$campaigns['hasAccessCampaign'] = $isValid = self::accessCampaign();
|
||||
}
|
||||
|
||||
//finally retrieve campaigns from db.
|
||||
if ($isValid) {
|
||||
$campaigns['campaigns'] = self::getCampaigns($includeId,
|
||||
$excludeId,
|
||||
$onlyActive,
|
||||
$onlyCurrent,
|
||||
$appendDatesToTitle,
|
||||
$forceAll
|
||||
);
|
||||
}
|
||||
|
||||
//store in cache.
|
||||
$validCampaigns[$cacheKey] = $campaigns;
|
||||
}
|
||||
|
||||
return $validCampaigns[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is CiviCampaign enabled.
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCampaignEnable() {
|
||||
static $isEnable = NULL;
|
||||
|
||||
if (!isset($isEnable)) {
|
||||
$isEnable = FALSE;
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if (in_array('CiviCampaign', $config->enableComponents)) {
|
||||
$isEnable = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return $isEnable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve campaigns for dashboard.
|
||||
*
|
||||
* @param array $params
|
||||
* @param bool $onlyCount
|
||||
*
|
||||
* @return array|int
|
||||
*/
|
||||
public static function getCampaignSummary($params = array(), $onlyCount = FALSE) {
|
||||
$campaigns = array();
|
||||
|
||||
//build the limit and order clause.
|
||||
$limitClause = $orderByClause = $lookupTableJoins = NULL;
|
||||
if (!$onlyCount) {
|
||||
$sortParams = array(
|
||||
'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']}";
|
||||
}
|
||||
$limitClause = "LIMIT {$sortParams['offset']}, {$sortParams['rowCount']}";
|
||||
}
|
||||
|
||||
//build the where clause.
|
||||
$queryParams = $where = array();
|
||||
if (!empty($params['id'])) {
|
||||
$where[] = "( campaign.id = %1 )";
|
||||
$queryParams[1] = array($params['id'], 'Positive');
|
||||
}
|
||||
if (!empty($params['name'])) {
|
||||
$where[] = "( campaign.name LIKE %2 )";
|
||||
$queryParams[2] = array('%' . trim($params['name']) . '%', 'String');
|
||||
}
|
||||
if (!empty($params['title'])) {
|
||||
$where[] = "( campaign.title LIKE %3 )";
|
||||
$queryParams[3] = array('%' . 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] = array($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] = array($endDate, 'String');
|
||||
}
|
||||
if (!empty($params['description'])) {
|
||||
$where[] = "( campaign.description LIKE %6 )";
|
||||
$queryParams[6] = array('%' . trim($params['description']) . '%', 'String');
|
||||
}
|
||||
if (!empty($params['campaign_type_id'])) {
|
||||
$typeId = $params['campaign_type_id'];
|
||||
if (is_array($params['campaign_type_id'])) {
|
||||
$typeId = implode(' , ', $params['campaign_type_id']);
|
||||
}
|
||||
$where[] = "( campaign.campaign_type_id IN ( {$typeId} ) )";
|
||||
}
|
||||
if (!empty($params['status_id'])) {
|
||||
$statusId = $params['status_id'];
|
||||
if (is_array($params['status_id'])) {
|
||||
$statusId = implode(' , ', $params['status_id']);
|
||||
}
|
||||
$where[] = "( campaign.status_id IN ( {$statusId} ) )";
|
||||
}
|
||||
if (array_key_exists('is_active', $params)) {
|
||||
$active = "( campaign.is_active = 1 )";
|
||||
if (!empty($params['is_active'])) {
|
||||
$active = "( campaign.is_active = 0 OR campaign.is_active IS NULL )";
|
||||
}
|
||||
$where[] = $active;
|
||||
}
|
||||
$whereClause = NULL;
|
||||
if (!empty($where)) {
|
||||
$whereClause = ' WHERE ' . implode(" \nAND ", $where);
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'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.
|
||||
*
|
||||
*/
|
||||
public static function getCampaignCount() {
|
||||
return (int) CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_campaign');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Campaigns groups.
|
||||
*
|
||||
* @param int $campaignId
|
||||
* Campaign id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCampaignGroups($campaignId) {
|
||||
static $campaignGroups;
|
||||
if (!$campaignId) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!isset($campaignGroups[$campaignId])) {
|
||||
$campaignGroups[$campaignId] = array();
|
||||
|
||||
$query = "
|
||||
SELECT grp.title, grp.id
|
||||
FROM civicrm_campaign_group campgrp
|
||||
INNER JOIN civicrm_group grp ON ( grp.id = campgrp.entity_id )
|
||||
WHERE campgrp.group_type = 'Include'
|
||||
AND campgrp.entity_table = 'civicrm_group'
|
||||
AND campgrp.campaign_id = %1";
|
||||
|
||||
$groups = CRM_Core_DAO::executeQuery($query, array(1 => array($campaignId, 'Positive')));
|
||||
while ($groups->fetch()) {
|
||||
$campaignGroups[$campaignId][$groups->id] = $groups->title;
|
||||
}
|
||||
}
|
||||
|
||||
return $campaignGroups[$campaignId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the is_active flag in the db.
|
||||
*
|
||||
* @param int $id
|
||||
* Id of the database record.
|
||||
* @param bool $is_active
|
||||
* Value we want to set the is_active field.
|
||||
*
|
||||
* @return CRM_Campaign_DAO_Campaign|null
|
||||
* DAO object on success, null otherwise
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_Campaign_DAO_Campaign', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function accessCampaign() {
|
||||
static $allow = NULL;
|
||||
|
||||
if (!isset($allow)) {
|
||||
$allow = FALSE;
|
||||
if (CRM_Core_Permission::check('manage campaign') ||
|
||||
CRM_Core_Permission::check('administer CiviCampaign')
|
||||
) {
|
||||
$allow = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return $allow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add select element for campaign
|
||||
* and assign needful info to templates.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param int $connectedCampaignId
|
||||
*/
|
||||
public static function addCampaign(&$form, $connectedCampaignId = NULL) {
|
||||
//some forms do set default and freeze.
|
||||
$appendDates = TRUE;
|
||||
if ($form->get('action') & CRM_Core_Action::VIEW) {
|
||||
$appendDates = FALSE;
|
||||
}
|
||||
|
||||
$campaignDetails = self::getPermissionedCampaigns($connectedCampaignId, NULL, TRUE, TRUE, $appendDates);
|
||||
$fields = array('campaigns', 'hasAccessCampaign', 'isCampaignEnabled');
|
||||
foreach ($fields as $fld) {
|
||||
$$fld = CRM_Utils_Array::value($fld, $campaignDetails);
|
||||
}
|
||||
|
||||
//lets see do we have past campaigns.
|
||||
$hasPastCampaigns = FALSE;
|
||||
$allActiveCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE);
|
||||
if (count($allActiveCampaigns) > count($campaigns)) {
|
||||
$hasPastCampaigns = TRUE;
|
||||
}
|
||||
$hasCampaigns = FALSE;
|
||||
if (!empty($campaigns)) {
|
||||
$hasCampaigns = TRUE;
|
||||
}
|
||||
if ($hasPastCampaigns) {
|
||||
$hasCampaigns = TRUE;
|
||||
$form->add('hidden', 'included_past_campaigns');
|
||||
}
|
||||
|
||||
$showAddCampaign = FALSE;
|
||||
$alreadyIncludedPastCampaigns = FALSE;
|
||||
if ($connectedCampaignId || ($isCampaignEnabled && $hasAccessCampaign)) {
|
||||
$showAddCampaign = TRUE;
|
||||
//lets add past campaigns as options to quick-form element.
|
||||
if ($hasPastCampaigns && $form->getElementValue('included_past_campaigns')) {
|
||||
$campaigns = $allActiveCampaigns;
|
||||
$alreadyIncludedPastCampaigns = TRUE;
|
||||
}
|
||||
$campaign = &$form->add('select',
|
||||
'campaign_id',
|
||||
ts('Campaign'),
|
||||
array('' => ts('- select -')) + $campaigns,
|
||||
FALSE,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
//lets freeze when user does not has access or campaign is disabled.
|
||||
if (!$isCampaignEnabled || !$hasAccessCampaign) {
|
||||
$campaign->freeze();
|
||||
}
|
||||
}
|
||||
|
||||
$addCampaignURL = NULL;
|
||||
if (empty($campaigns) && $hasAccessCampaign && $isCampaignEnabled) {
|
||||
$addCampaignURL = CRM_Utils_System::url('civicrm/campaign/add', 'reset=1');
|
||||
}
|
||||
|
||||
$includePastCampaignURL = NULL;
|
||||
if ($hasPastCampaigns && $isCampaignEnabled && $hasAccessCampaign) {
|
||||
$includePastCampaignURL = CRM_Utils_System::url('civicrm/ajax/rest',
|
||||
'className=CRM_Campaign_Page_AJAX&fnName=allActiveCampaigns',
|
||||
FALSE, NULL, FALSE
|
||||
);
|
||||
}
|
||||
|
||||
//carry this info to templates.
|
||||
$infoFields = array(
|
||||
'hasCampaigns',
|
||||
'addCampaignURL',
|
||||
'showAddCampaign',
|
||||
'hasPastCampaigns',
|
||||
'hasAccessCampaign',
|
||||
'isCampaignEnabled',
|
||||
'includePastCampaignURL',
|
||||
'alreadyIncludedPastCampaigns',
|
||||
);
|
||||
foreach ($infoFields as $fld) {
|
||||
$campaignInfo[$fld] = $$fld;
|
||||
}
|
||||
$form->assign('campaignInfo', $campaignInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add campaign in component search.
|
||||
* and assign needful info to templates.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* @param string $elementName
|
||||
*/
|
||||
public static function addCampaignInComponentSearch(&$form, $elementName = 'campaign_id') {
|
||||
$campaignInfo = array();
|
||||
$campaignDetails = self::getPermissionedCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
|
||||
$fields = array('campaigns', 'hasAccessCampaign', 'isCampaignEnabled');
|
||||
foreach ($fields as $fld) {
|
||||
$$fld = CRM_Utils_Array::value($fld, $campaignDetails);
|
||||
}
|
||||
$showCampaignInSearch = FALSE;
|
||||
if ($isCampaignEnabled && $hasAccessCampaign && !empty($campaigns)) {
|
||||
//get the current campaign only.
|
||||
$currentCampaigns = self::getCampaigns(NULL, NULL, FALSE);
|
||||
$pastCampaigns = array_diff($campaigns, $currentCampaigns);
|
||||
$allCampaigns = array();
|
||||
if (!empty($currentCampaigns)) {
|
||||
$allCampaigns = array('crm_optgroup_current_campaign' => ts('Current Campaigns')) + $currentCampaigns;
|
||||
}
|
||||
if (!empty($pastCampaigns)) {
|
||||
$allCampaigns += array('crm_optgroup_past_campaign' => ts('Past Campaigns')) + $pastCampaigns;
|
||||
}
|
||||
|
||||
$showCampaignInSearch = TRUE;
|
||||
$form->add('select', $elementName, ts('Campaigns'), $allCampaigns, FALSE,
|
||||
array('id' => 'campaigns', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
$infoFields = array(
|
||||
'elementName',
|
||||
'hasAccessCampaign',
|
||||
'isCampaignEnabled',
|
||||
'showCampaignInSearch',
|
||||
);
|
||||
foreach ($infoFields as $fld) {
|
||||
$campaignInfo[$fld] = $$fld;
|
||||
}
|
||||
$form->assign('campaignInfo', $campaignInfo);
|
||||
}
|
||||
|
||||
}
|
683
sites/all/modules/civicrm/CRM/Campaign/BAO/Petition.php
Normal file
683
sites/all/modules/civicrm/CRM/Campaign/BAO/Petition.php
Normal file
|
@ -0,0 +1,683 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_BAO_Petition extends CRM_Campaign_BAO_Survey {
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// expire cookie in one day
|
||||
$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 = array(), $onlyCount = FALSE) {
|
||||
//build the limit and order clause.
|
||||
$limitClause = $orderByClause = $lookupTableJoins = NULL;
|
||||
if (!$onlyCount) {
|
||||
$sortParams = array(
|
||||
'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 = array();
|
||||
|
||||
//we only have activity type as a
|
||||
//difference between survey and petition.
|
||||
$petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
|
||||
if ($petitionTypeID) {
|
||||
$where[] = "( petition.activity_type_id = %1 )";
|
||||
$queryParams[1] = array($petitionTypeID, 'Positive');
|
||||
}
|
||||
if (!empty($params['title'])) {
|
||||
$where[] = "( petition.title LIKE %2 )";
|
||||
$queryParams[2] = array('%' . trim($params['title']) . '%', 'String');
|
||||
}
|
||||
if (!empty($params['campaign_id'])) {
|
||||
$where[] = '( petition.campaign_id = %3 )';
|
||||
$queryParams[3] = array($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 = array();
|
||||
$properties = array(
|
||||
'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 = array();
|
||||
$petitionTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'petition', 'name');
|
||||
if ($petitionTypeID) {
|
||||
$whereClause = "WHERE ( petition.activity_type_id = %1 )";
|
||||
$queryParams[1] = array($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.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @return CRM_Campaign_BAO_Petition
|
||||
*/
|
||||
public function createSignature(&$params) {
|
||||
if (empty($params)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!isset($params['sid'])) {
|
||||
$statusMsg = ts('No survey sid parameter. Cannot process signature.');
|
||||
CRM_Core_Session::setStatus($statusMsg, ts('Sorry'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($params['contactId'])) {
|
||||
|
||||
// add signature as activity with survey id as source id
|
||||
// get the activity type id associated with this survey
|
||||
$surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo($params['sid']);
|
||||
|
||||
// create activity
|
||||
// 1-Schedule, 2-Completed
|
||||
|
||||
$activityParams = array(
|
||||
'source_contact_id' => $params['contactId'],
|
||||
'target_contact_id' => $params['contactId'],
|
||||
'source_record_id' => $params['sid'],
|
||||
'subject' => $surveyInfo['title'],
|
||||
'activity_type_id' => $surveyInfo['activity_type_id'],
|
||||
'activity_date_time' => date("YmdHis"),
|
||||
'status_id' => $params['statusId'],
|
||||
'activity_campaign_id' => $params['activity_campaign_id'],
|
||||
);
|
||||
|
||||
//activity creation
|
||||
// *** check for activity using source id - if already signed
|
||||
$activity = CRM_Activity_BAO_Activity::create($activityParams);
|
||||
|
||||
// save activity custom data
|
||||
if (!empty($params['custom']) &&
|
||||
is_array($params['custom'])
|
||||
) {
|
||||
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_activity', $activity->id);
|
||||
}
|
||||
|
||||
// Set browser cookie to indicate this petition was already signed.
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$url_parts = parse_url($config->userFrameworkBaseURL);
|
||||
setcookie('signed_' . $params['sid'], $activity->id, time() + $this->cookieExpire, $url_parts['path'], $url_parts['host'], CRM_Utils_System::isSSL());
|
||||
}
|
||||
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $activity_id
|
||||
* @param int $contact_id
|
||||
* @param int $petition_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function confirmSignature($activity_id, $contact_id, $petition_id) {
|
||||
// change activity status to completed (status_id = 2)
|
||||
// I wonder why do we need contact_id when we have activity_id anyway? [chastell]
|
||||
$sql = 'UPDATE civicrm_activity SET status_id = 2 WHERE id = %1';
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
$params = array(
|
||||
1 => array($activity_id, 'Integer'),
|
||||
2 => array($contact_id, 'Integer'),
|
||||
3 => array($sourceID, 'Integer'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
|
||||
$sql = 'UPDATE civicrm_activity_contact SET contact_id = %2 WHERE activity_id = %1 AND record_type_id = %3';
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
// remove 'Unconfirmed' tag for this contact
|
||||
$tag_name = Civi::settings()->get('tag_unconfirmed');
|
||||
|
||||
$sql = "
|
||||
DELETE FROM civicrm_entity_tag
|
||||
WHERE entity_table = 'civicrm_contact'
|
||||
AND entity_id = %1
|
||||
AND tag_id = ( SELECT id FROM civicrm_tag WHERE name = %2 )";
|
||||
$params = array(
|
||||
1 => array($contact_id, 'Integer'),
|
||||
2 => array($tag_name, 'String'),
|
||||
);
|
||||
CRM_Core_DAO::executeQuery($sql, $params);
|
||||
// validate arguments to setcookie are numeric to prevent header manipulation
|
||||
if (isset($petition_id) && is_numeric($petition_id)
|
||||
&& isset($activity_id) && is_numeric($activity_id)) {
|
||||
// set permanent cookie to indicate this users email address now confirmed
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$url_parts = parse_url($config->userFrameworkBaseURL);
|
||||
setcookie("confirmed_{$petition_id}",
|
||||
$activity_id,
|
||||
time() + $this->cookieExpire,
|
||||
$url_parts['path'],
|
||||
$url_parts['host'],
|
||||
CRM_Utils_System::isSSL()
|
||||
);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal(ts('Petition Id and/or Activity Id is not of the type Positive.'));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Petition Signature Total.
|
||||
*
|
||||
* @param int $surveyId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPetitionSignatureTotalbyCountry($surveyId) {
|
||||
$countries = array();
|
||||
$sql = "
|
||||
SELECT count(civicrm_address.country_id) as total,
|
||||
IFNULL(country_id,'') as country_id,IFNULL(iso_code,'') as country_iso, IFNULL(civicrm_country.name,'') as country
|
||||
FROM ( civicrm_activity a, civicrm_survey, civicrm_contact )
|
||||
LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id AND civicrm_address.is_primary = 1
|
||||
LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
|
||||
LEFT JOIN civicrm_activity_contact ac ON ( ac.activity_id = a.id AND ac.record_type_id = %2 )
|
||||
WHERE
|
||||
ac.contact_id = civicrm_contact.id AND
|
||||
a.activity_type_id = civicrm_survey.activity_type_id AND
|
||||
civicrm_survey.id = %1 AND
|
||||
a.source_record_id = %1 ";
|
||||
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
$params = array(
|
||||
1 => array($surveyId, 'Integer'),
|
||||
2 => array($sourceID, 'Integer'),
|
||||
);
|
||||
$sql .= " GROUP BY civicrm_address.country_id";
|
||||
$fields = array('total', 'country_id', 'country_iso', 'country');
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
while ($dao->fetch()) {
|
||||
$row = array();
|
||||
foreach ($fields as $field) {
|
||||
$row[$field] = $dao->$field;
|
||||
}
|
||||
$countries[] = $row;
|
||||
}
|
||||
return $countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Petition Signature Total.
|
||||
*
|
||||
* @param int $surveyId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPetitionSignatureTotal($surveyId) {
|
||||
$surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo((int) $surveyId);
|
||||
//$activityTypeID = $surveyInfo['activity_type_id'];
|
||||
$sql = "
|
||||
SELECT
|
||||
status_id,count(id) as total
|
||||
FROM civicrm_activity
|
||||
WHERE
|
||||
source_record_id = " . (int) $surveyId . " AND activity_type_id = " . (int) $surveyInfo['activity_type_id'] . " GROUP BY status_id";
|
||||
|
||||
$statusTotal = array();
|
||||
$total = 0;
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($dao->fetch()) {
|
||||
$total += $dao->total;
|
||||
$statusTotal['status'][$dao->status_id] = $dao->total;
|
||||
}
|
||||
$statusTotal['count'] = $total;
|
||||
return $statusTotal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $surveyId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSurveyInfo($surveyId = NULL) {
|
||||
$surveyInfo = array();
|
||||
|
||||
$sql = "
|
||||
SELECT activity_type_id,
|
||||
campaign_id,
|
||||
s.title,
|
||||
ov.label AS activity_type
|
||||
FROM civicrm_survey s, civicrm_option_value ov, civicrm_option_group og
|
||||
WHERE s.id = " . (int) $surveyId . "
|
||||
AND s.activity_type_id = ov.value
|
||||
AND ov.option_group_id = og.id
|
||||
AND og.name = 'activity_type'";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($dao->fetch()) {
|
||||
//$survey['campaign_id'] = $dao->campaign_id;
|
||||
//$survey['campaign_name'] = $dao->campaign_name;
|
||||
$surveyInfo['activity_type'] = $dao->activity_type;
|
||||
$surveyInfo['activity_type_id'] = $dao->activity_type_id;
|
||||
$surveyInfo['title'] = $dao->title;
|
||||
}
|
||||
|
||||
return $surveyInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Petition Signature Details.
|
||||
*
|
||||
* @param int $surveyId
|
||||
* @param int $status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPetitionSignature($surveyId, $status_id = NULL) {
|
||||
|
||||
// sql injection protection
|
||||
$surveyId = (int) $surveyId;
|
||||
$signature = array();
|
||||
|
||||
$sql = "
|
||||
SELECT a.id,
|
||||
a.source_record_id as survey_id,
|
||||
a.activity_date_time,
|
||||
a.status_id,
|
||||
civicrm_contact.id as contact_id,
|
||||
civicrm_contact.contact_type,civicrm_contact.contact_sub_type,image_URL,
|
||||
first_name,last_name,sort_name,
|
||||
employer_id,organization_name,
|
||||
household_name,
|
||||
IFNULL(gender_id,'') AS gender_id,
|
||||
IFNULL(state_province_id,'') AS state_province_id,
|
||||
IFNULL(country_id,'') as country_id,IFNULL(iso_code,'') as country_iso, IFNULL(civicrm_country.name,'') as country
|
||||
FROM (civicrm_activity a, civicrm_survey, civicrm_contact )
|
||||
LEFT JOIN civicrm_activity_contact ac ON ( ac.activity_id = a.id AND ac.record_type_id = %3 )
|
||||
LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id AND civicrm_address.is_primary = 1
|
||||
LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
|
||||
WHERE
|
||||
ac.contact_id = civicrm_contact.id AND
|
||||
a.activity_type_id = civicrm_survey.activity_type_id AND
|
||||
civicrm_survey.id = %1 AND
|
||||
a.source_record_id = %1 ";
|
||||
|
||||
$params = array(1 => array($surveyId, 'Integer'));
|
||||
|
||||
if ($status_id) {
|
||||
$sql .= " AND status_id = %2";
|
||||
$params[2] = array($status_id, 'Integer');
|
||||
}
|
||||
$sql .= " ORDER BY a.activity_date_time";
|
||||
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
$params[3] = array($sourceID, 'Integer');
|
||||
|
||||
$fields = array(
|
||||
'id',
|
||||
'survey_id',
|
||||
'contact_id',
|
||||
'activity_date_time',
|
||||
'activity_type_id',
|
||||
'status_id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'sort_name',
|
||||
'gender_id',
|
||||
'country_id',
|
||||
'state_province_id',
|
||||
'country_iso',
|
||||
'country',
|
||||
);
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
while ($dao->fetch()) {
|
||||
$row = array();
|
||||
foreach ($fields as $field) {
|
||||
$row[$field] = $dao->$field;
|
||||
}
|
||||
$signature[] = $row;
|
||||
}
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns all entities assigned to a specific tag.
|
||||
*
|
||||
* @param object $tag
|
||||
* An object of a tag.
|
||||
*
|
||||
* @return array
|
||||
* array of contact ids
|
||||
*/
|
||||
public function getEntitiesByTag($tag) {
|
||||
$contactIds = array();
|
||||
$entityTagDAO = new CRM_Core_DAO_EntityTag();
|
||||
$entityTagDAO->tag_id = $tag['id'];
|
||||
$entityTagDAO->find();
|
||||
|
||||
while ($entityTagDAO->fetch()) {
|
||||
$contactIds[] = $entityTagDAO->entity_id;
|
||||
}
|
||||
return $contactIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if contact has signed this petition.
|
||||
*
|
||||
* @param int $surveyId
|
||||
* @param int $contactId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function checkSignature($surveyId, $contactId) {
|
||||
|
||||
$surveyInfo = CRM_Campaign_BAO_Petition::getSurveyInfo($surveyId);
|
||||
$signature = array();
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
|
||||
$sql = "
|
||||
SELECT a.id AS id,
|
||||
a.source_record_id AS source_record_id,
|
||||
ac.contact_id AS source_contact_id,
|
||||
a.activity_date_time AS activity_date_time,
|
||||
a.activity_type_id AS activity_type_id,
|
||||
a.status_id AS status_id,
|
||||
%1 AS survey_title
|
||||
FROM civicrm_activity a
|
||||
INNER JOIN civicrm_activity_contact ac ON (ac.activity_id = a.id AND ac.record_type_id = %5)
|
||||
WHERE a.source_record_id = %2
|
||||
AND a.activity_type_id = %3
|
||||
AND ac.contact_id = %4
|
||||
";
|
||||
$params = array(
|
||||
1 => array($surveyInfo['title'], 'String'),
|
||||
2 => array($surveyId, 'Integer'),
|
||||
3 => array($surveyInfo['activity_type_id'], 'Integer'),
|
||||
4 => array($contactId, 'Integer'),
|
||||
5 => array($sourceID, 'Integer'),
|
||||
);
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($sql, $params);
|
||||
while ($dao->fetch()) {
|
||||
$signature[$dao->id]['id'] = $dao->id;
|
||||
$signature[$dao->id]['source_record_id'] = $dao->source_record_id;
|
||||
$signature[$dao->id]['source_contact_id'] = CRM_Contact_BAO_Contact::displayName($dao->source_contact_id);
|
||||
$signature[$dao->id]['activity_date_time'] = $dao->activity_date_time;
|
||||
$signature[$dao->id]['activity_type_id'] = $dao->activity_type_id;
|
||||
$signature[$dao->id]['status_id'] = $dao->status_id;
|
||||
$signature[$dao->id]['survey_title'] = $dao->survey_title;
|
||||
$signature[$dao->id]['contactId'] = $dao->source_contact_id;
|
||||
}
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an associative array and sends a thank you or email verification email.
|
||||
*
|
||||
* @param array $params
|
||||
* (reference ) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param int $sendEmailMode
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function sendEmail($params, $sendEmailMode) {
|
||||
|
||||
/* sendEmailMode
|
||||
* CRM_Campaign_Form_Petition_Signature::EMAIL_THANK
|
||||
* connected user via login/pwd - thank you
|
||||
* or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
|
||||
* or login using fb connect - thank you + click to add msg to fb wall
|
||||
*
|
||||
* CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM
|
||||
* send a confirmation request email
|
||||
*/
|
||||
|
||||
// check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it
|
||||
$petitionGroupName = Civi::settings()->get('petition_contacts');
|
||||
|
||||
$dao = new CRM_Contact_DAO_Group();
|
||||
$dao->title = $petitionGroupName;
|
||||
if (!$dao->find(TRUE)) {
|
||||
$dao->is_active = 1;
|
||||
$dao->visibility = 'User and User Admin Only';
|
||||
$dao->save();
|
||||
}
|
||||
$group_id = $dao->id;
|
||||
|
||||
// get petition info
|
||||
$petitionParams['id'] = $params['sid'];
|
||||
$petitionInfo = array();
|
||||
CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo);
|
||||
if (empty($petitionInfo)) {
|
||||
CRM_Core_Error::fatal('Petition doesn\'t exist.');
|
||||
}
|
||||
|
||||
//get the default domain email address.
|
||||
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
|
||||
|
||||
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
|
||||
|
||||
$toName = CRM_Contact_BAO_Contact::displayName($params['contactId']);
|
||||
|
||||
$replyTo = "do-not-reply@$emailDomain";
|
||||
|
||||
// set additional general message template params (custom tokens to use in email msg templates)
|
||||
// tokens then available in msg template as {$petition.title}, etc
|
||||
$petitionTokens['title'] = $petitionInfo['title'];
|
||||
$petitionTokens['petitionId'] = $params['sid'];
|
||||
$tplParams['petition'] = $petitionTokens;
|
||||
|
||||
switch ($sendEmailMode) {
|
||||
case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK:
|
||||
|
||||
// add this contact to the CIVICRM_PETITION_CONTACTS group
|
||||
// Cannot pass parameter 1 by reference
|
||||
$p = array($params['contactId']);
|
||||
CRM_Contact_BAO_GroupContact::addContactsToGroup($p, $group_id, 'API');
|
||||
|
||||
if ($params['email-Primary']) {
|
||||
CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_petition',
|
||||
'valueName' => 'petition_sign',
|
||||
'contactId' => $params['contactId'],
|
||||
'tplParams' => $tplParams,
|
||||
'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
|
||||
'toName' => $toName,
|
||||
'toEmail' => $params['email-Primary'],
|
||||
'replyTo' => $replyTo,
|
||||
'petitionId' => $params['sid'],
|
||||
'petitionTitle' => $petitionInfo['title'],
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM:
|
||||
// create mailing event subscription record for this contact
|
||||
// this will allow using a hash key to confirm email address by sending a url link
|
||||
$se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id,
|
||||
$params['email-Primary'],
|
||||
$params['contactId'],
|
||||
'profile'
|
||||
);
|
||||
|
||||
// require_once 'CRM/Core/BAO/Domain.php';
|
||||
// $domain = CRM_Core_BAO_Domain::getDomain();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
|
||||
|
||||
$replyTo = implode($config->verpSeparator,
|
||||
array(
|
||||
$localpart . 'c',
|
||||
$se->contact_id,
|
||||
$se->id,
|
||||
$se->hash,
|
||||
)
|
||||
) . "@$emailDomain";
|
||||
|
||||
$confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm',
|
||||
"reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&pid={$params['sid']}",
|
||||
TRUE
|
||||
);
|
||||
$confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm',
|
||||
"reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&pid={$params['sid']}",
|
||||
TRUE,
|
||||
NULL,
|
||||
FALSE
|
||||
);
|
||||
|
||||
// set email specific message template params and assign to tplParams
|
||||
$petitionTokens['confirmUrl'] = $confirmUrl;
|
||||
$petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText;
|
||||
$tplParams['petition'] = $petitionTokens;
|
||||
|
||||
if ($params['email-Primary']) {
|
||||
CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_petition',
|
||||
'valueName' => 'petition_confirmation_needed',
|
||||
'contactId' => $params['contactId'],
|
||||
'tplParams' => $tplParams,
|
||||
'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>",
|
||||
'toName' => $toName,
|
||||
'toEmail' => $params['email-Primary'],
|
||||
'replyTo' => $replyTo,
|
||||
'petitionId' => $params['sid'],
|
||||
'petitionTitle' => $petitionInfo['title'],
|
||||
'confirmUrl' => $confirmUrl,
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
565
sites/all/modules/civicrm/CRM/Campaign/BAO/Query.php
Normal file
565
sites/all/modules/civicrm/CRM/Campaign/BAO/Query.php
Normal file
|
@ -0,0 +1,565 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_BAO_Query {
|
||||
//since normal activity clause clause get collides.
|
||||
const
|
||||
CIVICRM_ACTIVITY = 'civicrm_survey_activity',
|
||||
CIVICRM_ACTIVITY_TARGET = 'civicrm_survey_activity_target',
|
||||
CIVICRM_ACTIVITY_ASSIGNMENT = 'civicrm_survey_activity_assignment';
|
||||
|
||||
/**
|
||||
* Static field for all the campaign fields.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_campaignFields = NULL;
|
||||
|
||||
static $_applySurveyClause = FALSE;
|
||||
|
||||
/**
|
||||
* Function get the fields for campaign.
|
||||
*
|
||||
* @return array
|
||||
* self::$_campaignFields an associative array of campaign fields
|
||||
*/
|
||||
public static function &getFields() {
|
||||
if (!isset(self::$_campaignFields)) {
|
||||
self::$_campaignFields = array();
|
||||
}
|
||||
|
||||
return self::$_campaignFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* If survey, campaign are involved, add the specific fields.
|
||||
*
|
||||
* @param CRM_Contact_BAO_Contact $query
|
||||
*/
|
||||
public static function select(&$query) {
|
||||
self::$_applySurveyClause = FALSE;
|
||||
if (is_array($query->_params)) {
|
||||
foreach ($query->_params as $values) {
|
||||
if (!is_array($values) || count($values) != 5) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($name, $op, $value, $grouping, $wildcard) = $values;
|
||||
if ($name == 'campaign_survey_id') {
|
||||
self::$_applySurveyClause = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// CRM-13810 Translate campaign_id to label for search builder
|
||||
// CRM-14238 Only translate when we are in contact mode
|
||||
// Other modes need the untranslated data for export and other functions
|
||||
if (is_array($query->_select) && $query->_mode == CRM_Contact_BAO_Query::MODE_CONTACTS) {
|
||||
foreach ($query->_select as $field => $queryString) {
|
||||
if (substr($field, -11) == 'campaign_id') {
|
||||
$query->_pseudoConstantsSelect[$field] = array(
|
||||
'pseudoField' => 'campaign_id',
|
||||
'idCol' => $field,
|
||||
'bao' => 'CRM_Activity_BAO_Activity',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//get survey clause in force,
|
||||
//only when we have survey id.
|
||||
if (!self::$_applySurveyClause) {
|
||||
return;
|
||||
}
|
||||
|
||||
//all below tables are require to fetch result.
|
||||
|
||||
//1. get survey activity target table in.
|
||||
$query->_select['survey_activity_target_contact_id'] = 'civicrm_activity_target.contact_id as survey_activity_target_contact_id';
|
||||
$query->_select['survey_activity_target_id'] = 'civicrm_activity_target.id as survey_activity_target_id';
|
||||
$query->_element['survey_activity_target_id'] = 1;
|
||||
$query->_element['survey_activity_target_contact_id'] = 1;
|
||||
$query->_tables[self::CIVICRM_ACTIVITY_TARGET] = 1;
|
||||
$query->_whereTables[self::CIVICRM_ACTIVITY_TARGET] = 1;
|
||||
|
||||
//2. get survey activity table in.
|
||||
$query->_select['survey_activity_id'] = 'civicrm_activity.id as survey_activity_id';
|
||||
$query->_element['survey_activity_id'] = 1;
|
||||
$query->_tables[self::CIVICRM_ACTIVITY] = 1;
|
||||
$query->_whereTables[self::CIVICRM_ACTIVITY] = 1;
|
||||
|
||||
//3. get the assignee table in.
|
||||
$query->_select['survey_interviewer_id'] = 'civicrm_activity_assignment.id as survey_interviewer_id';
|
||||
$query->_element['survey_interviewer_id'] = 1;
|
||||
$query->_tables[self::CIVICRM_ACTIVITY_ASSIGNMENT] = 1;
|
||||
$query->_whereTables[self::CIVICRM_ACTIVITY_ASSIGNMENT] = 1;
|
||||
|
||||
//4. get survey table.
|
||||
$query->_select['campaign_survey_id'] = 'civicrm_survey.id as campaign_survey_id';
|
||||
$query->_element['campaign_survey_id'] = 1;
|
||||
$query->_tables['civicrm_survey'] = 1;
|
||||
$query->_whereTables['civicrm_survey'] = 1;
|
||||
|
||||
//5. get campaign table.
|
||||
$query->_select['campaign_id'] = 'civicrm_campaign.id as campaign_id';
|
||||
$query->_element['campaign_id'] = 1;
|
||||
$query->_tables['civicrm_campaign'] = 1;
|
||||
$query->_whereTables['civicrm_campaign'] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
*/
|
||||
public static function where(&$query) {
|
||||
//get survey clause in force,
|
||||
//only when we have survey id.
|
||||
if (!self::$_applySurveyClause) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grouping = NULL;
|
||||
foreach (array_keys($query->_params) as $id) {
|
||||
if ($query->_mode == CRM_Contact_BAO_Query::MODE_CONTACTS) {
|
||||
$query->_useDistinct = TRUE;
|
||||
}
|
||||
|
||||
self::whereClauseSingle($query->_params[$id], $query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $values
|
||||
* @param $query
|
||||
*/
|
||||
public static function whereClauseSingle(&$values, &$query) {
|
||||
//get survey clause in force,
|
||||
//only when we have survey id.
|
||||
if (!self::$_applySurveyClause) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($name, $op, $value, $grouping, $wildcard) = $values;
|
||||
|
||||
switch ($name) {
|
||||
case 'campaign_survey_id':
|
||||
$query->_qill[$grouping][] = ts('Survey - %1', array(1 => CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title')));
|
||||
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_activity.source_record_id',
|
||||
$op, $value, 'Integer'
|
||||
);
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_survey.id',
|
||||
$op, $value, 'Integer'
|
||||
);
|
||||
return;
|
||||
|
||||
case 'survey_status_id':
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus();
|
||||
|
||||
$query->_qill[$grouping][] = ts('Survey Status - %1', array(1 => $activityStatus[$value]));
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_activity.status_id',
|
||||
$op, $value, 'Integer'
|
||||
);
|
||||
return;
|
||||
|
||||
case 'campaign_search_voter_for':
|
||||
if (in_array($value, array('release', 'interview'))) {
|
||||
$query->_where[$grouping][] = '(civicrm_activity.is_deleted = 0 OR civicrm_activity.is_deleted IS NULL)';
|
||||
}
|
||||
return;
|
||||
|
||||
case 'survey_interviewer_id':
|
||||
$surveyInterviewerName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name');
|
||||
$query->_qill[$grouping][] = ts('Survey Interviewer - %1', array(1 => $surveyInterviewerName));
|
||||
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_activity_assignment.contact_id',
|
||||
$op, $value, 'Integer'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $mode
|
||||
* @param $side
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function from($name, $mode, $side) {
|
||||
$from = NULL;
|
||||
//get survey clause in force,
|
||||
//only when we have survey id.
|
||||
if (!self::$_applySurveyClause) {
|
||||
return $from;
|
||||
}
|
||||
|
||||
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
|
||||
$sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
|
||||
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
|
||||
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
|
||||
|
||||
switch ($name) {
|
||||
case self::CIVICRM_ACTIVITY_TARGET:
|
||||
$from = " INNER JOIN civicrm_activity_contact civicrm_activity_target
|
||||
ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = $targetID) ";
|
||||
break;
|
||||
|
||||
case self::CIVICRM_ACTIVITY:
|
||||
$surveyActivityTypes = CRM_Campaign_PseudoConstant::activityType();
|
||||
$surveyKeys = "(" . implode(',', array_keys($surveyActivityTypes)) . ")";
|
||||
$from = " INNER JOIN civicrm_activity ON ( civicrm_activity.id = civicrm_activity_target.activity_id
|
||||
AND civicrm_activity.activity_type_id IN $surveyKeys ) ";
|
||||
break;
|
||||
|
||||
case self::CIVICRM_ACTIVITY_ASSIGNMENT:
|
||||
$from = "
|
||||
INNER JOIN civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
|
||||
civicrm_activity_assignment.record_type_id = $assigneeID ) ";
|
||||
break;
|
||||
|
||||
case 'civicrm_survey':
|
||||
$from = " INNER JOIN civicrm_survey ON ( civicrm_survey.id = civicrm_activity.source_record_id ) ";
|
||||
break;
|
||||
|
||||
case 'civicrm_campaign':
|
||||
$from = " $side JOIN civicrm_campaign ON ( civicrm_campaign.id = civicrm_survey.campaign_id ) ";
|
||||
break;
|
||||
}
|
||||
|
||||
return $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mode
|
||||
* @param bool $includeCustomFields
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function defaultReturnProperties(
|
||||
$mode,
|
||||
$includeCustomFields = TRUE
|
||||
) {
|
||||
$properties = NULL;
|
||||
if ($mode & CRM_Contact_BAO_Query::MODE_CAMPAIGN) {
|
||||
$properties = array(
|
||||
'contact_id' => 1,
|
||||
'contact_type' => 1,
|
||||
'contact_sub_type' => 1,
|
||||
'sort_name' => 1,
|
||||
'display_name' => 1,
|
||||
'street_unit' => 1,
|
||||
'street_name' => 1,
|
||||
'street_number' => 1,
|
||||
'street_address' => 1,
|
||||
'city' => 1,
|
||||
'postal_code' => 1,
|
||||
'state_province' => 1,
|
||||
'country' => 1,
|
||||
'email' => 1,
|
||||
'phone' => 1,
|
||||
'survey_activity_target_id' => 1,
|
||||
'survey_activity_id' => 1,
|
||||
'survey_status_id' => 1,
|
||||
'campaign_survey_id' => 1,
|
||||
'campaign_id' => 1,
|
||||
'survey_interviewer_id' => 1,
|
||||
'survey_activity_target_contact_id' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tables
|
||||
*/
|
||||
public static function tableNames(&$tables) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
* @param int $id
|
||||
*/
|
||||
public static function searchAction(&$row, $id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tables
|
||||
*/
|
||||
public static function info(&$tables) {
|
||||
//get survey clause in force,
|
||||
//only when we have survey id.
|
||||
if (!self::$_applySurveyClause) {
|
||||
return;
|
||||
}
|
||||
|
||||
$weight = end($tables);
|
||||
$tables[self::CIVICRM_ACTIVITY_TARGET] = ++$weight;
|
||||
$tables[self::CIVICRM_ACTIVITY] = ++$weight;
|
||||
$tables[self::CIVICRM_ACTIVITY_ASSIGNMENT] = ++$weight;
|
||||
$tables['civicrm_survey'] = ++$weight;
|
||||
$tables['civicrm_campaign'] = ++$weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the elements shared between,
|
||||
* normal voter search and voter listing (GOTV form)
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function buildSearchForm(&$form) {
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
|
||||
$className = CRM_Utils_System::getClassName($form);
|
||||
|
||||
$form->add('text', 'sort_name', ts('Contact Name'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
|
||||
);
|
||||
$form->add('text', 'street_name', ts('Street Name'), $attributes['street_name']);
|
||||
$form->add('text', 'street_number', ts('Street Number'), $attributes['street_number']);
|
||||
$form->add('text', 'street_unit', ts('Street Unit'), $attributes['street_unit']);
|
||||
$form->add('text', 'street_address', ts('Street Address'), $attributes['street_address']);
|
||||
$form->add('text', 'city', ts('City'), $attributes['city']);
|
||||
$form->add('text', 'postal_code', ts('Postal Code'), $attributes['postal_code']);
|
||||
|
||||
//@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
|
||||
// this is loaded onto then replace with something like '__' & test
|
||||
$separator = CRM_Core_DAO::VALUE_SEPARATOR;
|
||||
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator);
|
||||
$form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
|
||||
array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
$form->add('select', 'group', ts('Groups'), $groups, FALSE,
|
||||
array('multiple' => 'multiple', 'class' => 'crm-select2')
|
||||
);
|
||||
|
||||
$showInterviewer = FALSE;
|
||||
if (CRM_Core_Permission::check('administer CiviCampaign')) {
|
||||
$showInterviewer = TRUE;
|
||||
}
|
||||
$form->assign('showInterviewer', $showInterviewer);
|
||||
|
||||
if ($showInterviewer ||
|
||||
$className == 'CRM_Campaign_Form_Gotv'
|
||||
) {
|
||||
|
||||
$form->addEntityRef('survey_interviewer_id', ts('Interviewer'), array('class' => 'big'));
|
||||
|
||||
$userId = NULL;
|
||||
if (isset($form->_interviewerId) && $form->_interviewerId) {
|
||||
$userId = $form->_interviewerId;
|
||||
}
|
||||
if (!$userId) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$userId = $session->get('userID');
|
||||
}
|
||||
if ($userId) {
|
||||
$defaults = array();
|
||||
$defaults['survey_interviewer_id'] = $userId;
|
||||
$form->setDefaults($defaults);
|
||||
}
|
||||
}
|
||||
|
||||
//build ward and precinct custom fields.
|
||||
$query = '
|
||||
SELECT fld.id, fld.label
|
||||
FROM civicrm_custom_field fld
|
||||
INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id
|
||||
WHERE grp.name = %1';
|
||||
$dao = CRM_Core_DAO::executeQuery($query, array(1 => array('Voter_Info', 'String')));
|
||||
$customSearchFields = array();
|
||||
while ($dao->fetch()) {
|
||||
foreach (array(
|
||||
'ward',
|
||||
'precinct',
|
||||
) as $name) {
|
||||
if (stripos($name, $dao->label) !== FALSE) {
|
||||
$fieldId = $dao->id;
|
||||
$fieldName = 'custom_' . $dao->id;
|
||||
$customSearchFields[$name] = $fieldName;
|
||||
CRM_Core_BAO_CustomField::addQuickFormElement($form, $fieldName, $fieldId, FALSE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$form->assign('customSearchFields', $customSearchFields);
|
||||
|
||||
$surveys = CRM_Campaign_BAO_Survey::getSurveys();
|
||||
|
||||
if (empty($surveys) &&
|
||||
($className == 'CRM_Campaign_Form_Search')
|
||||
) {
|
||||
CRM_Core_Error::statusBounce(ts('Could not find survey for %1 respondents.',
|
||||
array(1 => $form->get('op'))
|
||||
),
|
||||
CRM_Utils_System::url('civicrm/survey/add',
|
||||
'reset=1&action=add'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//CRM-7406 --
|
||||
//If survey had associated campaign and
|
||||
//campaign has some contact groups, don't
|
||||
//allow to search the contacts those are not
|
||||
//in given campaign groups ( ie not in constituents )
|
||||
$props = array('class' => 'crm-select2');
|
||||
if ($form->get('searchVoterFor') == 'reserve') {
|
||||
$props['onChange'] = "buildCampaignGroups( );return false;";
|
||||
}
|
||||
$form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, TRUE, $props);
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve all valid voter ids,
|
||||
* and build respective clause to restrict search.
|
||||
*
|
||||
* @param array $criteria
|
||||
* An array.
|
||||
* @return $voterClause as a string
|
||||
*/
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function voterClause($params) {
|
||||
$voterClause = array();
|
||||
$fromClause = $whereClause = NULL;
|
||||
if (!is_array($params) || empty($params)) {
|
||||
return $voterClause;
|
||||
}
|
||||
$surveyId = CRM_Utils_Array::value('campaign_survey_id', $params);
|
||||
$searchVoterFor = CRM_Utils_Array::value('campaign_search_voter_for', $params);
|
||||
|
||||
//get the survey activities.
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$status = array('Scheduled');
|
||||
if ($searchVoterFor == 'reserve') {
|
||||
$status[] = 'Completed';
|
||||
}
|
||||
|
||||
$completedStatusId = NULL;
|
||||
foreach ($status as $name) {
|
||||
if ($statusId = array_search($name, $activityStatus)) {
|
||||
$statusIds[] = $statusId;
|
||||
if ($name == 'Completed') {
|
||||
$completedStatusId = $statusId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$voterActValues = CRM_Campaign_BAO_Survey::getSurveyVoterInfo($surveyId, NULL, $statusIds);
|
||||
|
||||
if (!empty($voterActValues)) {
|
||||
$operator = 'IN';
|
||||
$voterIds = array_keys($voterActValues);
|
||||
if ($searchVoterFor == 'reserve') {
|
||||
$operator = 'NOT IN';
|
||||
//filter out recontact survey contacts.
|
||||
$recontactInterval = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey',
|
||||
$surveyId, 'recontact_interval'
|
||||
);
|
||||
$recontactInterval = unserialize($recontactInterval);
|
||||
if ($surveyId &&
|
||||
is_array($recontactInterval) &&
|
||||
!empty($recontactInterval)
|
||||
) {
|
||||
$voterIds = array();
|
||||
foreach ($voterActValues as $values) {
|
||||
$numOfDays = CRM_Utils_Array::value($values['result'], $recontactInterval);
|
||||
if ($numOfDays &&
|
||||
$values['status_id'] == $completedStatusId
|
||||
) {
|
||||
$recontactIntSeconds = $numOfDays * 24 * 3600;
|
||||
$actDateTimeSeconds = CRM_Utils_Date::unixTime($values['activity_date_time']);
|
||||
$totalSeconds = $recontactIntSeconds + $actDateTimeSeconds;
|
||||
//don't consider completed survey activity
|
||||
//unless it fulfill recontact interval criteria.
|
||||
if ($totalSeconds <= time()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$voterIds[$values['voter_id']] = $values['voter_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//lets dump these ids in tmp table and
|
||||
//use appropriate join depend on operator.
|
||||
if (!empty($voterIds)) {
|
||||
$voterIdCount = count($voterIds);
|
||||
|
||||
//create temporary table to store voter ids.
|
||||
$tempTableName = CRM_Core_DAO::createTempTableName('civicrm_survey_respondent');
|
||||
CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS {$tempTableName}");
|
||||
|
||||
$query = "
|
||||
CREATE TEMPORARY TABLE {$tempTableName} (
|
||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||
survey_contact_id int unsigned NOT NULL,
|
||||
PRIMARY KEY ( id )
|
||||
);
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
|
||||
$batch = 100;
|
||||
$insertedCount = 0;
|
||||
do {
|
||||
$processIds = $voterIds;
|
||||
$insertIds = array_splice($processIds, $insertedCount, $batch);
|
||||
if (!empty($insertIds)) {
|
||||
$insertSQL = "INSERT IGNORE INTO {$tempTableName}( survey_contact_id )
|
||||
VALUES (" . implode('),(', $insertIds) . ');';
|
||||
CRM_Core_DAO::executeQuery($insertSQL);
|
||||
}
|
||||
$insertedCount += $batch;
|
||||
} while ($insertedCount < $voterIdCount);
|
||||
|
||||
if ($operator == 'IN') {
|
||||
$fromClause = " INNER JOIN {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact_a.id )";
|
||||
}
|
||||
else {
|
||||
$fromClause = " LEFT JOIN {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact_a.id )";
|
||||
$whereClause = "( {$tempTableName}.survey_contact_id IS NULL )";
|
||||
}
|
||||
}
|
||||
}
|
||||
$voterClause = array(
|
||||
'fromClause' => $fromClause,
|
||||
'whereClause' => $whereClause,
|
||||
);
|
||||
|
||||
return $voterClause;
|
||||
}
|
||||
|
||||
}
|
1155
sites/all/modules/civicrm/CRM/Campaign/BAO/Survey.php
Normal file
1155
sites/all/modules/civicrm/CRM/Campaign/BAO/Survey.php
Normal file
File diff suppressed because it is too large
Load diff
68
sites/all/modules/civicrm/CRM/Campaign/Controller/Search.php
Normal file
68
sites/all/modules/civicrm/CRM/Campaign/Controller/Search.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used by the Search functionality.
|
||||
*
|
||||
* - the search controller is used for building/processing multiform
|
||||
* searches.
|
||||
*
|
||||
* Typically the first form will display the search criteria and its results
|
||||
*
|
||||
* The second form is used to process search results with the associated actions
|
||||
*
|
||||
*/
|
||||
class CRM_Campaign_Controller_Search extends CRM_Core_Controller {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param null $title
|
||||
* @param bool|int $action
|
||||
* @param bool $modal
|
||||
*/
|
||||
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
|
||||
|
||||
parent::__construct($title, $modal);
|
||||
|
||||
$this->_stateMachine = new CRM_Campaign_StateMachine_Search($this, $action);
|
||||
|
||||
// create and instantiate the pages
|
||||
$this->addPages($this->_stateMachine, $action);
|
||||
|
||||
// add all the actions
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->addActions();
|
||||
}
|
||||
|
||||
}
|
557
sites/all/modules/civicrm/CRM/Campaign/DAO/Campaign.php
Normal file
557
sites/all/modules/civicrm/CRM/Campaign/DAO/Campaign.php
Normal file
|
@ -0,0 +1,557 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Campaign/Campaign.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:02b05b18f25c40f15b6992e2f853f5da)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Campaign_DAO_Campaign constructor.
|
||||
*/
|
||||
class CRM_Campaign_DAO_Campaign extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_campaign';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Unique Campaign ID.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Name of the Campaign.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* Title of the Campaign.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* Full description of Campaign.
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $description;
|
||||
/**
|
||||
* Date and time that Campaign starts.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $start_date;
|
||||
/**
|
||||
* Date and time that Campaign ends.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $end_date;
|
||||
/**
|
||||
* Campaign Type ID.Implicit FK to civicrm_option_value where option_group = campaign_type
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $campaign_type_id;
|
||||
/**
|
||||
* Campaign status ID.Implicit FK to civicrm_option_value where option_group = campaign_status
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
* Unique trusted external ID (generally from a legacy app/datasource). Particularly useful for deduping operations.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $external_identifier;
|
||||
/**
|
||||
* Optional parent id for this Campaign.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $parent_id;
|
||||
/**
|
||||
* Is this Campaign enabled or disabled/cancelled?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* FK to civicrm_contact, who created this Campaign.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $created_id;
|
||||
/**
|
||||
* Date and time that Campaign was created.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $created_date;
|
||||
/**
|
||||
* FK to civicrm_contact, who recently edited this Campaign.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $last_modified_id;
|
||||
/**
|
||||
* Date and time that Campaign was edited last time.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $last_modified_date;
|
||||
/**
|
||||
* General goals for Campaign.
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $goal_general;
|
||||
/**
|
||||
* The target revenue for this campaign.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $goal_revenue;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_campaign';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'parent_id', 'civicrm_campaign', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'created_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'last_modified_id', 'civicrm_contact', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign ID') ,
|
||||
'description' => 'Unique Campaign ID.',
|
||||
'required' => true,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'name' => array(
|
||||
'name' => 'name',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Campaign Name') ,
|
||||
'description' => 'Name of the Campaign.',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.name',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'title' => array(
|
||||
'name' => 'title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Campaign Title') ,
|
||||
'description' => 'Title of the Campaign.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.title',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'description' => array(
|
||||
'name' => 'description',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Campaign Description') ,
|
||||
'description' => 'Full description of Campaign.',
|
||||
'rows' => 8,
|
||||
'cols' => 60,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'start_date' => array(
|
||||
'name' => 'start_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Campaign Start Date') ,
|
||||
'description' => 'Date and time that Campaign starts.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.start_date',
|
||||
'headerPattern' => '/^start|(s(tart\s)?date)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
) ,
|
||||
) ,
|
||||
'end_date' => array(
|
||||
'name' => 'end_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Campaign End Date') ,
|
||||
'description' => 'Date and time that Campaign ends.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.end_date',
|
||||
'headerPattern' => '/^end|(e(nd\s)?date)$/i',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
) ,
|
||||
) ,
|
||||
'campaign_type_id' => array(
|
||||
'name' => 'campaign_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign Type') ,
|
||||
'description' => 'Campaign Type ID.Implicit FK to civicrm_option_value where option_group = campaign_type',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.campaign_type_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'campaign_type',
|
||||
'optionEditPath' => 'civicrm/admin/options/campaign_type',
|
||||
)
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign Status') ,
|
||||
'description' => 'Campaign status ID.Implicit FK to civicrm_option_value where option_group = campaign_status',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.status_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'campaign_status',
|
||||
'optionEditPath' => 'civicrm/admin/options/campaign_status',
|
||||
)
|
||||
) ,
|
||||
'external_identifier' => array(
|
||||
'name' => 'external_identifier',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Campaign External ID') ,
|
||||
'description' => 'Unique trusted external ID (generally from a legacy app/datasource). Particularly useful for deduping operations.',
|
||||
'maxlength' => 32,
|
||||
'size' => CRM_Utils_Type::MEDIUM,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.external_identifier',
|
||||
'headerPattern' => '/external\s?id/i',
|
||||
'dataPattern' => '/^\d{11,}$/',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'parent_id' => array(
|
||||
'name' => 'parent_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Parent Campaign') ,
|
||||
'description' => 'Optional parent id for this Campaign.',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_campaign.parent_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Campaign_DAO_Campaign',
|
||||
'html' => array(
|
||||
'type' => 'EntityRef',
|
||||
) ,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Campaign Active?') ,
|
||||
'description' => 'Is this Campaign enabled or disabled/cancelled?',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'created_id' => array(
|
||||
'name' => 'created_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign Created By') ,
|
||||
'description' => 'FK to civicrm_contact, who created this Campaign.',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'created_date' => array(
|
||||
'name' => 'created_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Campaign Created Date') ,
|
||||
'description' => 'Date and time that Campaign was created.',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select Date',
|
||||
) ,
|
||||
) ,
|
||||
'last_modified_id' => array(
|
||||
'name' => 'last_modified_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign Modified By') ,
|
||||
'description' => 'FK to civicrm_contact, who recently edited this Campaign.',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'last_modified_date' => array(
|
||||
'name' => 'last_modified_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Campaign Modified Date') ,
|
||||
'description' => 'Date and time that Campaign was edited last time.',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'goal_general' => array(
|
||||
'name' => 'goal_general',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Campaign Goals') ,
|
||||
'description' => 'General goals for Campaign.',
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'RichTextEditor',
|
||||
) ,
|
||||
) ,
|
||||
'goal_revenue' => array(
|
||||
'name' => 'goal_revenue',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Goal Revenue') ,
|
||||
'description' => 'The target revenue for this campaign.',
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_campaign',
|
||||
'entity' => 'Campaign',
|
||||
'bao' => 'CRM_Campaign_BAO_Campaign',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'campaign', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'campaign', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_campaign_type_id' => array(
|
||||
'name' => 'UI_campaign_type_id',
|
||||
'field' => array(
|
||||
0 => 'campaign_type_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_campaign::0::campaign_type_id',
|
||||
) ,
|
||||
'UI_campaign_status_id' => array(
|
||||
'name' => 'UI_campaign_status_id',
|
||||
'field' => array(
|
||||
0 => 'status_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_campaign::0::status_id',
|
||||
) ,
|
||||
'UI_external_identifier' => array(
|
||||
'name' => 'UI_external_identifier',
|
||||
'field' => array(
|
||||
0 => 'external_identifier',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'unique' => true,
|
||||
'sig' => 'civicrm_campaign::1::external_identifier',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
246
sites/all/modules/civicrm/CRM/Campaign/DAO/CampaignGroup.php
Normal file
246
sites/all/modules/civicrm/CRM/Campaign/DAO/CampaignGroup.php
Normal file
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Campaign/CampaignGroup.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:16989135f9745e57028278a41cc303ea)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Campaign_DAO_CampaignGroup constructor.
|
||||
*/
|
||||
class CRM_Campaign_DAO_CampaignGroup extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_campaign_group';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Campaign Group id.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Foreign key to the activity Campaign.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $campaign_id;
|
||||
/**
|
||||
* Type of Group.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $group_type;
|
||||
/**
|
||||
* Name of table where item being referenced is stored.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* Entity id of referenced table.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_campaign_group';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'campaign_id', 'civicrm_campaign', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign Group ID') ,
|
||||
'description' => 'Campaign Group id.',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_campaign_group',
|
||||
'entity' => 'CampaignGroup',
|
||||
'bao' => 'CRM_Campaign_DAO_CampaignGroup',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'campaign_id' => array(
|
||||
'name' => 'campaign_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Campaign') ,
|
||||
'description' => 'Foreign key to the activity Campaign.',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_campaign_group',
|
||||
'entity' => 'CampaignGroup',
|
||||
'bao' => 'CRM_Campaign_DAO_CampaignGroup',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Campaign_DAO_Campaign',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_campaign',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'title',
|
||||
)
|
||||
) ,
|
||||
'group_type' => array(
|
||||
'name' => 'group_type',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Campaign Group Type') ,
|
||||
'description' => 'Type of Group.',
|
||||
'maxlength' => 8,
|
||||
'size' => CRM_Utils_Type::EIGHT,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign_group',
|
||||
'entity' => 'CampaignGroup',
|
||||
'bao' => 'CRM_Campaign_DAO_CampaignGroup',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'callback' => 'CRM_Core_SelectValues::getCampaignGroupTypes',
|
||||
)
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Entity Table') ,
|
||||
'description' => 'Name of table where item being referenced is stored.',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign_group',
|
||||
'entity' => 'CampaignGroup',
|
||||
'bao' => 'CRM_Campaign_DAO_CampaignGroup',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity ID') ,
|
||||
'description' => 'Entity id of referenced table.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_campaign_group',
|
||||
'entity' => 'CampaignGroup',
|
||||
'bao' => 'CRM_Campaign_DAO_CampaignGroup',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'campaign_group', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'campaign_group', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
529
sites/all/modules/civicrm/CRM/Campaign/DAO/Survey.php
Normal file
529
sites/all/modules/civicrm/CRM/Campaign/DAO/Survey.php
Normal file
|
@ -0,0 +1,529 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/Campaign/Survey.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:55aa9d31d08f8b5353d42dde1278b7f2)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_Campaign_DAO_Survey constructor.
|
||||
*/
|
||||
class CRM_Campaign_DAO_Survey extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_survey';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = false;
|
||||
/**
|
||||
* Survey id.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* Title of the Survey.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* Foreign key to the Campaign.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $campaign_id;
|
||||
/**
|
||||
* Implicit FK to civicrm_option_value where option_group = activity_type
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $activity_type_id;
|
||||
/**
|
||||
* Recontact intervals for each status.
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $recontact_interval;
|
||||
/**
|
||||
* Script instructions for volunteers to use for the survey.
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $instructions;
|
||||
/**
|
||||
* Number of days for recurrence of release.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $release_frequency;
|
||||
/**
|
||||
* Maximum number of contacts to allow for survey.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $max_number_of_contacts;
|
||||
/**
|
||||
* Default number of contacts to allow for survey.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $default_number_of_contacts;
|
||||
/**
|
||||
* Is this survey enabled or disabled/cancelled?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Is this default survey?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_default;
|
||||
/**
|
||||
* FK to civicrm_contact, who created this Survey.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $created_id;
|
||||
/**
|
||||
* Date and time that Survey was created.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $created_date;
|
||||
/**
|
||||
* FK to civicrm_contact, who recently edited this Survey.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $last_modified_id;
|
||||
/**
|
||||
* Date and time that Survey was edited last time.
|
||||
*
|
||||
* @var datetime
|
||||
*/
|
||||
public $last_modified_date;
|
||||
/**
|
||||
* Used to store option group id.
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $result_id;
|
||||
/**
|
||||
* Bypass the email verification.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $bypass_confirm;
|
||||
/**
|
||||
* Title for Thank-you page (header title tag, and display at the top of the page).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $thankyou_title;
|
||||
/**
|
||||
* text and html allowed. displayed above result on success page
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $thankyou_text;
|
||||
/**
|
||||
* Can people share the petition through social media?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_share;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_survey';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'campaign_id', 'civicrm_campaign', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'created_id', 'civicrm_contact', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'last_modified_id', 'civicrm_contact', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey ID') ,
|
||||
'description' => 'Survey id.',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'title' => array(
|
||||
'name' => 'title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Survey Title') ,
|
||||
'description' => 'Title of the Survey.',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'import' => true,
|
||||
'where' => 'civicrm_survey.title',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'campaign_id' => array(
|
||||
'name' => 'campaign_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey Campaign ID') ,
|
||||
'description' => 'Foreign key to the Campaign.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Campaign_DAO_Campaign',
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_campaign',
|
||||
'keyColumn' => 'id',
|
||||
'labelColumn' => 'title',
|
||||
)
|
||||
) ,
|
||||
'activity_type_id' => array(
|
||||
'name' => 'activity_type_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Activity Type') ,
|
||||
'description' => 'Implicit FK to civicrm_option_value where option_group = activity_type',
|
||||
'import' => true,
|
||||
'where' => 'civicrm_survey.activity_type_id',
|
||||
'headerPattern' => '',
|
||||
'dataPattern' => '',
|
||||
'export' => true,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'activity_type',
|
||||
'optionEditPath' => 'civicrm/admin/options/activity_type',
|
||||
)
|
||||
) ,
|
||||
'recontact_interval' => array(
|
||||
'name' => 'recontact_interval',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Follow up Interval') ,
|
||||
'description' => 'Recontact intervals for each status.',
|
||||
'rows' => 20,
|
||||
'cols' => 80,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'instructions' => array(
|
||||
'name' => 'instructions',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Instructions') ,
|
||||
'description' => 'Script instructions for volunteers to use for the survey.',
|
||||
'rows' => 20,
|
||||
'cols' => 80,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 1,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'release_frequency' => array(
|
||||
'name' => 'release_frequency',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey Hold Duration') ,
|
||||
'description' => 'Number of days for recurrence of release.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'max_number_of_contacts' => array(
|
||||
'name' => 'max_number_of_contacts',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Maximum number of contacts') ,
|
||||
'description' => 'Maximum number of contacts to allow for survey.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'default_number_of_contacts' => array(
|
||||
'name' => 'default_number_of_contacts',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Default number of contacts') ,
|
||||
'description' => 'Default number of contacts to allow for survey.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Survey Is Active') ,
|
||||
'description' => 'Is this survey enabled or disabled/cancelled?',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_default' => array(
|
||||
'name' => 'is_default',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is Default Survey') ,
|
||||
'description' => 'Is this default survey?',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'created_id' => array(
|
||||
'name' => 'created_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey Created By') ,
|
||||
'description' => 'FK to civicrm_contact, who created this Survey.',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'created_date' => array(
|
||||
'name' => 'created_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Campaign Created Date') ,
|
||||
'description' => 'Date and time that Survey was created.',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'last_modified_id' => array(
|
||||
'name' => 'last_modified_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey Modified') ,
|
||||
'description' => 'FK to civicrm_contact, who recently edited this Survey.',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
) ,
|
||||
'last_modified_date' => array(
|
||||
'name' => 'last_modified_date',
|
||||
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
|
||||
'title' => ts('Survey Modified On') ,
|
||||
'description' => 'Date and time that Survey was edited last time.',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'result_id' => array(
|
||||
'name' => 'result_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Survey Result') ,
|
||||
'description' => 'Used to store option group id.',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'bypass_confirm' => array(
|
||||
'name' => 'bypass_confirm',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('No Email Verification') ,
|
||||
'description' => 'Bypass the email verification.',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'thankyou_title' => array(
|
||||
'name' => 'thankyou_title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Thank-you Title') ,
|
||||
'description' => 'Title for Thank-you page (header title tag, and display at the top of the page).',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'thankyou_text' => array(
|
||||
'name' => 'thankyou_text',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Thank-you Text') ,
|
||||
'description' => 'text and html allowed. displayed above result on success page',
|
||||
'rows' => 8,
|
||||
'cols' => 60,
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 1,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'is_share' => array(
|
||||
'name' => 'is_share',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Is shared through social media') ,
|
||||
'description' => 'Can people share the petition through social media?',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_survey',
|
||||
'entity' => 'Survey',
|
||||
'bao' => 'CRM_Campaign_BAO_Survey',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'survey', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'survey', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array(
|
||||
'UI_activity_type_id' => array(
|
||||
'name' => 'UI_activity_type_id',
|
||||
'field' => array(
|
||||
0 => 'activity_type_id',
|
||||
) ,
|
||||
'localizable' => false,
|
||||
'sig' => 'civicrm_survey::0::activity_type_id',
|
||||
) ,
|
||||
);
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
367
sites/all/modules/civicrm/CRM/Campaign/Form/Campaign.php
Normal file
367
sites/all/modules/civicrm/CRM/Campaign/Form/Campaign.php
Normal file
|
@ -0,0 +1,367 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a campaign.
|
||||
*/
|
||||
class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Context
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* Object values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_values;
|
||||
|
||||
/**
|
||||
* The id of the campaign we are proceessing
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_campaignId;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Campaign';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
|
||||
$this->_campaignId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
$title = NULL;
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
$title = ts('Edit Campaign');
|
||||
}
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$title = ts('Delete Campaign');
|
||||
}
|
||||
if ($title) {
|
||||
CRM_Utils_System::setTitle($title);
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
|
||||
$this->assign('action', $this->_action);
|
||||
|
||||
//load the values;
|
||||
$this->_values = $this->get('values');
|
||||
if (!is_array($this->_values)) {
|
||||
$this->_values = array();
|
||||
|
||||
// if we are editing
|
||||
if (isset($this->_campaignId) && $this->_campaignId) {
|
||||
$params = array('id' => $this->_campaignId);
|
||||
CRM_Campaign_BAO_Campaign::retrieve($params, $this->_values);
|
||||
}
|
||||
|
||||
//lets use current object session.
|
||||
$this->set('values', $this->_values);
|
||||
}
|
||||
|
||||
// when custom data is included in form.
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
$campaignTypeId = empty($_POST['campaign_type_id']) ? NULL : $_POST['campaign_type_id'];
|
||||
$this->set('type', 'Campaign');
|
||||
$this->set('subType', $campaignTypeId);
|
||||
$this->set('entityId', $this->_campaignId);
|
||||
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, $campaignTypeId, 1, 'Campaign', $this->_campaignId);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
if (isset($defaults['start_date'])) {
|
||||
list($defaults['start_date'], $defaults['start_date_time'])
|
||||
= CRM_Utils_Date::setDateDefaults($defaults['start_date'], 'activityDateTime');
|
||||
}
|
||||
else {
|
||||
list($defaults['start_date'], $defaults['start_date_time'])
|
||||
= CRM_Utils_Date::setDateDefaults();
|
||||
}
|
||||
|
||||
if (isset($defaults['end_date'])) {
|
||||
list($defaults['end_date'], $defaults['end_date_time'])
|
||||
= CRM_Utils_Date::setDateDefaults($defaults['end_date'], 'activityDateTime');
|
||||
}
|
||||
|
||||
if (!isset($defaults['is_active'])) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
if (!$this->_campaignId) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
$dao = new CRM_Campaign_DAO_CampaignGroup();
|
||||
|
||||
$campaignGroups = array();
|
||||
$dao->campaign_id = $this->_campaignId;
|
||||
$dao->find();
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$campaignGroups[$dao->entity_table][$dao->group_type][] = $dao->entity_id;
|
||||
}
|
||||
|
||||
if (!empty($campaignGroups)) {
|
||||
$defaults['includeGroups'] = $campaignGroups['civicrm_group']['Include'];
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
//lets assign custom data type and subtype.
|
||||
$this->assign('customDataType', 'Campaign');
|
||||
$this->assign('entityID', $this->_campaignId);
|
||||
$this->assign('customDataSubType', CRM_Utils_Array::value('campaign_type_id', $this->_values));
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign');
|
||||
|
||||
// add comaign title.
|
||||
$this->add('text', 'title', ts('Title'), $attributes['title'], TRUE);
|
||||
|
||||
// add description
|
||||
$this->add('textarea', 'description', ts('Description'), $attributes['description']);
|
||||
|
||||
// add campaign start date
|
||||
$this->addDateTime('start_date', ts('Start Date'), TRUE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
// add campaign end date
|
||||
$this->addDateTime('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDateTime'));
|
||||
|
||||
// add campaign type
|
||||
$this->addSelect('campaign_type_id', array('onChange' => "CRM.buildCustomData( 'Campaign', this.value );"), TRUE);
|
||||
|
||||
// add campaign status
|
||||
$this->addSelect('status_id');
|
||||
|
||||
// add External Identifier Element
|
||||
$this->add('text', 'external_identifier', ts('External ID'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign', 'external_identifier'), FALSE
|
||||
);
|
||||
|
||||
// add Campaign Parent Id
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('parent_id', $this->_values), $this->_campaignId);
|
||||
if (!empty($campaigns)) {
|
||||
$this->addElement('select', 'parent_id', ts('Parent ID'),
|
||||
array('' => ts('- select Parent -')) + $campaigns,
|
||||
array('class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
//get the campaign groups.
|
||||
$this->add('select', 'includeGroups',
|
||||
ts('Include Group(s)'),
|
||||
$groups,
|
||||
FALSE,
|
||||
array(
|
||||
'multiple' => TRUE,
|
||||
'class' => 'crm-select2 huge',
|
||||
'placeholder' => ts('- none -'),
|
||||
)
|
||||
);
|
||||
|
||||
$this->add('wysiwyg', 'goal_general', ts('Campaign Goals'), array('rows' => 2, 'cols' => 40));
|
||||
$this->add('text', 'goal_revenue', ts('Revenue Goal'), array('size' => 8, 'maxlength' => 12));
|
||||
$this->addRule('goal_revenue', ts('Please enter a valid money value (e.g. %1).',
|
||||
array(1 => CRM_Utils_Money::format('99.99', ' '))
|
||||
), 'money');
|
||||
|
||||
// is this Campaign active
|
||||
$this->addElement('checkbox', 'is_active', ts('Is Active?'));
|
||||
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* add the rules (mainly global rules) for form.
|
||||
* All local rules are added near the element
|
||||
*
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $errors
|
||||
*
|
||||
* @return bool|array
|
||||
* @see valid_date
|
||||
*/
|
||||
public static function formRule($fields, $files, $errors) {
|
||||
$errors = array();
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission of new/edit campaign is processed.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$groups = array();
|
||||
if (isset($this->_campaignId)) {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Campaign_BAO_Campaign::del($this->_campaignId);
|
||||
CRM_Core_Session::setStatus(ts('Campaign has been deleted.'), ts('Record Deleted'), 'success');
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
|
||||
return;
|
||||
}
|
||||
$params['id'] = $this->_campaignId;
|
||||
}
|
||||
else {
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
// format params
|
||||
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
|
||||
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
|
||||
$params['last_modified_id'] = $session->get('userID');
|
||||
$params['last_modified_date'] = date('YmdHis');
|
||||
|
||||
if (is_array($params['includeGroups'])) {
|
||||
foreach ($params['includeGroups'] as $key => $id) {
|
||||
if ($id) {
|
||||
$groups['include'][] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
$params['groups'] = $groups;
|
||||
|
||||
// delete previous includes/excludes, if campaign already existed
|
||||
$groupTableName = CRM_Contact_BAO_Group::getTableName();
|
||||
$dao = new CRM_Campaign_DAO_CampaignGroup();
|
||||
$dao->campaign_id = $this->_campaignId;
|
||||
$dao->entity_table = $groupTableName;
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$dao->delete();
|
||||
}
|
||||
|
||||
//process custom data.
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Campaign', FALSE, FALSE,
|
||||
CRM_Utils_Array::value('campaign_type_id', $params)
|
||||
);
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
$this->_campaignId,
|
||||
'Campaign'
|
||||
);
|
||||
|
||||
$result = CRM_Campaign_BAO_Campaign::create($params);
|
||||
|
||||
if ($result) {
|
||||
CRM_Core_Session::setStatus(ts('Campaign %1 has been saved.', array(1 => $result->title)), ts('Saved'), 'success');
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
|
||||
}
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->getButtonName('upload', 'new')) {
|
||||
CRM_Core_Session::setStatus(ts(' You can add another Campaign.'), '', 'info');
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
168
sites/all/modules/civicrm/CRM/Campaign/Form/Gotv.php
Normal file
168
sites/all/modules/civicrm/CRM/Campaign/Form/Gotv.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required
|
||||
*/
|
||||
class CRM_Campaign_Form_Gotv extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Are we forced to run a search
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_force;
|
||||
|
||||
protected $_votingTab = FALSE;
|
||||
|
||||
protected $_searchVoterFor;
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_search = CRM_Utils_Array::value('search', $_GET);
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
|
||||
$this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
|
||||
//does control come from voting tab interface.
|
||||
$this->_votingTab = $this->get('votingTab');
|
||||
$this->_subVotingTab = $this->get('subVotingTab');
|
||||
$this->_searchVoterFor = 'gotv';
|
||||
if ($this->_votingTab) {
|
||||
if ($this->_subVotingTab == 'searchANDReserve') {
|
||||
$this->_searchVoterFor = 'reserve';
|
||||
}
|
||||
elseif ($this->_subVotingTab == 'searchANDInterview') {
|
||||
$this->_searchVoterFor = 'interview';
|
||||
}
|
||||
}
|
||||
$this->assign('force', $this->_force);
|
||||
$this->assign('votingTab', $this->_votingTab);
|
||||
$this->assign('searchParams', json_encode($this->get('searchParams')));
|
||||
$this->assign('buildSelector', $this->_search);
|
||||
$this->assign('searchVoterFor', $this->_searchVoterFor);
|
||||
$this->set('searchVoterFor', $this->_searchVoterFor);
|
||||
|
||||
$surveyTitle = NULL;
|
||||
if ($this->_surveyId) {
|
||||
$surveyTitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'title');
|
||||
}
|
||||
$this->assign('surveyTitle', $surveyTitle);
|
||||
|
||||
//append breadcrumb to survey dashboard.
|
||||
if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
|
||||
}
|
||||
|
||||
//set the form title.
|
||||
CRM_Utils_System::setTitle(ts('GOTV (Voter Tracking)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_search) {
|
||||
return;
|
||||
}
|
||||
|
||||
//build common search form.
|
||||
CRM_Campaign_BAO_Query::buildSearchForm($this);
|
||||
|
||||
//build the array of all search params.
|
||||
$this->_searchParams = array();
|
||||
foreach ($this->_elements as $element) {
|
||||
$name = $element->_attributes['name'];
|
||||
if ($name == 'qfKey') {
|
||||
continue;
|
||||
}
|
||||
$this->_searchParams[$name] = $name;
|
||||
}
|
||||
$this->set('searchParams', $this->_searchParams);
|
||||
$this->assign('searchParams', json_encode($this->_searchParams));
|
||||
|
||||
$defaults = array();
|
||||
|
||||
if (!$this->_surveyId) {
|
||||
$this->_surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE));
|
||||
}
|
||||
|
||||
if ($this->_force || $this->_votingTab) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$userId = $session->get('userID');
|
||||
// get interviewer id
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, $userId
|
||||
);
|
||||
|
||||
$defaults['survey_interviewer_id'] = $cid;
|
||||
}
|
||||
if ($this->_surveyId) {
|
||||
$defaults['campaign_survey_id'] = $this->_surveyId;
|
||||
}
|
||||
if (!empty($defaults)) {
|
||||
$this->setDefaults($defaults);
|
||||
}
|
||||
|
||||
//validate the required ids.
|
||||
$this->validateIds();
|
||||
}
|
||||
|
||||
public function validateIds() {
|
||||
$errorMessages = array();
|
||||
//check for required permissions.
|
||||
if (!CRM_Core_Permission::check('manage campaign') &&
|
||||
!CRM_Core_Permission::check('administer CiviCampaign') &&
|
||||
!CRM_Core_Permission::check("{$this->_searchVoterFor} campaign contacts")
|
||||
) {
|
||||
$errorMessages[] = ts('You are not authorized to access this page.');
|
||||
}
|
||||
|
||||
$surveys = CRM_Campaign_BAO_Survey::getSurveys();
|
||||
if (empty($surveys)) {
|
||||
$errorMessages[] = ts("Oops. It looks like no surveys have been created. <a href='%1'>Click here to create a new survey.</a>", array(1 => CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')));
|
||||
}
|
||||
|
||||
if ($this->_force && !$this->_surveyId) {
|
||||
|
||||
$errorMessages[] = ts('Could not find Survey.');
|
||||
|
||||
}
|
||||
|
||||
$this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages);
|
||||
}
|
||||
|
||||
}
|
370
sites/all/modules/civicrm/CRM/Campaign/Form/Petition.php
Normal file
370
sites/all/modules/civicrm/CRM/Campaign/Form/Petition.php
Normal file
|
@ -0,0 +1,370 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for adding a petition.
|
||||
*/
|
||||
class CRM_Campaign_Form_Petition extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Making this public so we can reference it in the formRule
|
||||
* @var int
|
||||
*/
|
||||
public $_surveyId;
|
||||
|
||||
public function preProcess() {
|
||||
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
|
||||
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
CRM_Utils_System::setTitle(ts('Edit Survey'));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Delete Survey'));
|
||||
}
|
||||
}
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
$this->set('type', 'Event');
|
||||
$this->set('entityId', $this->_surveyId);
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
$session->pushUserContext($url);
|
||||
|
||||
$this->_values = $this->get('values');
|
||||
|
||||
if (!is_array($this->_values)) {
|
||||
$this->_values = array();
|
||||
if ($this->_surveyId) {
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->_values);
|
||||
}
|
||||
$this->set('values', $this->_values);
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('surveyId', $this->_surveyId);
|
||||
// for custom data
|
||||
$this->assign('entityID', $this->_surveyId);
|
||||
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
CRM_Utils_System::setTitle(ts('Edit Petition'));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setTitle(ts('Delete Petition'));
|
||||
}
|
||||
}
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition');
|
||||
$session->pushUserContext($url);
|
||||
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Petition Dashboard'), 'url' => $url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
$ufContactJoinParams = array(
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'entity_id' => $this->_surveyId,
|
||||
'weight' => 2,
|
||||
);
|
||||
|
||||
if ($ufContactGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufContactJoinParams)) {
|
||||
$defaults['contact_profile_id'] = $ufContactGroupId;
|
||||
}
|
||||
$ufActivityJoinParams = array(
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'entity_id' => $this->_surveyId,
|
||||
'weight' => 1,
|
||||
);
|
||||
|
||||
if ($ufActivityGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufActivityJoinParams)) {
|
||||
$defaults['profile_id'] = $ufActivityGroupId;
|
||||
}
|
||||
|
||||
if (!isset($defaults['is_active'])) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
$defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE);
|
||||
if (!isset($defaults['is_default']) && empty($defaultSurveys)) {
|
||||
$defaults['is_default'] = 1;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
|
||||
public function buildQuickForm() {
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add('text', 'title', ts('Petition Title'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'title'), TRUE);
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey');
|
||||
|
||||
$petitionTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Petition');
|
||||
$this->addElement('hidden', 'activity_type_id', $petitionTypeID);
|
||||
|
||||
// script / instructions / description of petition purpose
|
||||
$this->add('wysiwyg', 'instructions', ts('Introduction'), $attributes['instructions']);
|
||||
|
||||
// Campaign id
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('campaign_id', $this->_values));
|
||||
$this->add('select', 'campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns);
|
||||
|
||||
$customContactProfiles = CRM_Core_BAO_UFGroup::getProfiles(array('Individual'));
|
||||
// custom group id
|
||||
$this->add('select', 'contact_profile_id', ts('Contact Profile'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $customContactProfiles, TRUE
|
||||
);
|
||||
|
||||
$customProfiles = CRM_Core_BAO_UFGroup::getProfiles(array('Activity'));
|
||||
// custom group id
|
||||
$this->add('select', 'profile_id', ts('Activity Profile'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $customProfiles
|
||||
);
|
||||
|
||||
// thank you title and text (html allowed in text)
|
||||
$this->add('text', 'thankyou_title', ts('Thank-you Page Title'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'thankyou_title'));
|
||||
$this->add('wysiwyg', 'thankyou_text', ts('Thank-you Message'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'thankyou_text'));
|
||||
|
||||
// bypass email confirmation?
|
||||
$this->add('checkbox', 'bypass_confirm', ts('Bypass email confirmation'));
|
||||
|
||||
//is share through social media
|
||||
$this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
|
||||
|
||||
// is active ?
|
||||
$this->add('checkbox', 'is_active', ts('Is Active?'));
|
||||
|
||||
// is default ?
|
||||
$this->add('checkbox', 'is_default', ts('Is Default?'));
|
||||
|
||||
// add buttons
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save and New'),
|
||||
'subName' => 'new',
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// add a form rule to check default value
|
||||
$this->addFormRule(array('CRM_Campaign_Form_Petition', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $form
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$errors = array();
|
||||
// Petitions should be unique by: title, campaign ID (if assigned) and activity type ID
|
||||
// NOTE: This class is called for both Petition create / update AND for Survey Results tab, but this rule is only for Petition.
|
||||
$where = array('activity_type_id = %1', 'title = %2');
|
||||
$params = array(
|
||||
1 => array($fields['activity_type_id'], 'Integer'),
|
||||
2 => array($fields['title'], 'String'),
|
||||
);
|
||||
$uniqueRuleErrorMessage = ts('This title is already associated with the selected activity type. Please specify a unique title.');
|
||||
|
||||
if (empty($fields['campaign_id'])) {
|
||||
$where[] = 'campaign_id IS NULL';
|
||||
}
|
||||
else {
|
||||
$where[] = 'campaign_id = %3';
|
||||
$params[3] = array($fields['campaign_id'], 'Integer');
|
||||
$uniqueRuleErrorMessage = ts('This title is already associated with the selected campaign and activity type. Please specify a unique title.');
|
||||
}
|
||||
|
||||
// Exclude current Petition row if UPDATE.
|
||||
if ($form->_surveyId) {
|
||||
$where[] = 'id != %4';
|
||||
$params[4] = array($form->_surveyId, 'Integer');
|
||||
}
|
||||
|
||||
$whereClause = implode(' AND ', $where);
|
||||
|
||||
$query = "
|
||||
SELECT COUNT(*) AS row_count
|
||||
FROM civicrm_survey
|
||||
WHERE $whereClause
|
||||
";
|
||||
|
||||
$result = CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
if ($result >= 1) {
|
||||
$errors['title'] = $uniqueRuleErrorMessage;
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$params['last_modified_id'] = $session->get('userID');
|
||||
$params['last_modified_date'] = date('YmdHis');
|
||||
$params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
|
||||
|
||||
if ($this->_surveyId) {
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_Campaign_BAO_Survey::del($this->_surveyId);
|
||||
CRM_Core_Session::setStatus(ts(' Petition has been deleted.'), ts('Record Deleted'), 'success');
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'));
|
||||
return;
|
||||
}
|
||||
|
||||
$params['id'] = $this->_surveyId;
|
||||
}
|
||||
else {
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
|
||||
$params['bypass_confirm'] = CRM_Utils_Array::value('bypass_confirm', $params, 0);
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
|
||||
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
|
||||
|
||||
$customFields = CRM_Core_BAO_CustomField::getFields('Survey');
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
$this->_surveyId,
|
||||
'Survey'
|
||||
);
|
||||
|
||||
$surveyId = CRM_Campaign_BAO_Survey::create($params);
|
||||
|
||||
// also update the ProfileModule tables
|
||||
$ufJoinParams = array(
|
||||
'is_active' => 1,
|
||||
'module' => 'CiviCampaign',
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'entity_id' => $surveyId->id,
|
||||
);
|
||||
|
||||
// first delete all past entries
|
||||
if ($this->_surveyId) {
|
||||
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
|
||||
}
|
||||
if (!empty($params['profile_id'])) {
|
||||
$ufJoinParams['weight'] = 1;
|
||||
$ufJoinParams['uf_group_id'] = $params['profile_id'];
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParams);
|
||||
}
|
||||
|
||||
if (!empty($params['contact_profile_id'])) {
|
||||
$ufJoinParams['weight'] = 2;
|
||||
$ufJoinParams['uf_group_id'] = $params['contact_profile_id'];
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParams);
|
||||
}
|
||||
|
||||
if (!is_a($surveyId, 'CRM_Core_Error')) {
|
||||
CRM_Core_Session::setStatus(ts('Petition has been saved.'), ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->getButtonName('next', 'new')) {
|
||||
CRM_Core_Session::setStatus(ts(' You can add another Petition.'), '', 'info');
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/petition/add', 'reset=1&action=add'));
|
||||
}
|
||||
else {
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,653 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a petition signature.
|
||||
*/
|
||||
class CRM_Campaign_Form_Petition_Signature extends CRM_Core_Form {
|
||||
const EMAIL_THANK = 1, EMAIL_CONFIRM = 2, MODE_CREATE = 4;
|
||||
|
||||
protected $_mode;
|
||||
|
||||
/**
|
||||
* The id of the contact associated with this signature
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_contactId;
|
||||
|
||||
/**
|
||||
* Is this a logged in user
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_loggedIn = FALSE;
|
||||
|
||||
/**
|
||||
* The contact type
|
||||
*
|
||||
* @var string ("Individual"/"Household"/"Organization"). Never been tested for something else than Individual
|
||||
*/
|
||||
protected $_ctype = 'Individual';
|
||||
|
||||
/**
|
||||
* The contact profile id attached with this petition
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_contactProfileId;
|
||||
|
||||
/**
|
||||
* The contact profile fields used for this petition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactProfileFields;
|
||||
|
||||
/**
|
||||
* The activity profile id attached with this petition
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_activityProfileId;
|
||||
|
||||
/**
|
||||
* The activity profile fields used for this petition
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_activityProfileFields;
|
||||
|
||||
/**
|
||||
* The id of the survey (petition) we are proceessing
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_surveyId;
|
||||
|
||||
/**
|
||||
* The tag id used to set against contacts with unconfirmed email
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_tagId;
|
||||
|
||||
/**
|
||||
* Values to use for custom profiles
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* The params submitted by the form
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_params;
|
||||
|
||||
/**
|
||||
* Which email send mode do we use
|
||||
*
|
||||
* @var int
|
||||
* EMAIL_THANK = 1,
|
||||
* connected user via login/pwd - thank you
|
||||
* or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
|
||||
* or login using fb connect - thank you + click to add msg to fb wall
|
||||
* EMAIL_CONFIRM = 2;
|
||||
* send a confirmation request email
|
||||
*/
|
||||
protected $_sendEmailMode;
|
||||
|
||||
protected $_image_URL;
|
||||
|
||||
/**
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// this property used by civicrm_fb module and if true, forces thank you email to be sent
|
||||
// for users signing in via Facebook connect; also sets Fb email to check against
|
||||
$this->forceEmailConfirmed['flag'] = FALSE;
|
||||
$this->forceEmailConfirmed['email'] = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContactID() {
|
||||
$tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
|
||||
// force to ignore the authenticated user
|
||||
if ($tempID === '0') {
|
||||
return $tempID;
|
||||
}
|
||||
|
||||
//check if this is a checksum authentication
|
||||
$userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
|
||||
if ($userChecksum) {
|
||||
//check for anonymous user.
|
||||
$validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
|
||||
if ($validUser) {
|
||||
return $tempID;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the user is registered and we have a contact ID
|
||||
$session = CRM_Core_Session::singleton();
|
||||
return $session->get('userID');
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
$this->bao = new CRM_Campaign_BAO_Petition();
|
||||
$this->_mode = self::MODE_CREATE;
|
||||
|
||||
//get the survey id
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
|
||||
|
||||
//some sanity checks
|
||||
if (!$this->_surveyId) {
|
||||
CRM_Core_Error::fatal('Petition id is not valid. (it needs a "sid" in the url).');
|
||||
return;
|
||||
}
|
||||
//check petition is valid and active
|
||||
$params['id'] = $this->_surveyId;
|
||||
$this->petition = array();
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->petition);
|
||||
if (empty($this->petition)) {
|
||||
CRM_Core_Error::fatal('Petition doesn\'t exist.');
|
||||
}
|
||||
if ($this->petition['is_active'] == 0) {
|
||||
CRM_Core_Error::fatal('Petition is no longer active.');
|
||||
}
|
||||
|
||||
//get userID from session
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
//get the contact id for this user if logged in
|
||||
$this->_contactId = $this->getContactId();
|
||||
if (isset($this->_contactId)) {
|
||||
$this->_loggedIn = TRUE;
|
||||
}
|
||||
|
||||
// add the custom contact and activity profile fields to the signature form
|
||||
|
||||
$ufJoinParams = array(
|
||||
'entity_id' => $this->_surveyId,
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'module' => 'CiviCampaign',
|
||||
'weight' => 2,
|
||||
);
|
||||
|
||||
$this->_contactProfileId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
|
||||
if ($this->_contactProfileId) {
|
||||
$this->_contactProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_contactProfileId, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
if (!isset($this->_contactProfileFields['email-Primary'])) {
|
||||
CRM_Core_Error::fatal('The contact profile needs to contain the primary email address field');
|
||||
}
|
||||
|
||||
$ufJoinParams['weight'] = 1;
|
||||
$this->_activityProfileId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams);
|
||||
|
||||
if ($this->_activityProfileId) {
|
||||
$this->_activityProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_activityProfileId, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
|
||||
$this->setDefaultValues();
|
||||
CRM_Utils_System::setTitle($this->petition['title']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$this->_defaults = array();
|
||||
if ($this->_contactId) {
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_contactProfileFields, $this->_defaults, TRUE);
|
||||
if ($this->_activityProfileId) {
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_activityProfileFields, $this->_defaults, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
//set custom field defaults
|
||||
|
||||
foreach ($this->_contactProfileFields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
$htmlType = $field['html_type'];
|
||||
|
||||
if (!isset($this->_defaults[$name])) {
|
||||
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID,
|
||||
$name,
|
||||
$this->_defaults,
|
||||
$this->_contactId,
|
||||
$this->_mode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_activityProfileFields) {
|
||||
foreach ($this->_activityProfileFields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
$htmlType = $field['html_type'];
|
||||
|
||||
if (!isset($this->_defaults[$name])) {
|
||||
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID,
|
||||
$name,
|
||||
$this->_defaults,
|
||||
$this->_contactId,
|
||||
$this->_mode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->setDefaults($this->_defaults);
|
||||
}
|
||||
|
||||
public function buildQuickForm() {
|
||||
$this->assign('survey_id', $this->_surveyId);
|
||||
$this->assign('petitionTitle', $this->petition['title']);
|
||||
if (isset($_COOKIE['signed_' . $this->_surveyId])) {
|
||||
if (isset($_COOKIE['confirmed_' . $this->_surveyId])) {
|
||||
$this->assign('duplicate', "confirmed");
|
||||
}
|
||||
else {
|
||||
$this->assign('duplicate', "unconfirmed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
|
||||
$this->buildCustom($this->_contactProfileId, 'petitionContactProfile');
|
||||
if ($this->_activityProfileId) {
|
||||
$this->buildCustom($this->_activityProfileId, 'petitionActivityProfile');
|
||||
}
|
||||
// add buttons
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Sign the Petition'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* add the rules (mainly global rules) for form.
|
||||
* All local rules are added near the element
|
||||
*
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $errors
|
||||
*
|
||||
* @see valid_date
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields, $files, $errors) {
|
||||
$errors = array();
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission of petition signature.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$tag_name = Civi::settings()->get('tag_unconfirmed');
|
||||
|
||||
if ($tag_name) {
|
||||
// Check if contact 'email confirmed' tag exists, else create one
|
||||
// This should be in the petition module initialise code to create a default tag for this
|
||||
$tag_params['name'] = $tag_name;
|
||||
$tag_params['version'] = 3;
|
||||
$tag = civicrm_api('tag', 'get', $tag_params);
|
||||
if ($tag['count'] == 0) {
|
||||
//create tag
|
||||
$tag_params['description'] = $tag_name;
|
||||
$tag_params['is_reserved'] = 1;
|
||||
$tag_params['used_for'] = 'civicrm_contact';
|
||||
$tag = civicrm_api('tag', 'create', $tag_params);
|
||||
}
|
||||
$this->_tagId = $tag['id'];
|
||||
}
|
||||
|
||||
// export the field values to be used for saving the profile form
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
// format params
|
||||
$params['last_modified_id'] = $session->get('userID');
|
||||
$params['last_modified_date'] = date('YmdHis');
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
|
||||
if (isset($this->_surveyId)) {
|
||||
$params['sid'] = $this->_surveyId;
|
||||
}
|
||||
|
||||
if (isset($this->_contactId)) {
|
||||
$params['contactId'] = $this->_contactId;
|
||||
}
|
||||
|
||||
// if logged in user, skip dedupe
|
||||
if ($this->_loggedIn) {
|
||||
$ids[0] = $this->_contactId;
|
||||
}
|
||||
else {
|
||||
$ids = CRM_Contact_BAO_Contact::getDuplicateContacts($params, $this->_ctype, 'Unsupervised', array(), FALSE);
|
||||
}
|
||||
|
||||
$petition_params['id'] = $this->_surveyId;
|
||||
$petition = array();
|
||||
CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition);
|
||||
|
||||
switch (count($ids)) {
|
||||
case 0:
|
||||
//no matching contacts - create a new contact
|
||||
// Add a source for this new contact
|
||||
$params['source'] = ts('Petition Signature') . ' ' . $this->petition['title'];
|
||||
|
||||
if ($this->petition['bypass_confirm']) {
|
||||
// send thank you email directly, bypassing confirmation
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
// Set status for signature activity to completed
|
||||
$params['statusId'] = 2;
|
||||
}
|
||||
else {
|
||||
$this->_sendEmailMode = self::EMAIL_CONFIRM;
|
||||
|
||||
// Set status for signature activity to scheduled until email is verified
|
||||
$params['statusId'] = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$this->_contactId = $params['contactId'] = $ids[0];
|
||||
|
||||
// check if user has already signed this petition - redirects to Thank You if true
|
||||
$this->redirectIfSigned($params);
|
||||
|
||||
if ($this->petition['bypass_confirm']) {
|
||||
// send thank you email directly, bypassing confirmation
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
// Set status for signature activity to completed
|
||||
$params['statusId'] = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// dedupe matched single contact, check for 'unconfirmed' tag
|
||||
if ($tag_name) {
|
||||
$tag = new CRM_Core_DAO_EntityTag();
|
||||
$tag->entity_id = $this->_contactId;
|
||||
$tag->tag_id = $this->_tagId;
|
||||
|
||||
if (!($tag->find())) {
|
||||
// send thank you email directly, the user is known and validated
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
// Set status for signature activity to completed
|
||||
$params['statusId'] = 2;
|
||||
}
|
||||
else {
|
||||
// send email verification email
|
||||
$this->_sendEmailMode = self::EMAIL_CONFIRM;
|
||||
// Set status for signature activity to scheduled until email is verified
|
||||
$params['statusId'] = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// more than 1 matching contact
|
||||
// for time being, take the first matching contact (not sure that's the best strategy, but better than creating another duplicate)
|
||||
$this->_contactId = $params['contactId'] = $ids[0];
|
||||
|
||||
// check if user has already signed this petition - redirects to Thank You if true
|
||||
$this->redirectIfSigned($params);
|
||||
|
||||
if ($this->petition['bypass_confirm']) {
|
||||
// send thank you email directly, bypassing confirmation
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
// Set status for signature activity to completed
|
||||
$params['statusId'] = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($tag_name) {
|
||||
$tag = new CRM_Core_DAO_EntityTag();
|
||||
$tag->entity_id = $this->_contactId;
|
||||
$tag->tag_id = $this->_tagId;
|
||||
|
||||
if (!($tag->find())) {
|
||||
// send thank you email
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
// Set status for signature activity to completed
|
||||
$params['statusId'] = 2;
|
||||
}
|
||||
else {
|
||||
// send email verification email
|
||||
$this->_sendEmailMode = self::EMAIL_CONFIRM;
|
||||
// Set status for signature activity to scheduled until email is verified
|
||||
$params['statusId'] = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
// CRM-17029 - get the add_to_group_id from the _contactProfileFields array.
|
||||
// There's a much more elegant solution with
|
||||
// array_values($this->_contactProfileFields)[0] but it's PHP 5.4+ only.
|
||||
$slice = array_slice($this->_contactProfileFields, 0, 1);
|
||||
$firstField = array_shift($slice);
|
||||
$addToGroupID = isset($firstField['add_to_group_id']) ? $firstField['add_to_group_id'] : NULL;
|
||||
$this->_contactId = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_contactProfileFields,
|
||||
$this->_contactId, $addToGroupID,
|
||||
$this->_contactProfileId, $this->_ctype,
|
||||
TRUE
|
||||
);
|
||||
|
||||
// get additional custom activity profile field data
|
||||
// to save with new signature activity record
|
||||
$surveyInfo = $this->bao->getSurveyInfo($this->_surveyId);
|
||||
$customActivityFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE,
|
||||
$surveyInfo['activity_type_id']
|
||||
);
|
||||
$customActivityFields = CRM_Utils_Array::crmArrayMerge($customActivityFields,
|
||||
CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE,
|
||||
NULL, NULL, TRUE
|
||||
)
|
||||
);
|
||||
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
NULL,
|
||||
'Activity'
|
||||
);
|
||||
|
||||
// create the signature activity record
|
||||
$params['contactId'] = $this->_contactId;
|
||||
$params['activity_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->petition);
|
||||
$result = $this->bao->createSignature($params);
|
||||
|
||||
// send thank you or email verification emails
|
||||
|
||||
// if logged in using Facebook connect and email on form matches Fb email,
|
||||
// no need for email confirmation, send thank you email
|
||||
if ($this->forceEmailConfirmed['flag'] &&
|
||||
($this->forceEmailConfirmed['email'] == $params['email-Primary'])
|
||||
) {
|
||||
$this->_sendEmailMode = self::EMAIL_THANK;
|
||||
}
|
||||
|
||||
switch ($this->_sendEmailMode) {
|
||||
case self::EMAIL_THANK:
|
||||
// mark the signature activity as completed and set confirmed cookie
|
||||
$this->bao->confirmSignature($result->id, $this->_contactId, $this->_surveyId);
|
||||
break;
|
||||
|
||||
case self::EMAIL_CONFIRM:
|
||||
// set 'Unconfirmed' tag for this new contact
|
||||
if ($tag_name) {
|
||||
unset($tag_params);
|
||||
$tag_params['contact_id'] = $this->_contactId;
|
||||
$tag_params['tag_id'] = $this->_tagId;
|
||||
$tag_params['version'] = 3;
|
||||
$tag_value = civicrm_api('entity_tag', 'create', $tag_params);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//send email
|
||||
$params['activityId'] = $result->id;
|
||||
$params['tagId'] = $this->_tagId;
|
||||
|
||||
$transaction->commit();
|
||||
|
||||
$this->bao->sendEmail($params, $this->_sendEmailMode);
|
||||
|
||||
if ($result) {
|
||||
// call the hook before we redirect
|
||||
$this->postProcessHook();
|
||||
|
||||
// set the template to thank you
|
||||
$url = CRM_Utils_System::url(
|
||||
'civicrm/petition/thankyou',
|
||||
'pid=' . $this->_surveyId . '&id=' . $this->_sendEmailMode . '&reset=1'
|
||||
);
|
||||
CRM_Utils_System::redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the petition profile form.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param bool $viewOnly
|
||||
*/
|
||||
public function buildCustom($id, $name, $viewOnly = FALSE) {
|
||||
if ($id) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->assign("petition", $this->petition);
|
||||
//$contactID = $this->_contactId;
|
||||
$contactID = NULL;
|
||||
$this->assign('contact_id', $this->_contactId);
|
||||
|
||||
$fields = NULL;
|
||||
// TODO: contactID is never set (commented above)
|
||||
if ($contactID) {
|
||||
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
|
||||
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
|
||||
if ($fields) {
|
||||
$this->assign($name, $fields);
|
||||
|
||||
$addCaptcha = FALSE;
|
||||
foreach ($fields as $key => $field) {
|
||||
if ($viewOnly &&
|
||||
isset($field['data_type']) &&
|
||||
$field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL')
|
||||
) {
|
||||
// ignore file upload fields
|
||||
continue;
|
||||
}
|
||||
|
||||
// if state or country in the profile, create map
|
||||
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
|
||||
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
|
||||
$this->_fields[$key] = $field;
|
||||
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
|
||||
if ($field['add_captcha'] && !$this->_contactId) {
|
||||
$addCaptcha = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($addCaptcha && !$viewOnly) {
|
||||
$captcha = CRM_Utils_ReCAPTCHA::singleton();
|
||||
$captcha->add($this);
|
||||
$this->assign("isCaptcha", TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
if (isset($this->thankyou)) {
|
||||
return ('CRM/Campaign/Page/Petition/ThankYou.tpl');
|
||||
}
|
||||
else {
|
||||
}
|
||||
return parent::getTemplateFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if user has already signed this petition.
|
||||
* @param array $params
|
||||
*/
|
||||
public function redirectIfSigned($params) {
|
||||
$signature = $this->bao->checkSignature($this->_surveyId, $this->_contactId);
|
||||
//TODO: error case when more than one signature found for this petition and this contact
|
||||
if (!empty($signature) && (count($signature) == 1)) {
|
||||
$signature_id = array_keys($signature);
|
||||
switch ($signature[$signature_id[0]]['status_id']) {
|
||||
case 1:
|
||||
//status is scheduled - email is unconfirmed
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=4&reset=1'));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
//status is completed
|
||||
$this->bao->sendEmail($params, 1);
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=5&reset=1'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
474
sites/all/modules/civicrm/CRM/Campaign/Form/Search.php
Normal file
474
sites/all/modules/civicrm/CRM/Campaign/Form/Search.php
Normal file
|
@ -0,0 +1,474 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required.
|
||||
*/
|
||||
class CRM_Campaign_Form_Search extends CRM_Core_Form_Search {
|
||||
|
||||
/**
|
||||
* The params that are sent to the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_queryParams;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* Prefix for the controller.
|
||||
*/
|
||||
protected $_prefix = "survey_";
|
||||
|
||||
|
||||
private $_operation = 'reserve';
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_done = FALSE;
|
||||
$this->_defaults = array();
|
||||
|
||||
//set the button name.
|
||||
$this->_searchButtonName = $this->getButtonName('refresh');
|
||||
$this->_printButtonName = $this->getButtonName('next', 'print');
|
||||
$this->_actionButtonName = $this->getButtonName('next', 'action');
|
||||
|
||||
//we allow the controller to set force/reset externally,
|
||||
//useful when we are being driven by the wizard framework
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
|
||||
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
|
||||
|
||||
//operation for state machine.
|
||||
$this->_operation = CRM_Utils_Request::retrieve('op', 'String', $this, FALSE, 'reserve');
|
||||
//validate operation.
|
||||
if (!in_array($this->_operation, array(
|
||||
'reserve',
|
||||
'release',
|
||||
'interview',
|
||||
))
|
||||
) {
|
||||
$this->_operation = 'reserve';
|
||||
$this->set('op', $this->_operation);
|
||||
}
|
||||
$this->set('searchVoterFor', $this->_operation);
|
||||
$this->assign('searchVoterFor', $this->_operation);
|
||||
$this->assign('isFormSubmitted', $this->isSubmitted());
|
||||
|
||||
//do check permissions.
|
||||
if (!CRM_Core_Permission::check('administer CiviCampaign') &&
|
||||
!CRM_Core_Permission::check('manage campaign') &&
|
||||
!CRM_Core_Permission::check("{$this->_operation} campaign contacts")
|
||||
) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
$this->assign("context", $this->_context);
|
||||
|
||||
// get user submitted values
|
||||
// get it from controller only if form has been submitted, else preProcess has set this
|
||||
|
||||
if (empty($_POST)) {
|
||||
$this->_formValues = $this->get('formValues');
|
||||
}
|
||||
else {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
|
||||
if ($this->_force) {
|
||||
$this->postProcess();
|
||||
$this->set('force', 0);
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
//get the voter clause.
|
||||
$voterClause = $this->voterClause();
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
|
||||
$selector = new CRM_Campaign_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
$voterClause,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'user') {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$this->assign("{$prefix}limit", $this->_limit);
|
||||
$this->assign("{$prefix}single", $this->_single);
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::TRANSFER,
|
||||
$prefix
|
||||
);
|
||||
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->moveFromSessionToTemplate();
|
||||
|
||||
//append breadcrumb to survey dashboard.
|
||||
if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
|
||||
}
|
||||
|
||||
//set the form title.
|
||||
CRM_Utils_System::setTitle(ts('Find Respondents To %1', array(1 => ucfirst($this->_operation))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the default survey for all actions.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
if (empty($this->_defaults)) {
|
||||
$defaultSurveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE));
|
||||
if ($defaultSurveyId) {
|
||||
$this->_defaults['campaign_survey_id'] = $defaultSurveyId;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
//build the search form.
|
||||
CRM_Campaign_BAO_Query::buildSearchForm($this);
|
||||
|
||||
$rows = $this->get('rows');
|
||||
if (is_array($rows)) {
|
||||
if (!$this->_single) {
|
||||
$this->addRowSelectors($rows);
|
||||
}
|
||||
|
||||
$permission = CRM_Core_Permission::getPermission();
|
||||
$allTasks = CRM_Campaign_Task::permissionedTaskTitles($permission);
|
||||
|
||||
//hack to serve right page to state machine.
|
||||
$taskMapping = array(
|
||||
'interview' => 1,
|
||||
'reserve' => 2,
|
||||
'release' => 3,
|
||||
);
|
||||
|
||||
$currentTaskValue = CRM_Utils_Array::value($this->_operation, $taskMapping);
|
||||
$taskValue = array($currentTaskValue => $allTasks[$currentTaskValue]);
|
||||
if ($this->_operation == 'interview' && !empty($this->_formValues['campaign_survey_id'])) {
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
|
||||
|
||||
$surveyTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey',
|
||||
$this->_formValues['campaign_survey_id'],
|
||||
'activity_type_id'
|
||||
);
|
||||
$taskValue = array(
|
||||
$currentTaskValue => ts('Record %1 Responses',
|
||||
array(1 => $activityTypes[$surveyTypeId])
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$this->addTaskMenu($taskValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The post processing of the form gets done here.
|
||||
*
|
||||
* Key things done during post processing are
|
||||
* - check for reset or next request. if present, skip post procesing.
|
||||
* - now check if user requested running a saved search, if so, then
|
||||
* the form values associated with the saved search are used for searching.
|
||||
* - if user has done a submit with new values the regular post submissing is
|
||||
* done.
|
||||
* The processing consists of using a Selector / Controller framework for getting the
|
||||
* search results.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_done = TRUE;
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$this->_formValues = $this->controller->exportValues($this->_name);
|
||||
}
|
||||
|
||||
$this->fixFormValues();
|
||||
|
||||
//format params as per task.
|
||||
$this->formatParams();
|
||||
|
||||
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
|
||||
|
||||
$this->set('formValues', $this->_formValues);
|
||||
$this->set('queryParams', $this->_queryParams);
|
||||
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == $this->_actionButtonName) {
|
||||
// check actionName and if next, then do not repeat a search, since we are going to the next page
|
||||
|
||||
// hack, make sure we reset the task values
|
||||
$stateMachine = $this->controller->getStateMachine();
|
||||
$formName = $stateMachine->getTaskFormName();
|
||||
|
||||
$this->controller->resetPage($formName);
|
||||
return;
|
||||
}
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
//get the voter clause.
|
||||
$voterClause = $this->voterClause();
|
||||
|
||||
$selector = new CRM_Campaign_Selector_Search($this->_queryParams,
|
||||
$this->_action,
|
||||
$voterClause,
|
||||
$this->_single,
|
||||
$this->_limit,
|
||||
$this->_context
|
||||
);
|
||||
$selector->setKey($this->controller->_key);
|
||||
|
||||
$prefix = NULL;
|
||||
if ($this->_context == 'basic' ||
|
||||
$this->_context == 'user'
|
||||
) {
|
||||
$prefix = $this->_prefix;
|
||||
}
|
||||
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
$this->get(CRM_Utils_Pager::PAGE_ID),
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SESSION,
|
||||
$prefix
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$query = $selector->getQuery();
|
||||
if ($this->_context == 'user') {
|
||||
$query->setSkipPermission(TRUE);
|
||||
}
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
public function formatParams() {
|
||||
$interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->_formValues);
|
||||
if ($interviewerId) {
|
||||
$this->set('interviewerId', $interviewerId);
|
||||
}
|
||||
|
||||
//format multi-select group and contact types.
|
||||
foreach (array('group', 'contact_type') as $param) {
|
||||
if ($this->_force) {
|
||||
continue;
|
||||
}
|
||||
$paramValue = CRM_Utils_Array::value($param, $this->_formValues);
|
||||
if ($paramValue && is_array($paramValue)) {
|
||||
unset($this->_formValues[$param]);
|
||||
foreach ($paramValue as $key => $value) {
|
||||
$this->_formValues[$param][$value] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//apply filter of survey contact type for search.
|
||||
$contactType = CRM_Campaign_BAO_Survey::getSurveyContactType(CRM_Utils_Array::value('campaign_survey_id', $this->_formValues));
|
||||
if ($contactType && in_array($this->_operation, array(
|
||||
'reserve',
|
||||
'interview',
|
||||
))
|
||||
) {
|
||||
$this->_formValues['contact_type'][$contactType] = 1;
|
||||
}
|
||||
|
||||
if ($this->_operation == 'reserve') {
|
||||
if (!empty($this->_formValues['campaign_survey_id'])) {
|
||||
$campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey',
|
||||
$this->_formValues['campaign_survey_id'],
|
||||
'campaign_id'
|
||||
);
|
||||
|
||||
//allow voter search in sub-part of given constituents,
|
||||
//but make sure in case user does not select any group.
|
||||
//get all associated campaign groups in where filter, CRM-7406
|
||||
$groups = CRM_Utils_Array::value('group', $this->_formValues);
|
||||
if ($campaignId && CRM_Utils_System::isNull($groups)) {
|
||||
$campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
|
||||
foreach ($campGroups as $id => $title) {
|
||||
$this->_formValues['group'][$id] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//carry servey id w/ this.
|
||||
$this->set('surveyId', $this->_formValues['campaign_survey_id']);
|
||||
unset($this->_formValues['campaign_survey_id']);
|
||||
}
|
||||
unset($this->_formValues['survey_interviewer_id']);
|
||||
}
|
||||
elseif ($this->_operation == 'interview' ||
|
||||
$this->_operation == 'release'
|
||||
) {
|
||||
//to conduct interview / release activity status should be scheduled.
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
if ($scheduledStatusId = array_search('Scheduled', $activityStatus)) {
|
||||
$this->_formValues['survey_status_id'] = $scheduledStatusId;
|
||||
}
|
||||
}
|
||||
|
||||
//pass voter search operation.
|
||||
$this->_formValues['campaign_search_voter_for'] = $this->_operation;
|
||||
}
|
||||
|
||||
public function fixFormValues() {
|
||||
// if this search has been forced
|
||||
// then see if there are any get values, and if so over-ride the post values
|
||||
// note that this means that GET over-rides POST :)
|
||||
|
||||
//since we have qfKey, no need to manipulate set defaults.
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String');
|
||||
|
||||
if (!$this->_force || CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get survey id
|
||||
$surveyId = CRM_Utils_Request::retrieve('sid', 'Positive');
|
||||
|
||||
if ($surveyId) {
|
||||
$surveyId = CRM_Utils_Type::escape($surveyId, 'Integer');
|
||||
}
|
||||
else {
|
||||
// use default survey id
|
||||
$surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE));
|
||||
}
|
||||
if (!$surveyId) {
|
||||
CRM_Core_Error::fatal('Could not find valid Survey Id.');
|
||||
}
|
||||
$this->_formValues['campaign_survey_id'] = $this->_formValues['campaign_survey_id'] = $surveyId;
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$userId = $session->get('userID');
|
||||
|
||||
// get interviewer id
|
||||
$cid = CRM_Utils_Request::retrieve('cid', 'Positive',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, $userId
|
||||
);
|
||||
//to force other contact as interviewer, user should be admin.
|
||||
if ($cid != $userId &&
|
||||
!CRM_Core_Permission::check('administer CiviCampaign')
|
||||
) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$this->_formValues['survey_interviewer_id'] = $cid;
|
||||
//get all in defaults.
|
||||
$this->_defaults = $this->_formValues;
|
||||
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function voterClause() {
|
||||
$params = array('campaign_search_voter_for' => $this->_operation);
|
||||
|
||||
$clauseFields = array(
|
||||
'surveyId' => 'campaign_survey_id',
|
||||
'interviewerId' => 'survey_interviewer_id',
|
||||
);
|
||||
|
||||
foreach ($clauseFields as $param => $key) {
|
||||
$params[$key] = CRM_Utils_Array::value($key, $this->_formValues);
|
||||
if (!$params[$key]) {
|
||||
$params[$key] = $this->get($param);
|
||||
}
|
||||
}
|
||||
|
||||
//build the clause.
|
||||
$voterClause = CRM_Campaign_BAO_Query::voterClause($params);
|
||||
|
||||
return $voterClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Find Respondents');
|
||||
}
|
||||
|
||||
}
|
130
sites/all/modules/civicrm/CRM/Campaign/Form/Search/Campaign.php
Normal file
130
sites/all/modules/civicrm/CRM/Campaign/Form/Search/Campaign.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required.
|
||||
*/
|
||||
class CRM_Campaign_Form_Search_Campaign extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Are we forced to run a search.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_force;
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_search = CRM_Utils_Array::value('search', $_GET);
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
|
||||
$this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'campaign');
|
||||
|
||||
//when we do load tab, lets load the default objects.
|
||||
$this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
|
||||
$this->assign('searchParams', json_encode($this->get('searchParams')));
|
||||
$this->assign('buildSelector', $this->_search);
|
||||
$this->assign('searchFor', $this->_searchTab);
|
||||
$this->assign('campaignTypes', json_encode($this->get('campaignTypes')));
|
||||
$this->assign('campaignStatus', json_encode($this->get('campaignStatus')));
|
||||
$this->assign('suppressForm', TRUE);
|
||||
|
||||
//set the form title.
|
||||
CRM_Utils_System::setTitle(ts('Find Campaigns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_search) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign');
|
||||
$this->add('text', 'campaign_title', ts('Title'), $attributes['title']);
|
||||
|
||||
//campaign description.
|
||||
$this->add('text', 'description', ts('Description'), $attributes['description']);
|
||||
|
||||
//campaign start date.
|
||||
$this->addDate('start_date', ts('From'), FALSE, array('formatType' => 'searchDate'));
|
||||
|
||||
//campaign end date.
|
||||
$this->addDate('end_date', ts('To'), FALSE, array('formatType' => 'searchDate'));
|
||||
|
||||
//campaign type.
|
||||
$campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
|
||||
$this->add('select', 'campaign_type_id', ts('Campaign Type'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $campaignTypes
|
||||
);
|
||||
|
||||
$this->set('campaignTypes', $campaignTypes);
|
||||
$this->assign('campaignTypes', json_encode($campaignTypes));
|
||||
|
||||
//campaign status
|
||||
$campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus();
|
||||
$this->addElement('select', 'status_id', ts('Campaign Status'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $campaignStatus
|
||||
);
|
||||
$this->set('campaignStatus', $campaignStatus);
|
||||
$this->assign('campaignStatus', json_encode($campaignStatus));
|
||||
|
||||
//active campaigns
|
||||
$this->addElement('select', 'is_active', ts('Is Active?'), array(
|
||||
'' => ts('- select -'),
|
||||
'0' => ts('Yes'),
|
||||
'1' => ts('No'),
|
||||
)
|
||||
);
|
||||
|
||||
//build the array of all search params.
|
||||
$this->_searchParams = array();
|
||||
foreach ($this->_elements as $element) {
|
||||
$name = $element->_attributes['name'];
|
||||
$label = $element->_label;
|
||||
if ($name == 'qfKey') {
|
||||
continue;
|
||||
}
|
||||
$this->_searchParams[$name] = ($label) ? $label : $name;
|
||||
}
|
||||
$this->set('searchParams', $this->_searchParams);
|
||||
$this->assign('searchParams', json_encode($this->_searchParams));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required.
|
||||
*/
|
||||
class CRM_Campaign_Form_Search_Petition extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Are we forced to run a search.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_force;
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_search = CRM_Utils_Array::value('search', $_GET);
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
|
||||
$this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'petition');
|
||||
|
||||
//when we do load tab, lets load the default objects.
|
||||
$this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
|
||||
$this->assign('searchParams', json_encode($this->get('searchParams')));
|
||||
$this->assign('buildSelector', $this->_search);
|
||||
$this->assign('searchFor', $this->_searchTab);
|
||||
$this->assign('petitionCampaigns', json_encode($this->get('petitionCampaigns')));
|
||||
$this->assign('suppressForm', TRUE);
|
||||
|
||||
//set the form title.
|
||||
CRM_Utils_System::setTitle(ts('Find Petition'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_search) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey');
|
||||
$this->add('text', 'petition_title', ts('Title'), $attributes['title']);
|
||||
|
||||
//campaigns
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
|
||||
$this->add('select', 'petition_campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns);
|
||||
$this->set('petitionCampaigns', $campaigns);
|
||||
$this->assign('petitionCampaigns', json_encode($campaigns));
|
||||
|
||||
//build the array of all search params.
|
||||
$this->_searchParams = array();
|
||||
foreach ($this->_elements as $element) {
|
||||
$name = $element->_attributes['name'];
|
||||
$label = $element->_label;
|
||||
if ($name == 'qfKey') {
|
||||
continue;
|
||||
}
|
||||
$this->_searchParams[$name] = ($label) ? $label : $name;
|
||||
}
|
||||
$this->set('searchParams', $this->_searchParams);
|
||||
$this->assign('searchParams', json_encode($this->_searchParams));
|
||||
}
|
||||
|
||||
}
|
108
sites/all/modules/civicrm/CRM/Campaign/Form/Search/Survey.php
Normal file
108
sites/all/modules/civicrm/CRM/Campaign/Form/Search/Survey.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Files required.
|
||||
*/
|
||||
class CRM_Campaign_Form_Search_Survey extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Are we forced to run a search.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_force;
|
||||
|
||||
/**
|
||||
* Processing needed for buildForm and later.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_search = CRM_Utils_Array::value('search', $_GET);
|
||||
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE, FALSE);
|
||||
$this->_searchTab = CRM_Utils_Request::retrieve('type', 'String', $this, FALSE, 'survey');
|
||||
|
||||
//when we do load tab, lets load the default objects.
|
||||
$this->assign('force', ($this->_force || $this->_searchTab) ? TRUE : FALSE);
|
||||
$this->assign('searchParams', json_encode($this->get('searchParams')));
|
||||
$this->assign('buildSelector', $this->_search);
|
||||
$this->assign('searchFor', $this->_searchTab);
|
||||
$this->assign('surveyTypes', json_encode($this->get('surveyTypes')));
|
||||
$this->assign('surveyCampaigns', json_encode($this->get('surveyCampaigns')));
|
||||
$this->assign('suppressForm', TRUE);
|
||||
|
||||
//set the form title.
|
||||
CRM_Utils_System::setTitle(ts('Find Survey'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_search) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey');
|
||||
$this->add('text', 'survey_title', ts('Title'), $attributes['title']);
|
||||
|
||||
//activity Type id
|
||||
$surveyTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType();
|
||||
$this->add('select', 'activity_type_id',
|
||||
ts('Activity Type'), array(
|
||||
'' => ts('- select -'),
|
||||
) + $surveyTypes
|
||||
);
|
||||
$this->set('surveyTypes', $surveyTypes);
|
||||
$this->assign('surveyTypes', json_encode($surveyTypes));
|
||||
|
||||
//campaigns
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
|
||||
$this->add('select', 'survey_campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns);
|
||||
$this->set('surveyCampaigns', $campaigns);
|
||||
$this->assign('surveyCampaigns', json_encode($campaigns));
|
||||
|
||||
//build the array of all search params.
|
||||
$this->_searchParams = array();
|
||||
foreach ($this->_elements as $element) {
|
||||
$name = $element->_attributes['name'];
|
||||
$label = $element->_label;
|
||||
if ($name == 'qfKey') {
|
||||
continue;
|
||||
}
|
||||
$this->_searchParams[$name] = ($label) ? $label : $name;
|
||||
}
|
||||
$this->set('searchParams', $this->_searchParams);
|
||||
$this->assign('searchParams', json_encode($this->_searchParams));
|
||||
}
|
||||
|
||||
}
|
188
sites/all/modules/civicrm/CRM/Campaign/Form/Survey.php
Normal file
188
sites/all/modules/civicrm/CRM/Campaign/Form/Survey.php
Normal file
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a survey.
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the object being edited.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_surveyId;
|
||||
|
||||
/**
|
||||
* Action.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* SurveyTitle.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_surveyTitle;
|
||||
|
||||
public function preProcess() {
|
||||
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
|
||||
|
||||
if ($this->_surveyId) {
|
||||
$this->_single = TRUE;
|
||||
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo);
|
||||
$this->_surveyTitle = $surveyInfo['title'];
|
||||
$this->assign('surveyTitle', $this->_surveyTitle);
|
||||
CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle)));
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('surveyId', $this->_surveyId);
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
$this->set('type', 'Survey');
|
||||
$this->set('entityId', $this->_surveyId);
|
||||
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
CRM_Custom_Form_CustomData::setDefaultValues($this);
|
||||
}
|
||||
|
||||
// CRM-11480, CRM-11682
|
||||
// Preload libraries required by the "Questions" tab
|
||||
CRM_UF_Page_ProfileEditor::registerProfileScripts();
|
||||
CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel'));
|
||||
|
||||
CRM_Campaign_Form_Survey_TabHeader::build($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
if ($this->_surveyId) {
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and Done'),
|
||||
'subName' => 'done',
|
||||
),
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save and Next'),
|
||||
'spacing' => ' ',
|
||||
'subName' => 'next',
|
||||
),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Continue'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
$buttons[] = array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
$this->addButtons($buttons);
|
||||
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
$session->replaceUserContext($url);
|
||||
}
|
||||
|
||||
public function endPostProcess() {
|
||||
// make submit buttons keep the current working tab opened.
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
|
||||
$tabTitle = $className = CRM_Utils_String::getClassName($this->_name);
|
||||
if ($tabTitle == 'Main') {
|
||||
$tabTitle = 'Main settings';
|
||||
}
|
||||
$subPage = strtolower($className);
|
||||
CRM_Core_Session::setStatus(ts("'%1' have been saved.", array(1 => $tabTitle)), ts('Saved'), 'success');
|
||||
|
||||
$this->postProcessHook();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::ADD) {
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/questions",
|
||||
"action=update&reset=1&id={$this->_surveyId}"));
|
||||
}
|
||||
if ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_done") {
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
|
||||
}
|
||||
elseif ($this->controller->getButtonName('submit') == "_qf_{$className}_upload_next") {
|
||||
$subPage = CRM_Campaign_Form_Survey_TabHeader::getNextTab($this);
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}",
|
||||
"action=update&reset=1&id={$this->_surveyId}"));
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url("civicrm/survey/configure/{$subPage}",
|
||||
"action=update&reset=1&id={$this->_surveyId}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
if ($this->controller->getPrint() || $this->getVar('_surveyId') <= 0) {
|
||||
return parent::getTemplateFileName();
|
||||
}
|
||||
else {
|
||||
// hack lets suppress the form rendering for now
|
||||
self::$_template->assign('isForm', FALSE);
|
||||
return 'CRM/Campaign/Form/Survey/Tab.tpl';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
102
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Delete.php
Normal file
102
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Delete.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is to build the form for deleting a Survey.
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey_Delete extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The id of the object being deleted
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_surveyId;
|
||||
|
||||
/**
|
||||
* SurveyTitle
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_surveyTitle;
|
||||
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo);
|
||||
$this->_surveyTitle = $surveyInfo['title'];
|
||||
$this->assign('surveyTitle', $this->_surveyTitle);
|
||||
CRM_Utils_System::setTitle(ts('Delete Survey') . ' - ' . $this->_surveyTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form when submitted.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_surveyId) {
|
||||
CRM_Campaign_BAO_Survey::del($this->_surveyId);
|
||||
CRM_Core_Session::setStatus('', ts("'%1' survey has been deleted.", array(1 => $this->_surveyTitle)), 'success');
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal(ts('Delete action is missing expected survey ID.'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
224
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Main.php
Normal file
224
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Main.php
Normal file
|
@ -0,0 +1,224 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a survey.
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
|
||||
|
||||
/* values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
||||
public $_values;
|
||||
|
||||
/**
|
||||
* Context.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context;
|
||||
|
||||
/**
|
||||
* Explicitly declare the entity api name.
|
||||
*/
|
||||
public function getDefaultEntity() {
|
||||
return 'Survey';
|
||||
}
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
|
||||
|
||||
if ($this->_action & CRM_Core_Action::UPDATE) {
|
||||
CRM_Utils_System::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle);
|
||||
}
|
||||
|
||||
// when custom data is included in this page
|
||||
if (!empty($_POST['hidden_custom'])) {
|
||||
CRM_Custom_Form_CustomData::preProcess($this);
|
||||
CRM_Custom_Form_CustomData::buildQuickForm($this);
|
||||
}
|
||||
|
||||
if ($this->_name != 'Petition') {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey Dashboard'), 'url' => $url)));
|
||||
}
|
||||
|
||||
$this->_values = $this->get('values');
|
||||
if (!is_array($this->_values)) {
|
||||
$this->_values = array();
|
||||
if ($this->_surveyId) {
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->_values);
|
||||
}
|
||||
$this->set('values', $this->_values);
|
||||
}
|
||||
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('surveyId', $this->_surveyId);
|
||||
// for custom data
|
||||
$this->assign('entityID', $this->_surveyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
|
||||
$defaults = $this->_values;
|
||||
|
||||
if ($this->_surveyId) {
|
||||
|
||||
if (!empty($defaults['result_id']) && !empty($defaults['recontact_interval'])) {
|
||||
|
||||
$resultId = $defaults['result_id'];
|
||||
$recontactInterval = unserialize($defaults['recontact_interval']);
|
||||
|
||||
unset($defaults['recontact_interval']);
|
||||
$defaults['option_group_id'] = $resultId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($defaults['is_active'])) {
|
||||
$defaults['is_active'] = 1;
|
||||
}
|
||||
|
||||
$defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE);
|
||||
if (!isset($defaults['is_default']) && empty($defaultSurveys)) {
|
||||
$defaults['is_default'] = 1;
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'title'), TRUE);
|
||||
|
||||
$surveyActivityTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType();
|
||||
// Activity Type id
|
||||
$this->addSelect('activity_type_id', array('option_url' => 'civicrm/admin/campaign/surveyType'), TRUE);
|
||||
|
||||
// Campaign id
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('campaign_id', $this->_values));
|
||||
$this->add('select', 'campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns);
|
||||
|
||||
// script / instructions
|
||||
$this->add('wysiwyg', 'instructions', ts('Instructions for interviewers'), array('rows' => 5, 'cols' => 40));
|
||||
|
||||
// release frequency
|
||||
$this->add('text', 'release_frequency', ts('Release Frequency'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'release_frequency'));
|
||||
|
||||
$this->addRule('release_frequency', ts('Release Frequency interval should be a positive number.'), 'positiveInteger');
|
||||
|
||||
// max reserved contacts at a time
|
||||
$this->add('text', 'default_number_of_contacts', ts('Maximum reserved at one time'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'default_number_of_contacts'));
|
||||
$this->addRule('default_number_of_contacts', ts('Maximum reserved at one time should be a positive number'), 'positiveInteger');
|
||||
|
||||
// total reserved per interviewer
|
||||
$this->add('text', 'max_number_of_contacts', ts('Total reserved per interviewer'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'max_number_of_contacts'));
|
||||
$this->addRule('max_number_of_contacts', ts('Total reserved contacts should be a positive number'), 'positiveInteger');
|
||||
|
||||
// is active ?
|
||||
$this->add('checkbox', 'is_active', ts('Active?'));
|
||||
|
||||
// is default ?
|
||||
$this->add('checkbox', 'is_default', ts('Default?'));
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
|
||||
$params['last_modified_id'] = $session->get('userID');
|
||||
$params['last_modified_date'] = date('YmdHis');
|
||||
|
||||
if ($this->_surveyId) {
|
||||
$params['id'] = $this->_surveyId;
|
||||
}
|
||||
else {
|
||||
$params['created_id'] = $session->get('userID');
|
||||
$params['created_date'] = date('YmdHis');
|
||||
}
|
||||
|
||||
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
|
||||
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
|
||||
|
||||
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
$this->_surveyId,
|
||||
'Survey'
|
||||
);
|
||||
$survey = CRM_Campaign_BAO_Survey::create($params);
|
||||
$this->_surveyId = $survey->id;
|
||||
|
||||
if (!empty($this->_values['result_id'])) {
|
||||
$query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
|
||||
$countSurvey = (int) CRM_Core_DAO::singleValueQuery($query,
|
||||
array(
|
||||
1 => array(
|
||||
$this->_values['result_id'],
|
||||
'Positive',
|
||||
),
|
||||
)
|
||||
);
|
||||
// delete option group if no any survey is using it.
|
||||
if (!$countSurvey) {
|
||||
CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
|
||||
}
|
||||
}
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
}
|
140
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Questions.php
Normal file
140
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Questions.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a survey.
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey_Questions extends CRM_Campaign_Form_Survey {
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$ufJoinParams = array(
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'module' => 'CiviCampaign',
|
||||
'entity_id' => $this->_surveyId,
|
||||
);
|
||||
|
||||
list($defaults['contact_profile_id'], $second)
|
||||
= CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
|
||||
$defaults['activity_profile_id'] = $second ? array_shift($second) : '';
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$subTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'activity_type_id');
|
||||
if (!CRM_Core_BAO_CustomGroup::autoCreateByActivityType($subTypeId)) {
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, FALSE); // everything
|
||||
// FIXME: Displays weird "/\ Array" message; doesn't work with tabs
|
||||
CRM_Core_Session::setStatus(
|
||||
ts(
|
||||
'There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.',
|
||||
array(
|
||||
1 => $activityTypes[$subTypeId],
|
||||
2 => CRM_Utils_System::url('civicrm/admin/custom/group', 'action=add&reset=1'),
|
||||
3 => '_blank',
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$allowCoreTypes = CRM_Campaign_BAO_Survey::surveyProfileTypes();
|
||||
$allowSubTypes = array(
|
||||
'ActivityType' => array($subTypeId),
|
||||
);
|
||||
$entities = array(
|
||||
array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'),
|
||||
array('entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId),
|
||||
);
|
||||
$this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities);
|
||||
$this->addProfileSelector('activity_profile_id', ts('Questions'), $allowCoreTypes, $allowSubTypes, $entities);
|
||||
// Note: Because this is in a tab, we also preload the schema via CRM_Campaign_Form_Survey::preProcess
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
// also update the ProfileModule tables
|
||||
$ufJoinParams = array(
|
||||
'is_active' => 1,
|
||||
'module' => 'CiviCampaign',
|
||||
'entity_table' => 'civicrm_survey',
|
||||
'entity_id' => $this->_surveyId,
|
||||
);
|
||||
|
||||
// first delete all past entries
|
||||
CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
|
||||
|
||||
$uf = array();
|
||||
$wt = 2;
|
||||
if (!empty($params['contact_profile_id'])) {
|
||||
$uf[1] = $params['contact_profile_id'];
|
||||
$wt = 1;
|
||||
}
|
||||
if (!empty($params['activity_profile_id'])) {
|
||||
$uf[2] = $params['activity_profile_id'];
|
||||
}
|
||||
|
||||
$uf = array_values($uf);
|
||||
if (!empty($uf)) {
|
||||
foreach ($uf as $weight => $ufGroupId) {
|
||||
$ufJoinParams['weight'] = $weight + $wt;
|
||||
$ufJoinParams['uf_group_id'] = $ufGroupId;
|
||||
CRM_Core_BAO_UFJoin::create($ufJoinParams);
|
||||
unset($ufJoinParams['id']);
|
||||
}
|
||||
}
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
}
|
503
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Results.php
Normal file
503
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/Results.php
Normal file
|
@ -0,0 +1,503 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a survey.
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey_Results extends CRM_Campaign_Form_Survey {
|
||||
|
||||
protected $_reportId;
|
||||
|
||||
protected $_reportTitle;
|
||||
|
||||
/* values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_values;
|
||||
|
||||
const NUM_OPTION = 11;
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
$this->_values = $this->get('values');
|
||||
if (!is_array($this->_values)) {
|
||||
$this->_values = array();
|
||||
if ($this->_surveyId) {
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->_values);
|
||||
}
|
||||
$this->set('values', $this->_values);
|
||||
}
|
||||
|
||||
$query = "SELECT MAX(id) as id, title FROM civicrm_report_instance WHERE name = %1 GROUP BY id";
|
||||
$params = array(1 => array("survey_{$this->_surveyId}", 'String'));
|
||||
$result = CRM_Core_DAO::executeQuery($query, $params);
|
||||
if ($result->fetch()) {
|
||||
$this->_reportId = $result->id;
|
||||
$this->_reportTitle = $result->title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
* Note that in edit/view mode the default values are retrieved from the database.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = $this->_values;
|
||||
|
||||
// set defaults for weight.
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
$defaults["option_weight[{$i}]"] = $i;
|
||||
}
|
||||
|
||||
$defaults['create_report'] = 1;
|
||||
if ($this->_reportId) {
|
||||
$defaults['report_title'] = $this->_reportTitle;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$optionGroups = CRM_Campaign_BAO_Survey::getResultSets();
|
||||
|
||||
if (empty($optionGroups)) {
|
||||
$optionTypes = array('1' => ts('Create new result set'));
|
||||
}
|
||||
else {
|
||||
$optionTypes = array(
|
||||
'1' => ts('Create new result set'),
|
||||
'2' => ts('Use existing result set'),
|
||||
);
|
||||
$this->add('select',
|
||||
'option_group_id',
|
||||
ts('Select Result Set'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) + $optionGroups, FALSE,
|
||||
array('onChange' => 'loadOptionGroup( )')
|
||||
);
|
||||
}
|
||||
|
||||
$element = &$this->addRadio('option_type',
|
||||
ts('Survey Responses'),
|
||||
$optionTypes,
|
||||
array(
|
||||
'onclick' => "showOptionSelect();",
|
||||
), '<br/>', TRUE
|
||||
);
|
||||
|
||||
if (empty($optionGroups) || empty($this->_values['result_id'])) {
|
||||
$this->setdefaults(array('option_type' => 1));
|
||||
}
|
||||
elseif (!empty($this->_values['result_id'])) {
|
||||
$this->setdefaults(array(
|
||||
'option_type' => 2,
|
||||
'option_group_id' => $this->_values['result_id'],
|
||||
));
|
||||
}
|
||||
|
||||
// form fields of Custom Option rows
|
||||
$defaultOption = array();
|
||||
$_showHide = new CRM_Core_ShowHideBlocks('', '');
|
||||
|
||||
$optionAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue');
|
||||
$optionAttributes['label']['size'] = $optionAttributes['value']['size'] = 25;
|
||||
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
//the show hide blocks
|
||||
$showBlocks = 'optionField_' . $i;
|
||||
if ($i > 2) {
|
||||
$_showHide->addHide($showBlocks);
|
||||
if ($i == self::NUM_OPTION) {
|
||||
$_showHide->addHide('additionalOption');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$_showHide->addShow($showBlocks);
|
||||
}
|
||||
|
||||
$this->add('text', 'option_label[' . $i . ']', ts('Label'),
|
||||
$optionAttributes['label']
|
||||
);
|
||||
|
||||
// value
|
||||
$this->add('text', 'option_value[' . $i . ']', ts('Value'),
|
||||
$optionAttributes['value']
|
||||
);
|
||||
|
||||
// weight
|
||||
$this->add('text', "option_weight[$i]", ts('Order'),
|
||||
$optionAttributes['weight']
|
||||
);
|
||||
|
||||
$this->add('text', 'option_interval[' . $i .
|
||||
']', ts('Recontact Interval'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'release_frequency')
|
||||
);
|
||||
|
||||
$defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
|
||||
}
|
||||
|
||||
//default option selection
|
||||
$this->addGroup($defaultOption, 'default_option');
|
||||
|
||||
$_showHide->addToTemplate();
|
||||
|
||||
$this->addElement('checkbox', 'create_report', ts('Create Report'));
|
||||
$this->addElement('text', 'report_title', ts('Report Title'));
|
||||
|
||||
if ($this->_reportId) {
|
||||
$this->freeze('create_report');
|
||||
$this->freeze('report_title');
|
||||
}
|
||||
|
||||
$this->addFormRule(array(
|
||||
'CRM_Campaign_Form_Survey_Results',
|
||||
'formRule',
|
||||
), $this);
|
||||
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param $fields
|
||||
* @param $files
|
||||
* @param $form
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
$errors = array();
|
||||
if (!empty($fields['option_label']) && !empty($fields['option_value']) &&
|
||||
(count(array_filter($fields['option_label'])) == 0) &&
|
||||
(count(array_filter($fields['option_value'])) == 0)
|
||||
) {
|
||||
$errors['option_label[1]'] = ts('Enter at least one result option.');
|
||||
return $errors;
|
||||
}
|
||||
elseif (empty($fields['option_label']) && empty($fields['option_value'])) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if (
|
||||
$fields['option_type'] == 2 && empty($fields['option_group_id'])
|
||||
) {
|
||||
$errors['option_group_id'] = ts("Please select a Survey Result Set.");
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$_flagOption = $_rowError = 0;
|
||||
$_showHide = new CRM_Core_ShowHideBlocks('', '');
|
||||
|
||||
//capture duplicate Custom option values
|
||||
if (!empty($fields['option_value'])) {
|
||||
$countValue = count($fields['option_value']);
|
||||
$uniqueCount = count(array_unique($fields['option_value']));
|
||||
|
||||
if ($countValue > $uniqueCount) {
|
||||
$start = 1;
|
||||
while ($start < self::NUM_OPTION) {
|
||||
$nextIndex = $start + 1;
|
||||
|
||||
while ($nextIndex <= self::NUM_OPTION) {
|
||||
if ($fields['option_value'][$start] ==
|
||||
$fields['option_value'][$nextIndex] &&
|
||||
!empty($fields['option_value'][$nextIndex])
|
||||
) {
|
||||
|
||||
$errors['option_value[' . $start .
|
||||
']'] = ts('Duplicate Option values');
|
||||
$errors['option_value[' . $nextIndex .
|
||||
']'] = ts('Duplicate Option values');
|
||||
$_flagOption = 1;
|
||||
}
|
||||
$nextIndex++;
|
||||
}
|
||||
$start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//capture duplicate Custom Option label
|
||||
if (!empty($fields['option_label'])) {
|
||||
$countValue = count($fields['option_label']);
|
||||
$uniqueCount = count(array_unique($fields['option_label']));
|
||||
|
||||
if ($countValue > $uniqueCount) {
|
||||
$start = 1;
|
||||
while ($start < self::NUM_OPTION) {
|
||||
$nextIndex = $start + 1;
|
||||
|
||||
while ($nextIndex <= self::NUM_OPTION) {
|
||||
if ($fields['option_label'][$start] ==
|
||||
$fields['option_label'][$nextIndex] &&
|
||||
!empty($fields['option_label'][$nextIndex])
|
||||
) {
|
||||
$errors['option_label[' . $start .
|
||||
']'] = ts('Duplicate Option label');
|
||||
$errors['option_label[' . $nextIndex .
|
||||
']'] = ts('Duplicate Option label');
|
||||
$_flagOption = 1;
|
||||
}
|
||||
$nextIndex++;
|
||||
}
|
||||
$start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
|
||||
if (!$fields['option_label'][$i]) {
|
||||
if ($fields['option_value'][$i]) {
|
||||
$errors['option_label[' . $i .
|
||||
']'] = ts('Option label cannot be empty');
|
||||
$_flagOption = 1;
|
||||
}
|
||||
else {
|
||||
$_emptyRow = 1;
|
||||
}
|
||||
}
|
||||
elseif (!strlen(trim($fields['option_value'][$i]))) {
|
||||
if (!$fields['option_value'][$i]) {
|
||||
$errors['option_value[' . $i .
|
||||
']'] = ts('Option value cannot be empty');
|
||||
$_flagOption = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($fields['option_interval'][$i]) &&
|
||||
!CRM_Utils_Rule::integer($fields['option_interval'][$i])
|
||||
) {
|
||||
$_flagOption = 1;
|
||||
$errors['option_interval[' . $i .
|
||||
']'] = ts('Please enter a valid integer.');
|
||||
}
|
||||
|
||||
$showBlocks = 'optionField_' . $i;
|
||||
if ($_flagOption) {
|
||||
$_showHide->addShow($showBlocks);
|
||||
$_rowError = 1;
|
||||
}
|
||||
|
||||
if (!empty($_emptyRow)) {
|
||||
$_showHide->addHide($showBlocks);
|
||||
}
|
||||
else {
|
||||
$_showHide->addShow($showBlocks);
|
||||
}
|
||||
|
||||
if ($i == self::NUM_OPTION) {
|
||||
$hideBlock = 'additionalOption';
|
||||
$_showHide->addHide($hideBlock);
|
||||
}
|
||||
|
||||
$_flagOption = $_emptyRow = 0;
|
||||
}
|
||||
$_showHide->addToTemplate();
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// store the submitted values in an array
|
||||
$status = '';
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$params['id'] = $this->_surveyId;
|
||||
|
||||
$updateResultSet = FALSE;
|
||||
$resultSetOptGrpId = NULL;
|
||||
if ((CRM_Utils_Array::value('option_type', $params) == 2) &&
|
||||
!empty($params['option_group_id'])
|
||||
) {
|
||||
$updateResultSet = TRUE;
|
||||
$resultSetOptGrpId = $params['option_group_id'];
|
||||
}
|
||||
|
||||
$recontactInterval = array();
|
||||
if ($updateResultSet) {
|
||||
$optionValue = new CRM_Core_DAO_OptionValue();
|
||||
$optionValue->option_group_id = $resultSetOptGrpId;
|
||||
$optionValue->delete();
|
||||
|
||||
$params['result_id'] = $resultSetOptGrpId;
|
||||
}
|
||||
else {
|
||||
$opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
|
||||
|
||||
$optionGroup = new CRM_Core_DAO_OptionGroup();
|
||||
$optionGroup->name = $opGroupName;
|
||||
$optionGroup->title = $this->_values['title'] . ' Result Set';
|
||||
$optionGroup->is_active = 1;
|
||||
$optionGroup->save();
|
||||
|
||||
$params['result_id'] = $optionGroup->id;
|
||||
}
|
||||
|
||||
foreach ($params['option_value'] as $k => $v) {
|
||||
if (strlen(trim($v))) {
|
||||
$optionValue = new CRM_Core_DAO_OptionValue();
|
||||
$optionValue->option_group_id = $params['result_id'];
|
||||
$optionValue->label = $params['option_label'][$k];
|
||||
$optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
|
||||
$optionValue->value = trim($v);
|
||||
$optionValue->weight = $params['option_weight'][$k];
|
||||
$optionValue->is_active = 1;
|
||||
|
||||
if (!empty($params['default_option']) &&
|
||||
$params['default_option'] == $k
|
||||
) {
|
||||
$optionValue->is_default = 1;
|
||||
}
|
||||
|
||||
$optionValue->save();
|
||||
|
||||
// using is_numeric since 0 is a valid value for option_interval
|
||||
if (is_numeric($params['option_interval'][$k])) {
|
||||
$recontactInterval[$optionValue->label] = $params['option_interval'][$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$params['recontact_interval'] = serialize($recontactInterval);
|
||||
$survey = CRM_Campaign_BAO_Survey::create($params);
|
||||
|
||||
// create report if required.
|
||||
if (!$this->_reportId && $survey->id && !empty($params['create_report'])) {
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$activityStatus = array_flip($activityStatus);
|
||||
$this->_params = array(
|
||||
'name' => "survey_{$survey->id}",
|
||||
'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'],
|
||||
'status_id_op' => 'eq',
|
||||
'status_id_value' => $activityStatus['Scheduled'], // reserved status
|
||||
'survey_id_value' => array($survey->id),
|
||||
'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.'),
|
||||
);
|
||||
//Default value of order by
|
||||
$this->_params['order_bys'] = array(
|
||||
1 => array(
|
||||
'column' => 'sort_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
);
|
||||
// for WalkList or default
|
||||
$displayFields = array(
|
||||
'id',
|
||||
'sort_name',
|
||||
'result',
|
||||
'street_number',
|
||||
'street_name',
|
||||
'street_unit',
|
||||
'survey_response',
|
||||
);
|
||||
if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') ==
|
||||
$this->_values['activity_type_id']
|
||||
) {
|
||||
$this->_params['order_bys'] = array(
|
||||
1 => array(
|
||||
'column' => 'street_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
2 => array(
|
||||
'column' => 'street_number_odd_even',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
3 => array(
|
||||
'column' => 'street_number',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
4 => array(
|
||||
'column' => 'sort_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
);
|
||||
}
|
||||
elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') ==
|
||||
$this->_values['activity_type_id']
|
||||
) {
|
||||
array_push($displayFields, 'phone');
|
||||
}
|
||||
elseif ((CRM_Core_OptionGroup::getValue('activity_type', 'Survey') ==
|
||||
$this->_values['activity_type_id']) ||
|
||||
(CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') ==
|
||||
$this->_values['activity_type_id'])
|
||||
) {
|
||||
array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email');
|
||||
}
|
||||
foreach ($displayFields as $key) {
|
||||
$this->_params['fields'][$key] = 1;
|
||||
}
|
||||
$this->_createNew = TRUE;
|
||||
$this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail');
|
||||
CRM_Report_Form_Instance::postProcess($this, FALSE);
|
||||
|
||||
$query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1";
|
||||
$reportID = CRM_Core_DAO::singleValueQuery($query, array(
|
||||
1 => array(
|
||||
"survey_{$survey->id}",
|
||||
'String',
|
||||
),
|
||||
));
|
||||
if ($reportID) {
|
||||
$url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
|
||||
$status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.",
|
||||
array(1 => $url, 2 => $this->_params['title']));
|
||||
}
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
// reset status as we don't want status set by Instance::postProcess
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->getStatus(TRUE);
|
||||
// set new status
|
||||
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
|
||||
}
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
}
|
189
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/TabHeader.php
Normal file
189
sites/all/modules/civicrm/CRM/Campaign/Form/Survey/TabHeader.php
Normal file
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class to build navigation links
|
||||
*/
|
||||
class CRM_Campaign_Form_Survey_TabHeader {
|
||||
|
||||
/**
|
||||
* Build tab header.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function build(&$form) {
|
||||
$tabs = $form->get('tabHeader');
|
||||
if (!$tabs || empty($_GET['reset'])) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
$form->assign_by_ref('tabHeader', $tabs);
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'tabSettings' => array(
|
||||
'active' => self::getCurrentTab($tabs),
|
||||
),
|
||||
));
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function process(&$form) {
|
||||
if ($form->getVar('_surveyId') <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$tabs = array(
|
||||
'main' => array(
|
||||
'title' => ts('Main Information'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'questions' => array(
|
||||
'title' => ts('Questions'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
'results' => array(
|
||||
'title' => ts('Results'),
|
||||
'link' => NULL,
|
||||
'valid' => FALSE,
|
||||
'active' => FALSE,
|
||||
'current' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
$surveyID = $form->getVar('_surveyId');
|
||||
$class = $form->getVar('_name');
|
||||
$class = CRM_Utils_String::getClassName($class);
|
||||
$class = strtolower($class);
|
||||
|
||||
if (array_key_exists($class, $tabs)) {
|
||||
$tabs[$class]['current'] = TRUE;
|
||||
$qfKey = $form->get('qfKey');
|
||||
if ($qfKey) {
|
||||
$tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
|
||||
}
|
||||
}
|
||||
|
||||
if ($surveyID) {
|
||||
$reset = !empty($_GET['reset']) ? 'reset=1&' : '';
|
||||
|
||||
foreach ($tabs as $key => $value) {
|
||||
if (!isset($tabs[$key]['qfKey'])) {
|
||||
$tabs[$key]['qfKey'] = NULL;
|
||||
}
|
||||
|
||||
$tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}",
|
||||
"{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}"
|
||||
);
|
||||
$tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
|
||||
}
|
||||
}
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CRM_Core_Form $form
|
||||
*/
|
||||
public static function reset(&$form) {
|
||||
$tabs = self::process($form);
|
||||
$form->set('tabHeader', $tabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tabs
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getCurrentTab($tabs) {
|
||||
static $current = FALSE;
|
||||
|
||||
if ($current) {
|
||||
return $current;
|
||||
}
|
||||
|
||||
if (is_array($tabs)) {
|
||||
foreach ($tabs as $subPage => $pageVal) {
|
||||
if ($pageVal['current'] === TRUE) {
|
||||
$current = $subPage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$current = $current ? $current : 'main';
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $form
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getNextTab(&$form) {
|
||||
static $next = FALSE;
|
||||
if ($next) {
|
||||
return $next;
|
||||
}
|
||||
|
||||
$tabs = $form->get('tabHeader');
|
||||
if (is_array($tabs)) {
|
||||
$current = FALSE;
|
||||
foreach ($tabs as $subPage => $pageVal) {
|
||||
if ($current) {
|
||||
$next = $subPage;
|
||||
break;
|
||||
}
|
||||
if ($pageVal['current'] === TRUE) {
|
||||
$current = $subPage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$next = $next ? $next : 'main';
|
||||
return $next;
|
||||
}
|
||||
|
||||
}
|
167
sites/all/modules/civicrm/CRM/Campaign/Form/SurveyType.php
Normal file
167
sites/all/modules/civicrm/CRM/Campaign/Form/SurveyType.php
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Option Group.
|
||||
*/
|
||||
class CRM_Campaign_Form_SurveyType extends CRM_Admin_Form {
|
||||
protected $_gid;
|
||||
|
||||
/**
|
||||
* The option group name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_gName;
|
||||
|
||||
/**
|
||||
* Id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* Action
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_action;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
|
||||
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
$this->assign('action', $this->_action);
|
||||
$this->assign('id', $this->_id);
|
||||
|
||||
$this->_BAOName = 'CRM_Core_BAO_OptionValue';
|
||||
$this->_gName = 'activity_type';
|
||||
$this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name');
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$url = CRM_Utils_System::url('civicrm/admin/campaign/surveyType', 'reset=1');
|
||||
$session->pushUserContext($url);
|
||||
|
||||
if ($this->_id && in_array($this->_gName, CRM_Core_OptionGroup::$_domainIDGroups)) {
|
||||
$domainID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'domain_id', 'id');
|
||||
if (CRM_Core_Config::domainID() != $domainID) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
* the default values are retrieved from the database.
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = parent::setDefaultValues();
|
||||
|
||||
if (!isset($defaults['weight']) || !$defaults['weight']) {
|
||||
$fieldValues = array('option_group_id' => $this->_gid);
|
||||
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
|
||||
}
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
parent::buildQuickForm();
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applyFilter('__ALL__', 'trim');
|
||||
$this->add('text', 'label', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE);
|
||||
|
||||
$this->add('wysiwyg', 'description',
|
||||
ts('Description'),
|
||||
CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'description')
|
||||
);
|
||||
|
||||
$this->add('checkbox', 'is_active', ts('Enabled?'));
|
||||
|
||||
if ($this->_action == CRM_Core_Action::UPDATE &&
|
||||
CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_id, 'is_reserved')
|
||||
) {
|
||||
$this->freeze(array('label', 'is_active'));
|
||||
}
|
||||
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'weight'), TRUE);
|
||||
|
||||
$this->assign('id', $this->_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$fieldValues = array('option_group_id' => $this->_gid);
|
||||
$wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
|
||||
|
||||
if (CRM_Core_BAO_OptionValue::del($this->_id)) {
|
||||
CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$params = $ids = array();
|
||||
$params = $this->exportValues();
|
||||
|
||||
// set db value of filter in params if filter is non editable
|
||||
if ($this->_id && !array_key_exists('filter', $params)) {
|
||||
$params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
|
||||
}
|
||||
|
||||
$groupParams = array('name' => ($this->_gName));
|
||||
$params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign');
|
||||
$optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
|
||||
|
||||
CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
153
sites/all/modules/civicrm/CRM/Campaign/Form/Task.php
Normal file
153
sites/all/modules/civicrm/CRM/Campaign/Form/Task.php
Normal file
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for relationship.
|
||||
*/
|
||||
class CRM_Campaign_Form_Task extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_componentClause = NULL;
|
||||
|
||||
/**
|
||||
* The task being performed
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* The array that holds all the contact ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_contactIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the component ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_componentIds;
|
||||
|
||||
/**
|
||||
* The array that holds all the voter ids
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_voterIds;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$values = $this->controller->exportValues('Search');
|
||||
|
||||
$this->_task = $values['task'];
|
||||
$campaignTasks = CRM_Campaign_Task::tasks();
|
||||
$taskName = CRM_Utils_Array::value($this->_task, $campaignTasks);
|
||||
$this->assign('taskName', $taskName);
|
||||
|
||||
$ids = array();
|
||||
if ($values['radio_ts'] == 'ts_sel') {
|
||||
foreach ($values as $name => $value) {
|
||||
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
|
||||
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
|
||||
$cacheKey = "civicrm search {$qfKey}";
|
||||
$allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall");
|
||||
$ids = array_keys($allCids[$cacheKey]);
|
||||
$this->assign('totalSelectedVoters', count($ids));
|
||||
}
|
||||
|
||||
if (!empty($ids)) {
|
||||
$this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) ';
|
||||
$this->assign('totalSelectedVoters', count($ids));
|
||||
}
|
||||
$this->_voterIds = $this->_contactIds = $this->_componentIds = $ids;
|
||||
|
||||
$this->assign('totalSelectedContacts', count($this->_contactIds));
|
||||
|
||||
//set the context for redirection for any task actions
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
|
||||
$urlParams = 'force=1';
|
||||
if (CRM_Utils_Rule::qfKey($qfKey)) {
|
||||
$urlParams .= '&qfKey=' . $qfKey;
|
||||
}
|
||||
$session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the voter id, compute the contact id
|
||||
* since its used for things like send email
|
||||
*/
|
||||
public function setContactIDs() {
|
||||
$this->_contactIds = $this->_voterIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple shell that derived classes can call to add buttons to.
|
||||
* the form with a customized title for the main Submit
|
||||
*
|
||||
* @param string $title
|
||||
* Title of the main button.
|
||||
* @param string $nextType
|
||||
* Button type for the form after processing.
|
||||
* @param string $backType
|
||||
* @param bool $submitOnce
|
||||
*/
|
||||
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => $nextType,
|
||||
'name' => $title,
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => $backType,
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
651
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Interview.php
Normal file
651
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Interview.php
Normal file
|
@ -0,0 +1,651 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to record voter's interview.
|
||||
*/
|
||||
class CRM_Campaign_Form_Task_Interview extends CRM_Campaign_Form_Task {
|
||||
|
||||
/**
|
||||
* The title of the group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_title;
|
||||
|
||||
/**
|
||||
* Variable to store redirect path
|
||||
*/
|
||||
private $_userContext;
|
||||
|
||||
private $_groupTree;
|
||||
|
||||
private $_surveyFields;
|
||||
|
||||
private $_surveyTypeId;
|
||||
|
||||
private $_interviewerId;
|
||||
|
||||
private $_surveyActivityIds;
|
||||
|
||||
private $_votingTab = FALSE;
|
||||
|
||||
private $_surveyValues;
|
||||
|
||||
private $_resultOptions;
|
||||
|
||||
private $_allowAjaxReleaseButton;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_votingTab = $this->get('votingTab');
|
||||
$this->_reserveToInterview = $this->get('reserveToInterview');
|
||||
if ($this->_reserveToInterview || $this->_votingTab) {
|
||||
//user came from voting tab / reserve form.
|
||||
foreach (array(
|
||||
'surveyId',
|
||||
'contactIds',
|
||||
'interviewerId',
|
||||
) as $fld) {
|
||||
$this->{"_$fld"} = $this->get($fld);
|
||||
}
|
||||
//get the target voter ids.
|
||||
if ($this->_votingTab) {
|
||||
$this->getVoterIds();
|
||||
}
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
//get the survey id from user submitted values.
|
||||
$this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues'));
|
||||
$this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues'));
|
||||
}
|
||||
|
||||
if ($this->_surveyId) {
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
|
||||
}
|
||||
|
||||
$orderClause = FALSE;
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) {
|
||||
$orderByParams = CRM_Utils_Array::value('order_bys', $_POST);
|
||||
}
|
||||
elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) {
|
||||
$orderByParams
|
||||
= array(
|
||||
1 => array(
|
||||
'column' => 'civicrm_address.street_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
2 => array(
|
||||
'column' => 'civicrm_address.street_number%2',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
3 => array(
|
||||
'column' => 'civicrm_address.street_number',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
4 => array(
|
||||
'column' => 'contact_a.sort_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$orderBy = array();
|
||||
if (!empty($orderByParams)) {
|
||||
foreach ($orderByParams as $key => $val) {
|
||||
if (!empty($val['column'])) {
|
||||
$orderBy[] = "{$val['column']} {$val['order']}";
|
||||
}
|
||||
}
|
||||
if (!empty($orderBy)) {
|
||||
$orderClause = "ORDER BY " . implode(', ', $orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_contactIds = array_unique($this->_contactIds);
|
||||
if (!empty($this->_contactIds) && $orderClause) {
|
||||
$clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) ';
|
||||
$sql = "
|
||||
SELECT contact_a.id
|
||||
FROM civicrm_contact contact_a
|
||||
LEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id
|
||||
WHERE {$clause}
|
||||
{$orderClause}";
|
||||
|
||||
$this->_contactIds = array();
|
||||
$dao = CRM_Core_DAO::executeQuery($sql);
|
||||
while ($dao->fetch()) {
|
||||
$this->_contactIds[] = $dao->id;
|
||||
}
|
||||
}
|
||||
|
||||
//get the contact read only fields to display.
|
||||
$readOnlyFields = array_merge(array(
|
||||
'contact_type' => '',
|
||||
'sort_name' => ts('Name'),
|
||||
));
|
||||
|
||||
//get the read only field data.
|
||||
$returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
|
||||
$returnProperties['contact_sub_type'] = TRUE;
|
||||
|
||||
//validate all voters for required activity.
|
||||
//get the survey activities for given voters.
|
||||
$this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId,
|
||||
$this->_contactIds,
|
||||
$this->_interviewerId
|
||||
);
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$scheduledStatusId = array_search('Scheduled', $activityStatus);
|
||||
|
||||
$activityIds = array();
|
||||
foreach ($this->_contactIds as $key => $voterId) {
|
||||
$actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds);
|
||||
$statusId = CRM_Utils_Array::value('status_id', $actVals);
|
||||
$activityId = CRM_Utils_Array::value('activity_id', $actVals);
|
||||
if ($activityId &&
|
||||
$statusId &&
|
||||
$scheduledStatusId == $statusId
|
||||
) {
|
||||
$activityIds["activity_id_{$voterId}"] = $activityId;
|
||||
}
|
||||
else {
|
||||
unset($this->_contactIds[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
//retrieve the contact details.
|
||||
$voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties);
|
||||
|
||||
$this->_allowAjaxReleaseButton = FALSE;
|
||||
if ($this->_votingTab &&
|
||||
(CRM_Core_Permission::check('manage campaign') ||
|
||||
CRM_Core_Permission::check('administer CiviCampaign') ||
|
||||
CRM_Core_Permission::check('release campaign contacts')
|
||||
)
|
||||
) {
|
||||
$this->_allowAjaxReleaseButton = TRUE;
|
||||
}
|
||||
|
||||
//validate voter ids across profile.
|
||||
$this->filterVoterIds();
|
||||
$this->assign('votingTab', $this->_votingTab);
|
||||
$this->assign('componentIds', $this->_contactIds);
|
||||
$this->assign('componentIdsJson', json_encode($this->_contactIds));
|
||||
$this->assign('voterDetails', $voterDetails);
|
||||
$this->assign('readOnlyFields', $readOnlyFields);
|
||||
$this->assign('interviewerId', $this->_interviewerId);
|
||||
$this->assign('surveyActivityIds', json_encode($activityIds));
|
||||
$this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton);
|
||||
|
||||
//get the survey values.
|
||||
$this->_surveyValues = $this->get('surveyValues');
|
||||
if (!is_array($this->_surveyValues)) {
|
||||
$this->_surveyValues = array();
|
||||
if ($this->_surveyId) {
|
||||
$surveyParams = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues);
|
||||
}
|
||||
$this->set('surveyValues', $this->_surveyValues);
|
||||
}
|
||||
$this->assign('surveyValues', $this->_surveyValues);
|
||||
|
||||
$result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId);
|
||||
$this->assign("instanceId", $result);
|
||||
|
||||
//get the survey result options.
|
||||
$this->_resultOptions = $this->get('resultOptions');
|
||||
if (!is_array($this->_resultOptions)) {
|
||||
$this->_resultOptions = array();
|
||||
if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) {
|
||||
$this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId);
|
||||
}
|
||||
$this->set('resultOptions', $this->_resultOptions);
|
||||
}
|
||||
|
||||
//validate the required ids.
|
||||
$this->validateIds();
|
||||
|
||||
//append breadcrumb to survey dashboard.
|
||||
if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
|
||||
}
|
||||
|
||||
//set the title.
|
||||
$activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
|
||||
$this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues);
|
||||
CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId])));
|
||||
}
|
||||
|
||||
public function validateIds() {
|
||||
$required = array(
|
||||
'surveyId' => ts('Could not find Survey.'),
|
||||
'interviewerId' => ts('Could not find Interviewer.'),
|
||||
'contactIds' => ts('No respondents are currently reserved for you to interview.'),
|
||||
'resultOptions' => ts('Oops. It looks like there is no response option configured.'),
|
||||
);
|
||||
|
||||
$errorMessages = array();
|
||||
foreach ($required as $fld => $msg) {
|
||||
if (empty($this->{"_$fld"})) {
|
||||
if (!$this->_votingTab) {
|
||||
CRM_Core_Error::statusBounce($msg);
|
||||
break;
|
||||
}
|
||||
$errorMessages[] = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->assign('surveyTypeId', $this->_surveyTypeId);
|
||||
|
||||
$options
|
||||
= array(
|
||||
'' => ' - none - ',
|
||||
'civicrm_address.street_name' => 'Street Name',
|
||||
'civicrm_address.street_number%2' => 'Odd / Even Street Number',
|
||||
'civicrm_address.street_number' => 'Street Number',
|
||||
'contact_a.sort_name' => 'Respondent Name',
|
||||
);
|
||||
for ($i = 1; $i < count($options); $i++) {
|
||||
$this->addElement('select', "order_bys[{$i}][column]", ts('Order by Column'), $options);
|
||||
$this->addElement('select', "order_bys[{$i}][order]", ts('Order by Order'), array(
|
||||
'ASC' => ts('Ascending'),
|
||||
'DESC' => ts('Descending'),
|
||||
));
|
||||
}
|
||||
|
||||
//pickup the uf fields.
|
||||
$this->_surveyFields = CRM_Campaign_BAO_Survey::getSurveyResponseFields($this->_surveyId,
|
||||
$this->_surveyTypeId
|
||||
);
|
||||
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
//build the profile fields.
|
||||
foreach ($this->_surveyFields as $name => $field) {
|
||||
if ($field) {
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $contactId);
|
||||
}
|
||||
}
|
||||
|
||||
//build the result field.
|
||||
if (!empty($this->_resultOptions)) {
|
||||
$this->add('select', "field[$contactId][result]", ts('Result'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) +
|
||||
array_combine($this->_resultOptions, $this->_resultOptions)
|
||||
);
|
||||
}
|
||||
|
||||
$this->add('text', "field[{$contactId}][note]", ts('Note'));
|
||||
|
||||
//need to keep control for release/reserve.
|
||||
if ($this->_allowAjaxReleaseButton) {
|
||||
$this->addElement('hidden',
|
||||
"field[{$contactId}][is_release_or_reserve]", 0,
|
||||
array('id' => "field_{$contactId}_is_release_or_reserve")
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->assign('surveyFields', empty($this->_surveyFields) ? FALSE : $this->_surveyFields);
|
||||
|
||||
//no need to get qf buttons.
|
||||
if ($this->_votingTab) {
|
||||
return;
|
||||
}
|
||||
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Done'),
|
||||
'subName' => 'interview',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
$buttons[] = array(
|
||||
'type' => 'submit',
|
||||
'name' => ts('Order By >>'),
|
||||
'subName' => 'orderBy',
|
||||
);
|
||||
|
||||
$manageCampaign = CRM_Core_Permission::check('manage campaign');
|
||||
$adminCampaign = CRM_Core_Permission::check('administer CiviCampaign');
|
||||
if ($manageCampaign ||
|
||||
$adminCampaign ||
|
||||
CRM_Core_Permission::check('release campaign contacts')
|
||||
) {
|
||||
$buttons[] = array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Release Respondents >>'),
|
||||
'subName' => 'interviewToRelease',
|
||||
);
|
||||
}
|
||||
if ($manageCampaign ||
|
||||
$adminCampaign ||
|
||||
CRM_Core_Permission::check('reserve campaign contacts')
|
||||
) {
|
||||
$buttons[] = array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Reserve More Respondents >>'),
|
||||
'subName' => 'interviewToReserve',
|
||||
);
|
||||
}
|
||||
|
||||
$this->addButtons($buttons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
//load default data for only contact fields.
|
||||
$contactFields = $defaults = array();
|
||||
foreach ($this->_surveyFields as $name => $field) {
|
||||
$acceptable_types = CRM_Contact_BAO_ContactType::basicTypes();
|
||||
$acceptable_types[] = 'Contact';
|
||||
if (in_array($field['field_type'], $acceptable_types)) {
|
||||
$contactFields[$name] = $field;
|
||||
}
|
||||
}
|
||||
if (!empty($contactFields)) {
|
||||
foreach ($this->_contactIds as $contactId) {
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $contactFields, $defaults, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) {
|
||||
$defaults['order_bys']
|
||||
= array(
|
||||
1 => array(
|
||||
'column' => 'civicrm_address.street_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
2 => array(
|
||||
'column' => 'civicrm_address.street_number%2',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
3 => array(
|
||||
'column' => 'civicrm_address.street_number',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
4 => array(
|
||||
'column' => 'contact_a.sort_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$defaults['order_bys']
|
||||
= array(
|
||||
1 => array(
|
||||
'column' => 'contact_a.sort_name',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
);
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if ($buttonName == '_qf_Interview_done_interviewToReserve') {
|
||||
//hey its time to stop cycle.
|
||||
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/survey/search', 'reset=1&op=reserve'));
|
||||
}
|
||||
elseif ($buttonName == '_qf_Interview_next_interviewToRelease') {
|
||||
//get ready to jump to release form.
|
||||
foreach (array(
|
||||
'surveyId',
|
||||
'contactIds',
|
||||
'interviewerId',
|
||||
) as $fld) {
|
||||
$this->controller->set($fld, $this->{"_$fld"});
|
||||
}
|
||||
$this->controller->set('interviewToRelease', TRUE);
|
||||
}
|
||||
|
||||
// vote is done through ajax
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function registerInterview($params) {
|
||||
$activityId = CRM_Utils_Array::value('activity_id', $params);
|
||||
$surveyTypeId = CRM_Utils_Array::value('activity_type_id', $params);
|
||||
if (!is_array($params) || !$surveyTypeId || !$activityId) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static $surveyFields;
|
||||
if (!is_array($surveyFields)) {
|
||||
$surveyFields = CRM_Core_BAO_CustomField::getFields('Activity',
|
||||
FALSE,
|
||||
FALSE,
|
||||
$surveyTypeId,
|
||||
NULL,
|
||||
FALSE,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
static $statusId;
|
||||
if (!$statusId) {
|
||||
$statusId = array_search('Completed', CRM_Core_PseudoConstant::activityStatus('name'));
|
||||
}
|
||||
|
||||
//format custom fields.
|
||||
$customParams = CRM_Core_BAO_CustomField::postProcess($params,
|
||||
$activityId,
|
||||
'Activity'
|
||||
);
|
||||
|
||||
CRM_Core_BAO_CustomValueTable::store($customParams, 'civicrm_activity', $activityId);
|
||||
|
||||
//process contact data.
|
||||
$contactParams = $fields = array();
|
||||
|
||||
$contactFieldTypes = array_merge(array('Contact'), CRM_Contact_BAO_ContactType::basicTypes());
|
||||
$responseFields = CRM_Campaign_BAO_Survey::getSurveyResponseFields($params['survey_id']);
|
||||
if (!empty($responseFields)) {
|
||||
foreach ($params as $key => $value) {
|
||||
if (array_key_exists($key, $responseFields)) {
|
||||
if (in_array($responseFields[$key]['field_type'], $contactFieldTypes)) {
|
||||
$fields[$key] = $responseFields[$key];
|
||||
$contactParams[$key] = $value;
|
||||
if (isset($params["{$key}_id"])) {
|
||||
$contactParams["{$key}_id"] = $params["{$key}_id"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$contactId = CRM_Utils_Array::value('voter_id', $params);
|
||||
if ($contactId && !empty($contactParams)) {
|
||||
CRM_Contact_BAO_Contact::createProfileContact($contactParams, $fields, $contactId);
|
||||
}
|
||||
|
||||
//update activity record.
|
||||
$activity = new CRM_Activity_DAO_Activity();
|
||||
$activity->id = $activityId;
|
||||
|
||||
$activity->selectAdd();
|
||||
$activity->selectAdd('activity_date_time, status_id, result, subject');
|
||||
$activity->find(TRUE);
|
||||
$activity->activity_date_time = date('YmdHis');
|
||||
$activity->status_id = $statusId;
|
||||
|
||||
if (!empty($params['activity_date_time'])) {
|
||||
$activity->activity_date_time = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
|
||||
}
|
||||
|
||||
$subject = '';
|
||||
$surveyTitle = CRM_Utils_Array::value('surveyTitle', $params);
|
||||
if ($surveyTitle) {
|
||||
$subject = $surveyTitle . ' - ';
|
||||
}
|
||||
$subject .= ts('Respondent Interview');
|
||||
|
||||
$activity->subject = $subject;
|
||||
$activityParams = array(
|
||||
'details' => 'details',
|
||||
'result' => 'result',
|
||||
'engagement_level' => 'activity_engagement_level',
|
||||
'subject' => 'activity_subject',
|
||||
'status_id' => 'activity_status_id',
|
||||
'source_contact_id' => 'source_contact',
|
||||
'location' => 'activity_location',
|
||||
'campaign_id' => 'activity_campaign_id',
|
||||
'duration' => 'activity_duration',
|
||||
);
|
||||
foreach ($activityParams as $key => $field) {
|
||||
if (!empty($params[$field])) {
|
||||
$activity->$key = $params[$field];
|
||||
}
|
||||
}
|
||||
|
||||
$activity->save();
|
||||
//really this should use Activity BAO& not be here but refactoring will have to be later
|
||||
//actually the whole ajax call could be done as an api ajax call & post hook would be sorted
|
||||
CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity);
|
||||
$activity->free();
|
||||
|
||||
return $activityId;
|
||||
}
|
||||
|
||||
public function getVoterIds() {
|
||||
if (!$this->_interviewerId) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$this->_interviewerId = $session->get('userID');
|
||||
}
|
||||
if (!$this->_surveyId) {
|
||||
// use default survey id
|
||||
$dao = new CRM_Campaign_DAO_Survey();
|
||||
$dao->is_active = 1;
|
||||
$dao->is_default = 1;
|
||||
$dao->find(TRUE);
|
||||
$this->_surveyId = $dao->id;
|
||||
}
|
||||
|
||||
$this->_contactIds = $this->get('contactIds');
|
||||
if (!is_array($this->_contactIds)) {
|
||||
//get the survey activities.
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$statusIds = array();
|
||||
if ($statusId = array_search('Scheduled', $activityStatus)) {
|
||||
$statusIds[] = $statusId;
|
||||
}
|
||||
$surveyActivities = CRM_Campaign_BAO_Survey::getSurveyVoterInfo($this->_surveyId,
|
||||
$this->_interviewerId,
|
||||
$statusIds
|
||||
);
|
||||
$this->_contactIds = array();
|
||||
foreach ($surveyActivities as $val) {
|
||||
$this->_contactIds[$val['voter_id']] = $val['voter_id'];
|
||||
}
|
||||
$this->set('contactIds', $this->_contactIds);
|
||||
}
|
||||
}
|
||||
|
||||
public function filterVoterIds() {
|
||||
//do the cleanup later on.
|
||||
if (!is_array($this->_contactIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$profileId = CRM_Campaign_BAO_Survey::getSurveyProfileId($this->_surveyId);
|
||||
if ($profileId) {
|
||||
$profileType = CRM_Core_BAO_UFField::getProfileType($profileId);
|
||||
if (in_array($profileType, CRM_Contact_BAO_ContactType::basicTypes())) {
|
||||
$voterIdCount = count($this->_contactIds);
|
||||
|
||||
//create temporary table to store voter ids.
|
||||
$tempTableName = CRM_Core_DAO::createTempTableName('civicrm_survey_respondent');
|
||||
CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS {$tempTableName}");
|
||||
$query = "
|
||||
CREATE TEMPORARY TABLE {$tempTableName} (
|
||||
id int unsigned NOT NULL AUTO_INCREMENT,
|
||||
survey_contact_id int unsigned NOT NULL,
|
||||
PRIMARY KEY ( id )
|
||||
);
|
||||
";
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
$batch = 100;
|
||||
$insertedCount = 0;
|
||||
do {
|
||||
$processIds = $this->_contactIds;
|
||||
$insertIds = array_splice($processIds, $insertedCount, $batch);
|
||||
if (!empty($insertIds)) {
|
||||
$insertSQL = "INSERT IGNORE INTO {$tempTableName}( survey_contact_id )
|
||||
VALUES (" . implode('),(', $insertIds) . ');';
|
||||
CRM_Core_DAO::executeQuery($insertSQL);
|
||||
}
|
||||
$insertedCount += $batch;
|
||||
} while ($insertedCount < $voterIdCount);
|
||||
|
||||
$query = "
|
||||
SELECT contact.id as id
|
||||
FROM civicrm_contact contact
|
||||
INNER JOIN {$tempTableName} ON ( {$tempTableName}.survey_contact_id = contact.id )
|
||||
WHERE contact.contact_type != %1";
|
||||
$removeContact = CRM_Core_DAO::executeQuery($query,
|
||||
array(1 => array($profileType, 'String'))
|
||||
);
|
||||
while ($removeContact->fetch()) {
|
||||
unset($this->_contactIds[$removeContact->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
106
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Print.php
Normal file
106
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Print.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to print voter records
|
||||
*/
|
||||
class CRM_Campaign_Form_Task_Print extends CRM_Campaign_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preprocess();
|
||||
|
||||
// set print view, so that print templates are called
|
||||
$this->controller->setPrint(1);
|
||||
|
||||
// get the formatted params
|
||||
$queryParams = $this->get('queryParams');
|
||||
|
||||
$sortID = NULL;
|
||||
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
|
||||
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
|
||||
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
|
||||
);
|
||||
}
|
||||
|
||||
$selector = new CRM_Campaign_Selector_Search($queryParams,
|
||||
$this->_action,
|
||||
$this->_componentClause
|
||||
);
|
||||
$controller = new CRM_Core_Selector_Controller($selector,
|
||||
NULL,
|
||||
$sortID,
|
||||
CRM_Core_Action::VIEW,
|
||||
$this,
|
||||
CRM_Core_Selector_Controller::SCREEN
|
||||
);
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* It consists of
|
||||
* - displaying the QILL (query in local language)
|
||||
* - displaying elements for saving the search
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
//
|
||||
// just need to add a javacript to popup the window for printing
|
||||
//
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Print Respondents'),
|
||||
'js' => array('onclick' => 'window.print()'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Done'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
// redirect to the main search page after printing is over
|
||||
}
|
||||
|
||||
}
|
174
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Release.php
Normal file
174
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Release.php
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to add contacts for voter reservation.
|
||||
*/
|
||||
class CRM_Campaign_Form_Task_Release extends CRM_Campaign_Form_Task {
|
||||
|
||||
/**
|
||||
* Survet id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_surveyId;
|
||||
|
||||
/**
|
||||
* Number of voters
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_interviewerId;
|
||||
|
||||
/**
|
||||
* Survey details
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $_surveyDetails;
|
||||
|
||||
protected $_surveyActivities;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_interviewToRelease = $this->get('interviewToRelease');
|
||||
if ($this->_interviewToRelease) {
|
||||
//user came from interview form.
|
||||
foreach (array(
|
||||
'surveyId',
|
||||
'contactIds',
|
||||
'interviewerId',
|
||||
) as $fld) {
|
||||
$this->{"_$fld"} = $this->get($fld);
|
||||
}
|
||||
|
||||
if (!empty($this->_contactIds)) {
|
||||
$this->assign('totalSelectedContacts', count($this->_contactIds));
|
||||
}
|
||||
}
|
||||
else {
|
||||
parent::preProcess();
|
||||
//get the survey id from user submitted values.
|
||||
$this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues'));
|
||||
$this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues'));
|
||||
}
|
||||
|
||||
if (!$this->_surveyId) {
|
||||
CRM_Core_Error::statusBounce(ts("Please search with 'Survey', to apply this action."));
|
||||
}
|
||||
if (!$this->_interviewerId) {
|
||||
CRM_Core_Error::statusBounce(ts('Missing Interviewer contact.'));
|
||||
}
|
||||
if (!is_array($this->_contactIds) || empty($this->_contactIds)) {
|
||||
CRM_Core_Error::statusBounce(ts('Could not find respondents to release.'));
|
||||
}
|
||||
|
||||
$surveyDetails = array();
|
||||
$params = array('id' => $this->_surveyId);
|
||||
$this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails);
|
||||
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$statusIds = array();
|
||||
foreach (array(
|
||||
'Scheduled',
|
||||
) as $name) {
|
||||
if ($statusId = array_search($name, $activityStatus)) {
|
||||
$statusIds[] = $statusId;
|
||||
}
|
||||
}
|
||||
//fetch the target survey activities.
|
||||
$this->_surveyActivities = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId,
|
||||
$this->_contactIds,
|
||||
$this->_interviewerId,
|
||||
$statusIds
|
||||
);
|
||||
if (count($this->_surveyActivities) < 1) {
|
||||
CRM_Core_Error::statusBounce(ts('We could not found respondent for this survey to release.'));
|
||||
}
|
||||
|
||||
$this->assign('surveyTitle', $surveyDetails['title']);
|
||||
|
||||
//append breadcrumb to survey dashboard.
|
||||
if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
|
||||
}
|
||||
|
||||
//set the title.
|
||||
CRM_Utils_System::setTitle(ts('Release Respondents'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
|
||||
$this->addDefaultButtons(ts('Release Respondents'), 'done');
|
||||
}
|
||||
|
||||
public function postProcess() {
|
||||
$deleteActivityIds = array();
|
||||
foreach ($this->_contactIds as $cid) {
|
||||
if (array_key_exists($cid, $this->_surveyActivities)) {
|
||||
$deleteActivityIds[] = $this->_surveyActivities[$cid]['activity_id'];
|
||||
}
|
||||
}
|
||||
|
||||
//set survey activities as deleted = true.
|
||||
if (!empty($deleteActivityIds)) {
|
||||
$query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )';
|
||||
CRM_Core_DAO::executeQuery($query);
|
||||
|
||||
if ($deleteActivityIds) {
|
||||
$status = ts("Respondent has been released.", array(
|
||||
'count' => count($deleteActivityIds),
|
||||
'plural' => '%count respondents have been released.',
|
||||
));
|
||||
CRM_Core_Session::setStatus($status, ts('Released'), 'success');
|
||||
}
|
||||
|
||||
if (count($this->_contactIds) > count($deleteActivityIds)) {
|
||||
$status = ts('1 respondent did not release.',
|
||||
array(
|
||||
'count' => (count($this->_contactIds) - count($deleteActivityIds)),
|
||||
'plural' => '%count respondents did not release.',
|
||||
)
|
||||
);
|
||||
CRM_Core_Session::setStatus($status, ts('Notice'), 'alert');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
357
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Reserve.php
Normal file
357
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Reserve.php
Normal file
|
@ -0,0 +1,357 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class provides the functionality to add contacts for voter reservation.
|
||||
*/
|
||||
class CRM_Campaign_Form_Task_Reserve extends CRM_Campaign_Form_Task {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* Survey id.
|
||||
*/
|
||||
protected $_surveyId;
|
||||
|
||||
/**
|
||||
* Interviewer id
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_interviewerId;
|
||||
|
||||
/**
|
||||
* Survey details
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $_surveyDetails;
|
||||
|
||||
/**
|
||||
* Number of voters
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_numVoters;
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
|
||||
//get the survey id from user submitted values.
|
||||
$this->_surveyId = $this->get('surveyId');
|
||||
$this->_interviewerId = $this->get('interviewerId');
|
||||
if (!$this->_surveyId) {
|
||||
CRM_Core_Error::statusBounce(ts("Could not find Survey Id."));
|
||||
}
|
||||
if (!$this->_interviewerId) {
|
||||
CRM_Core_Error::statusBounce(ts("Missing Interviewer contact."));
|
||||
}
|
||||
if (!is_array($this->_contactIds) || empty($this->_contactIds)) {
|
||||
CRM_Core_Error::statusBounce(ts("Could not find contacts for reservation."));
|
||||
}
|
||||
|
||||
$params = array('id' => $this->_surveyId);
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);
|
||||
|
||||
//get the survey activities.
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$statusIds = array();
|
||||
foreach (array('Scheduled') as $name) {
|
||||
if ($statusId = array_search($name, $activityStatus)) {
|
||||
$statusIds[] = $statusId;
|
||||
}
|
||||
}
|
||||
|
||||
// these are the activities count that are linked to the current
|
||||
// interviewer and current survey and not the list of ALL survey activities
|
||||
$this->_numVoters = CRM_Campaign_BAO_Survey::getSurveyActivities($this->_surveyId,
|
||||
$this->_interviewerId,
|
||||
$statusIds,
|
||||
NULL,
|
||||
TRUE
|
||||
);
|
||||
//validate the selected survey.
|
||||
$this->validateSurvey();
|
||||
$this->assign('surveyTitle', $this->_surveyDetails['title']);
|
||||
$this->assign('activityType', $this->_surveyDetails['activity_type_id']);
|
||||
$this->assign('surveyId', $this->_surveyId);
|
||||
|
||||
//append breadcrumb to survey dashboard.
|
||||
if (CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
|
||||
CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
|
||||
}
|
||||
|
||||
//set the title.
|
||||
CRM_Utils_System::setTitle(ts('Reserve Respondents'));
|
||||
}
|
||||
|
||||
public function validateSurvey() {
|
||||
$errorMsg = NULL;
|
||||
$maxVoters = CRM_Utils_Array::value('max_number_of_contacts', $this->_surveyDetails);
|
||||
if ($maxVoters) {
|
||||
if ($maxVoters <= $this->_numVoters) {
|
||||
$errorMsg = ts('The maximum number of contacts is already reserved for this interviewer.');
|
||||
}
|
||||
elseif (count($this->_contactIds) > ($maxVoters - $this->_numVoters)) {
|
||||
$errorMsg = ts('You can reserve a maximum of %count contact at a time for this survey.',
|
||||
array(
|
||||
'plural' => 'You can reserve a maximum of %count contacts at a time for this survey.',
|
||||
'count' => $maxVoters - $this->_numVoters,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$defaultNum = CRM_Utils_Array::value('default_number_of_contacts', $this->_surveyDetails);
|
||||
if (!$errorMsg && $defaultNum && (count($this->_contactIds) > $defaultNum)) {
|
||||
$errorMsg = ts('You can reserve a maximum of %count contact at a time for this survey.',
|
||||
array(
|
||||
'plural' => 'You can reserve a maximum of %count contacts at a time for this survey.',
|
||||
'count' => $defaultNum,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($errorMsg) {
|
||||
CRM_Core_Error::statusBounce($errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
// allow to add contact to either new or existing group.
|
||||
$this->addElement('text', 'ActivityType', ts('Activity Type'));
|
||||
$this->addElement('text', 'newGroupName', ts('Name for new group'));
|
||||
$this->addElement('text', 'newGroupDesc', ts('Description of new group'));
|
||||
$groups = CRM_Core_PseudoConstant::nestedGroup();
|
||||
$hasExistingGroups = FALSE;
|
||||
if (is_array($groups) && !empty($groups)) {
|
||||
$hasExistingGroups = TRUE;
|
||||
$this->addElement('select', 'groups', ts('Add respondent(s) to existing group(s)'),
|
||||
$groups, array('multiple' => "multiple", 'class' => 'crm-select2')
|
||||
);
|
||||
}
|
||||
$this->assign('hasExistingGroups', $hasExistingGroups);
|
||||
|
||||
$buttons = array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Reserve'),
|
||||
'subName' => 'reserve',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
if (CRM_Core_Permission::check('manage campaign') ||
|
||||
CRM_Core_Permission::check('administer CiviCampaign') ||
|
||||
CRM_Core_Permission::check('interview campaign contacts')
|
||||
) {
|
||||
$buttons[] = array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Reserve and Interview'),
|
||||
'subName' => 'reserveToInterview',
|
||||
);
|
||||
}
|
||||
$buttons[] = array(
|
||||
'type' => 'back',
|
||||
'name' => ts('Cancel'),
|
||||
);
|
||||
|
||||
$this->addButtons($buttons);
|
||||
$this->addFormRule(array('CRM_Campaign_Form_Task_Reserve', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return array
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
$invalidGroupName = FALSE;
|
||||
if (!empty($fields['newGroupName'])) {
|
||||
$title = trim($fields['newGroupName']);
|
||||
$name = CRM_Utils_String::titleToVar($title);
|
||||
$query = 'select count(*) from civicrm_group where name like %1 OR title like %2';
|
||||
$grpCnt = CRM_Core_DAO::singleValueQuery($query, array(
|
||||
1 => array($name, 'String'),
|
||||
2 => array($title, 'String'),
|
||||
));
|
||||
if ($grpCnt) {
|
||||
$invalidGroupName = TRUE;
|
||||
$errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName']));
|
||||
}
|
||||
}
|
||||
$self->assign('invalidGroupName', $invalidGroupName);
|
||||
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form after the input has been submitted and validated.
|
||||
*/
|
||||
public function postProcess() {
|
||||
//add reservation.
|
||||
$countVoters = 0;
|
||||
$maxVoters = CRM_Utils_Array::value('max_number_of_contacts', $this->_surveyDetails);
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$statusHeld = array_search('Scheduled', $activityStatus);
|
||||
|
||||
$reservedVoterIds = array();
|
||||
foreach ($this->_contactIds as $cid) {
|
||||
$subject = $this->_surveyDetails['title'] . ' - ' . ts('Respondent Reservation');
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$activityParams = array(
|
||||
'source_contact_id' => $session->get('userID'),
|
||||
'assignee_contact_id' => array($this->_interviewerId),
|
||||
'target_contact_id' => array($cid),
|
||||
'source_record_id' => $this->_surveyId,
|
||||
'activity_type_id' => $this->_surveyDetails['activity_type_id'],
|
||||
'subject' => $subject,
|
||||
'activity_date_time' => date('YmdHis'),
|
||||
'status_id' => $statusHeld,
|
||||
'skipRecentView' => 1,
|
||||
'campaign_id' => CRM_Utils_Array::value('campaign_id', $this->_surveyDetails),
|
||||
);
|
||||
$activity = CRM_Activity_BAO_Activity::create($activityParams);
|
||||
if ($activity->id) {
|
||||
$countVoters++;
|
||||
$reservedVoterIds[$cid] = $cid;
|
||||
}
|
||||
if ($maxVoters && ($maxVoters <= ($this->_numVoters + $countVoters))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//add reserved voters to groups.
|
||||
$groupAdditions = $this->_addRespondentToGroup($reservedVoterIds);
|
||||
|
||||
// Success message
|
||||
if ($countVoters > 0) {
|
||||
$status = '<p>' . ts("%count contact has been reserved.", array('plural' => '%count contacts have been reserved.', 'count' => $countVoters)) . '</p>';
|
||||
if ($groupAdditions) {
|
||||
$status .= '<p>' . ts('They have been added to %1.',
|
||||
array(1 => implode(' ' . ts('and') . ' ', $groupAdditions))
|
||||
) . '</p>';
|
||||
}
|
||||
CRM_Core_Session::setStatus($status, ts('Reservation Added'), 'success');
|
||||
}
|
||||
// Error message
|
||||
if (count($this->_contactIds) > $countVoters) {
|
||||
CRM_Core_Session::setStatus(ts('Reservation did not add for %count contact.',
|
||||
array(
|
||||
'plural' => 'Reservation did not add for %count contacts.',
|
||||
'count' => (count($this->_contactIds) - $countVoters),
|
||||
)
|
||||
), ts('Notice'));
|
||||
}
|
||||
|
||||
//get ready to jump to voter interview form.
|
||||
$buttonName = $this->controller->getButtonName();
|
||||
if (!empty($reservedVoterIds) &&
|
||||
$buttonName == '_qf_Reserve_next_reserveToInterview'
|
||||
) {
|
||||
$this->controller->set('surveyId', $this->_surveyId);
|
||||
$this->controller->set('contactIds', $reservedVoterIds);
|
||||
$this->controller->set('interviewerId', $this->_interviewerId);
|
||||
$this->controller->set('reserveToInterview', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $contactIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _addRespondentToGroup($contactIds) {
|
||||
$groupAdditions = array();
|
||||
if (empty($contactIds)) {
|
||||
return $groupAdditions;
|
||||
}
|
||||
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$groups = CRM_Utils_Array::value('groups', $params, array());
|
||||
$newGroupName = CRM_Utils_Array::value('newGroupName', $params);
|
||||
$newGroupDesc = CRM_Utils_Array::value('newGroupDesc', $params);
|
||||
|
||||
$newGroupId = NULL;
|
||||
//create new group.
|
||||
if ($newGroupName) {
|
||||
$grpParams = array(
|
||||
'title' => $newGroupName,
|
||||
'description' => $newGroupDesc,
|
||||
'is_active' => TRUE,
|
||||
);
|
||||
$group = CRM_Contact_BAO_Group::create($grpParams);
|
||||
$groups[] = $newGroupId = $group->id;
|
||||
}
|
||||
|
||||
//add the respondents to groups.
|
||||
if (is_array($groups)) {
|
||||
$existingGroups = CRM_Core_PseudoConstant::group();
|
||||
foreach ($groups as $groupId) {
|
||||
$addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
|
||||
$totalCount = CRM_Utils_Array::value(1, $addCount);
|
||||
if ($groupId == $newGroupId) {
|
||||
$name = $newGroupName;
|
||||
$new = TRUE;
|
||||
}
|
||||
else {
|
||||
$name = $existingGroups[$groupId];
|
||||
$new = FALSE;
|
||||
}
|
||||
if ($totalCount) {
|
||||
$url = CRM_Utils_System::url('civicrm/group/search',
|
||||
'reset=1&force=1&context=smog&gid=' . $groupId
|
||||
);
|
||||
$groupAdditions[] = '<a href="' . $url . '">' . $name . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $groupAdditions;
|
||||
}
|
||||
|
||||
}
|
59
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Result.php
Normal file
59
sites/all/modules/civicrm/CRM/Campaign/Form/Task/Result.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used for displaying results.
|
||||
*/
|
||||
class CRM_Campaign_Form_Task_Result extends CRM_Campaign_Form_Task {
|
||||
|
||||
/**
|
||||
* Build all the data structures needed to build the form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'done',
|
||||
'name' => ts('Done'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
174
sites/all/modules/civicrm/CRM/Campaign/Info.php
Normal file
174
sites/all/modules/civicrm/CRM/Campaign/Info.php
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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 |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class introduces component to the system and provides all the
|
||||
* information about it. It needs to extend CRM_Core_Component_Info
|
||||
* abstract class.
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_Campaign_Info extends CRM_Core_Component_Info {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $keyword = 'campaign';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return array
|
||||
*/
|
||||
public function getInfo() {
|
||||
return array(
|
||||
'name' => 'CiviCampaign',
|
||||
'translatedName' => ts('CiviCampaign'),
|
||||
'title' => ts('CiviCRM Campaign Engine'),
|
||||
'search' => 1,
|
||||
'showActivitiesInCore' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @param bool $getAllUnconditionally
|
||||
* @param bool $descriptions
|
||||
* Whether to return permission descriptions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
|
||||
$permissions = array(
|
||||
'administer CiviCampaign' => array(
|
||||
ts('administer CiviCampaign'),
|
||||
ts('Create new campaign, survey and petition types and their status'),
|
||||
),
|
||||
'manage campaign' => array(
|
||||
ts('manage campaign'),
|
||||
ts('Create new campaigns, surveys and petitions, reserve respondents'),
|
||||
),
|
||||
'reserve campaign contacts' => array(
|
||||
ts('reserve campaign contacts'),
|
||||
ts('Reserve campaign contacts for surveys and petitions'),
|
||||
),
|
||||
'release campaign contacts' => array(
|
||||
ts('release campaign contacts'),
|
||||
ts('Release reserved campaign contacts for surveys and petitions'),
|
||||
),
|
||||
'interview campaign contacts' => array(
|
||||
ts('interview campaign contacts'),
|
||||
ts('Record survey and petition responses from their reserved contacts'),
|
||||
),
|
||||
'gotv campaign contacts' => array(
|
||||
ts('GOTV campaign contacts'),
|
||||
ts('Record that contacts voted'),
|
||||
),
|
||||
'sign CiviCRM Petition' => array(
|
||||
ts('sign CiviCRM Petition'),
|
||||
),
|
||||
);
|
||||
|
||||
if (!$descriptions) {
|
||||
foreach ($permissions as $name => $attr) {
|
||||
$permissions[$name] = array_shift($attr);
|
||||
}
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return null
|
||||
*/
|
||||
public function getUserDashboardElement() {
|
||||
// no dashboard element for this component
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
public function getUserDashboardObject() {
|
||||
// no dashboard element for this component
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return null
|
||||
*/
|
||||
public function registerTab() {
|
||||
// this component doesn't use contact record tabs
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return null
|
||||
*/
|
||||
public function registerAdvancedSearchPane() {
|
||||
// this component doesn't use advanced search
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getActivityTypes() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* add shortcut to Create New.
|
||||
* @param $shortCuts
|
||||
*/
|
||||
public function creatNewShortcut(&$shortCuts) {
|
||||
if (CRM_Core_Permission::check('manage campaign') ||
|
||||
CRM_Core_Permission::check('administer CiviCampaign')
|
||||
) {
|
||||
$shortCuts = array_merge($shortCuts, array(
|
||||
array(
|
||||
'path' => 'civicrm/campaign/add',
|
||||
'query' => "reset=1&action=add",
|
||||
'ref' => 'new-campaign',
|
||||
'title' => ts('Campaign'),
|
||||
),
|
||||
array(
|
||||
'path' => 'civicrm/survey/add',
|
||||
'query' => "reset=1&action=add",
|
||||
'ref' => 'new-survey',
|
||||
'title' => ts('Survey'),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
875
sites/all/modules/civicrm/CRM/Campaign/Page/AJAX.php
Normal file
875
sites/all/modules/civicrm/CRM/Campaign/Page/AJAX.php
Normal file
|
@ -0,0 +1,875 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains all campaign related functions that are called using AJAX (jQuery)
|
||||
*/
|
||||
class CRM_Campaign_Page_AJAX {
|
||||
|
||||
public static function registerInterview() {
|
||||
$fields = array(
|
||||
'result',
|
||||
'voter_id',
|
||||
'survey_id',
|
||||
'activity_id',
|
||||
'surveyTitle',
|
||||
'interviewer_id',
|
||||
'activity_type_id',
|
||||
);
|
||||
|
||||
$params = array();
|
||||
foreach ($fields as $fld) {
|
||||
$params[$fld] = CRM_Utils_Array::value($fld, $_POST);
|
||||
}
|
||||
$params['details'] = CRM_Utils_Array::value('note', $_POST);
|
||||
$voterId = $params['voter_id'];
|
||||
$activityId = $params['activity_id'];
|
||||
|
||||
$customKey = "field_{$voterId}_custom";
|
||||
foreach ($_POST as $key => $value) {
|
||||
if (strpos($key, $customKey) !== FALSE) {
|
||||
$customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
|
||||
$params[$customFieldKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) &&
|
||||
is_array($_POST['field'][$voterId])
|
||||
) {
|
||||
foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
|
||||
$params[$fieldKey] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//lets pickup contat related fields.
|
||||
foreach ($_POST as $key => $value) {
|
||||
if (strpos($key, "field_{$voterId}_") !== FALSE &&
|
||||
strpos($key, "field_{$voterId}_custom") === FALSE
|
||||
) {
|
||||
$key = substr($key, strlen("field_{$voterId}_"));
|
||||
$params[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'status' => 'fail',
|
||||
'voter_id' => $voterId,
|
||||
'activity_id' => $params['interviewer_id'],
|
||||
);
|
||||
|
||||
//time to validate custom data.
|
||||
$errors = CRM_Core_BAO_CustomField::validateCustomData($params);
|
||||
if (is_array($errors) && !empty($errors)) {
|
||||
$result['errors'] = $errors;
|
||||
CRM_Utils_JSON::output($result);
|
||||
}
|
||||
|
||||
//process the response/interview data.
|
||||
$activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
|
||||
if ($activityId) {
|
||||
$result['status'] = 'success';
|
||||
}
|
||||
|
||||
CRM_Utils_JSON::output($result);
|
||||
}
|
||||
|
||||
public static function loadOptionGroupDetails() {
|
||||
|
||||
$id = CRM_Utils_Request::retrieve('option_group_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$status = 'fail';
|
||||
$opValues = array();
|
||||
|
||||
if ($id) {
|
||||
$groupParams['id'] = $id;
|
||||
CRM_Core_OptionValue::getValues($groupParams, $opValues);
|
||||
}
|
||||
|
||||
$surveyId = CRM_Utils_Request::retrieve('survey_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
if ($surveyId) {
|
||||
$survey = new CRM_Campaign_DAO_Survey();
|
||||
$survey->id = $surveyId;
|
||||
$survey->result_id = $id;
|
||||
if ($survey->find(TRUE)) {
|
||||
if ($survey->recontact_interval) {
|
||||
$recontactInterval = unserialize($survey->recontact_interval);
|
||||
foreach ($opValues as $opValId => $opVal) {
|
||||
if (is_numeric($recontactInterval[$opVal['label']])) {
|
||||
$opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($opValues)) {
|
||||
$status = 'success';
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'status' => $status,
|
||||
'result' => $opValues,
|
||||
);
|
||||
|
||||
CRM_Utils_JSON::output($result);
|
||||
}
|
||||
|
||||
public function voterList() {
|
||||
//get the search criteria params.
|
||||
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$searchParams = explode(',', $searchCriteria);
|
||||
|
||||
$params = $searchRows = array();
|
||||
foreach ($searchParams as $param) {
|
||||
if (!empty($_POST[$param])) {
|
||||
$params[$param] = $_POST[$param];
|
||||
}
|
||||
}
|
||||
|
||||
//format multi-select group and contact types.
|
||||
foreach (array(
|
||||
'group',
|
||||
'contact_type',
|
||||
) as $param) {
|
||||
$paramValue = CRM_Utils_Array::value($param, $params);
|
||||
if ($paramValue) {
|
||||
unset($params[$param]);
|
||||
$paramValue = explode(',', $paramValue);
|
||||
foreach ($paramValue as $key => $value) {
|
||||
$params[$param][$value] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$voterClauseParams = array();
|
||||
foreach (array(
|
||||
'campaign_survey_id',
|
||||
'survey_interviewer_id',
|
||||
'campaign_search_voter_for',
|
||||
) as $fld) {
|
||||
$voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params);
|
||||
}
|
||||
|
||||
$interviewerId = $surveyTypeId = $surveyId = NULL;
|
||||
$searchVoterFor = $params['campaign_search_voter_for'];
|
||||
if ($searchVoterFor == 'reserve') {
|
||||
if (!empty($params['campaign_survey_id'])) {
|
||||
$survey = new CRM_Campaign_DAO_Survey();
|
||||
$survey->id = $surveyId = $params['campaign_survey_id'];
|
||||
$survey->selectAdd('campaign_id, activity_type_id');
|
||||
$survey->find(TRUE);
|
||||
$campaignId = $survey->campaign_id;
|
||||
$surveyTypeId = $survey->activity_type_id;
|
||||
|
||||
//allow voter search in sub-part of given constituents,
|
||||
//but make sure in case user does not select any group.
|
||||
//get all associated campaign groups in where filter, CRM-7406
|
||||
$groups = CRM_Utils_Array::value('group', $params);
|
||||
if ($campaignId && CRM_Utils_System::isNull($groups)) {
|
||||
$campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
|
||||
foreach ($campaignGroups as $id => $group) {
|
||||
$params['group'][$id] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//apply filter of survey contact type for search.
|
||||
$contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId);
|
||||
if ($contactType) {
|
||||
$params['contact_type'][$contactType] = 1;
|
||||
}
|
||||
|
||||
unset($params['campaign_survey_id']);
|
||||
}
|
||||
unset($params['survey_interviewer_id']);
|
||||
}
|
||||
else {
|
||||
//get the survey status in where clause.
|
||||
$scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name'));
|
||||
if ($scheduledStatusId) {
|
||||
$params['survey_status_id'] = $scheduledStatusId;
|
||||
}
|
||||
//BAO/Query knows reserve/release/interview processes.
|
||||
if ($params['campaign_search_voter_for'] == 'gotv') {
|
||||
$params['campaign_search_voter_for'] = 'release';
|
||||
}
|
||||
}
|
||||
|
||||
$selectorCols = array(
|
||||
'sort_name',
|
||||
'street_address',
|
||||
'street_name',
|
||||
'street_number',
|
||||
'street_unit',
|
||||
);
|
||||
|
||||
// get the data table params.
|
||||
$dataTableParams = array(
|
||||
'sEcho' => array(
|
||||
'name' => 'sEcho',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'offset' => array(
|
||||
'name' => 'iDisplayStart',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'rowCount' => array(
|
||||
'name' => 'iDisplayLength',
|
||||
'type' => 'Integer',
|
||||
'default' => 25,
|
||||
),
|
||||
'sort' => array(
|
||||
'name' => 'iSortCol_0',
|
||||
'type' => 'Integer',
|
||||
'default' => 'sort_name',
|
||||
),
|
||||
'sortOrder' => array(
|
||||
'name' => 'sSortDir_0',
|
||||
'type' => 'String',
|
||||
'default' => 'asc',
|
||||
),
|
||||
);
|
||||
foreach ($dataTableParams as $pName => $pValues) {
|
||||
$$pName = $pValues['default'];
|
||||
if (!empty($_POST[$pValues['name']])) {
|
||||
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
|
||||
if ($pName == 'sort') {
|
||||
$$pName = $selectorCols[$$pName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$queryParams = CRM_Contact_BAO_Query::convertFormValues($params);
|
||||
$query = new CRM_Contact_BAO_Query($queryParams,
|
||||
NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_CAMPAIGN,
|
||||
TRUE
|
||||
);
|
||||
|
||||
//get the voter clause to restrict and validate search.
|
||||
$voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams);
|
||||
|
||||
$searchCount = $query->searchQuery(0, 0, NULL,
|
||||
TRUE, FALSE,
|
||||
FALSE, FALSE,
|
||||
FALSE,
|
||||
CRM_Utils_Array::value('whereClause', $voterClause),
|
||||
NULL,
|
||||
CRM_Utils_Array::value('fromClause', $voterClause)
|
||||
);
|
||||
|
||||
$iTotal = $searchCount;
|
||||
|
||||
$selectorCols = array(
|
||||
'contact_type',
|
||||
'sort_name',
|
||||
'street_address',
|
||||
'street_name',
|
||||
'street_number',
|
||||
'street_unit',
|
||||
);
|
||||
|
||||
$extraVoterColName = 'is_interview_conducted';
|
||||
if ($params['campaign_search_voter_for'] == 'reserve') {
|
||||
$extraVoterColName = 'reserve_voter';
|
||||
}
|
||||
|
||||
if ($searchCount > 0) {
|
||||
if ($searchCount < $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
// get the result of the search
|
||||
$result = $query->searchQuery($offset, $rowCount, $sort,
|
||||
FALSE, FALSE,
|
||||
FALSE, FALSE,
|
||||
FALSE,
|
||||
CRM_Utils_Array::value('whereClause', $voterClause),
|
||||
$sortOrder,
|
||||
CRM_Utils_Array::value('fromClause', $voterClause)
|
||||
);
|
||||
while ($result->fetch()) {
|
||||
$contactID = $result->contact_id;
|
||||
$typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type,
|
||||
FALSE,
|
||||
$result->contact_id
|
||||
);
|
||||
|
||||
$searchRows[$contactID] = array('id' => $contactID);
|
||||
foreach ($selectorCols as $col) {
|
||||
$val = $result->$col;
|
||||
if ($col == 'contact_type') {
|
||||
$val = $typeImage;
|
||||
}
|
||||
$searchRows[$contactID][$col] = $val;
|
||||
}
|
||||
if ($searchVoterFor == 'reserve') {
|
||||
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />';
|
||||
$msg = ts('Respondent Reserved.');
|
||||
$voterExtraColHtml .= " <span id='success_msg_{$contactID}' class='ok' style='display:none;'>$msg</span>";
|
||||
}
|
||||
elseif ($searchVoterFor == 'gotv') {
|
||||
$surveyActId = $result->survey_activity_id;
|
||||
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />';
|
||||
$msg = ts('Vote Recorded.');
|
||||
$voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>";
|
||||
}
|
||||
else {
|
||||
$surveyActId = $result->survey_activity_id;
|
||||
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />';
|
||||
$msg = ts('Vote Recorded.');
|
||||
$voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>";
|
||||
}
|
||||
$searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml;
|
||||
}
|
||||
}
|
||||
|
||||
$selectorElements = array_merge($selectorCols, array($extraVoterColName));
|
||||
|
||||
$iFilteredTotal = $iTotal;
|
||||
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
public function processVoterData() {
|
||||
$status = NULL;
|
||||
$operation = CRM_Utils_Type::escape($_POST['operation'], 'String');
|
||||
if ($operation == 'release') {
|
||||
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
|
||||
$isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String'));
|
||||
if ($activityId &&
|
||||
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
|
||||
$activityId,
|
||||
'is_deleted',
|
||||
$isDelete
|
||||
)
|
||||
) {
|
||||
$status = 'success';
|
||||
}
|
||||
}
|
||||
elseif ($operation == 'reserve') {
|
||||
$activityId = NULL;
|
||||
$createActivity = TRUE;
|
||||
if (!empty($_POST['activity_id'])) {
|
||||
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
|
||||
if ($activityId) {
|
||||
$createActivity = FALSE;
|
||||
$activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
|
||||
$activityId,
|
||||
'is_deleted',
|
||||
0
|
||||
);
|
||||
if ($activityUpdated) {
|
||||
$status = 'success';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($createActivity) {
|
||||
$ids = array(
|
||||
'source_record_id',
|
||||
'source_contact_id',
|
||||
'target_contact_id',
|
||||
'assignee_contact_id',
|
||||
);
|
||||
$activityParams = array();
|
||||
foreach ($ids as $id) {
|
||||
$val = CRM_Utils_Array::value($id, $_POST);
|
||||
if (!$val) {
|
||||
$createActivity = FALSE;
|
||||
break;
|
||||
}
|
||||
$activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer');
|
||||
}
|
||||
}
|
||||
if ($createActivity) {
|
||||
$isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String'));
|
||||
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
|
||||
$scheduledStatusId = array_search('Scheduled', $activityStatus);
|
||||
if ($isReserved) {
|
||||
$surveyValues = array();
|
||||
$surveyParams = array('id' => $activityParams['source_record_id']);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey',
|
||||
$surveyParams,
|
||||
$surveyValues,
|
||||
array('title', 'activity_type_id', 'campaign_id')
|
||||
);
|
||||
|
||||
$activityTypeId = $surveyValues['activity_type_id'];
|
||||
|
||||
$surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST);
|
||||
if (!$surveytitle) {
|
||||
$surveytitle = $surveyValues['title'];
|
||||
}
|
||||
|
||||
$subject = $surveytitle . ' - ' . ts('Respondent Reservation');
|
||||
$activityParams['subject'] = $subject;
|
||||
$activityParams['status_id'] = $scheduledStatusId;
|
||||
$activityParams['skipRecentView'] = 1;
|
||||
$activityParams['activity_date_time'] = date('YmdHis');
|
||||
$activityParams['activity_type_id'] = $activityTypeId;
|
||||
$activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL;
|
||||
|
||||
$activity = CRM_Activity_BAO_Activity::create($activityParams);
|
||||
if ($activity->id) {
|
||||
$status = 'success';
|
||||
}
|
||||
}
|
||||
else {
|
||||
//delete reserved activity for given voter.
|
||||
$voterIds = array($activityParams['target_contact_id']);
|
||||
$activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'],
|
||||
$voterIds,
|
||||
$activityParams['source_contact_id'],
|
||||
array($scheduledStatusId)
|
||||
);
|
||||
foreach ($activities as $voterId => $values) {
|
||||
$activityId = CRM_Utils_Array::value('activity_id', $values);
|
||||
if ($activityId && ($values['status_id'] == $scheduledStatusId)) {
|
||||
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
|
||||
$activityId,
|
||||
'is_deleted',
|
||||
TRUE
|
||||
);
|
||||
$status = 'success';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($operation == 'gotv') {
|
||||
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
|
||||
$hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String'));
|
||||
if ($activityId) {
|
||||
if ($hasVoted) {
|
||||
$statusValue = 2;
|
||||
}
|
||||
else {
|
||||
$statusValue = 1;
|
||||
}
|
||||
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
|
||||
$activityId,
|
||||
'status_id',
|
||||
$statusValue
|
||||
);
|
||||
$status = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Utils_JSON::output(array('status' => $status));
|
||||
}
|
||||
|
||||
public function allActiveCampaigns() {
|
||||
$currentCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns();
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
|
||||
$options = array(
|
||||
array(
|
||||
'value' => '',
|
||||
'title' => ts('- select -'),
|
||||
),
|
||||
);
|
||||
foreach ($campaigns as $value => $title) {
|
||||
$class = NULL;
|
||||
if (!array_key_exists($value, $currentCampaigns)) {
|
||||
$class = 'status-past';
|
||||
}
|
||||
$options[] = array(
|
||||
'value' => $value,
|
||||
'title' => $title,
|
||||
'class' => $class,
|
||||
);
|
||||
}
|
||||
$status = 'fail';
|
||||
if (count($options) > 1) {
|
||||
$status = 'success';
|
||||
}
|
||||
|
||||
$results = array(
|
||||
'status' => $status,
|
||||
'campaigns' => $options,
|
||||
);
|
||||
|
||||
CRM_Utils_JSON::output($results);
|
||||
}
|
||||
|
||||
public function campaignGroups() {
|
||||
$surveyId = CRM_Utils_Request::retrieve('survey_id', 'Positive',
|
||||
CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'
|
||||
);
|
||||
$campGroups = array();
|
||||
if ($surveyId) {
|
||||
$campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'campaign_id');
|
||||
if ($campaignId) {
|
||||
$campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
|
||||
}
|
||||
}
|
||||
|
||||
//CRM-7406 --If there is no campaign or no group associated with
|
||||
//campaign of given survey, lets allow to search across all groups.
|
||||
if (empty($campGroups)) {
|
||||
$campGroups = CRM_Core_PseudoConstant::group();
|
||||
}
|
||||
$groups = array(
|
||||
array(
|
||||
'value' => '',
|
||||
'title' => ts('- select -'),
|
||||
),
|
||||
);
|
||||
foreach ($campGroups as $grpId => $title) {
|
||||
$groups[] = array(
|
||||
'value' => $grpId,
|
||||
'title' => $title,
|
||||
);
|
||||
}
|
||||
$results = array(
|
||||
'status' => 'success',
|
||||
'groups' => $groups,
|
||||
);
|
||||
|
||||
CRM_Utils_JSON::output($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*/
|
||||
public static function campaignList() {
|
||||
//get the search criteria params.
|
||||
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$searchParams = explode(',', $searchCriteria);
|
||||
|
||||
$params = $searchRows = array();
|
||||
foreach ($searchParams as $param) {
|
||||
if (isset($_POST[$param])) {
|
||||
$params[$param] = $_POST[$param];
|
||||
}
|
||||
}
|
||||
|
||||
//this is sequence columns on datatable.
|
||||
$selectorCols = array(
|
||||
'id',
|
||||
'name',
|
||||
'title',
|
||||
'description',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'campaign_type_id',
|
||||
'campaign_type',
|
||||
'status_id',
|
||||
'status',
|
||||
'is_active',
|
||||
'isActive',
|
||||
'action',
|
||||
);
|
||||
|
||||
// get the data table params.
|
||||
$dataTableParams = array(
|
||||
'sEcho' => array(
|
||||
'name' => 'sEcho',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'offset' => array(
|
||||
'name' => 'iDisplayStart',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'rowCount' => array(
|
||||
'name' => 'iDisplayLength',
|
||||
'type' => 'Integer',
|
||||
'default' => 25,
|
||||
),
|
||||
'sort' => array(
|
||||
'name' => 'iSortCol_0',
|
||||
'type' => 'Integer',
|
||||
'default' => 'start_date',
|
||||
),
|
||||
'sortOrder' => array(
|
||||
'name' => 'sSortDir_0',
|
||||
'type' => 'String',
|
||||
'default' => 'desc',
|
||||
),
|
||||
);
|
||||
foreach ($dataTableParams as $pName => $pValues) {
|
||||
$$pName = $pValues['default'];
|
||||
if (!empty($_POST[$pValues['name']])) {
|
||||
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
|
||||
if ($pName == 'sort') {
|
||||
$$pName = $selectorCols[$$pName];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (array(
|
||||
'sort',
|
||||
'offset',
|
||||
'rowCount',
|
||||
'sortOrder',
|
||||
) as $sortParam) {
|
||||
$params[$sortParam] = $$sortParam;
|
||||
}
|
||||
|
||||
$searchCount = CRM_Campaign_BAO_Campaign::getCampaignSummary($params, TRUE);
|
||||
$campaigns = CRM_Campaign_Page_DashBoard::getCampaignSummary($params);
|
||||
$iTotal = $searchCount;
|
||||
|
||||
if ($searchCount > 0) {
|
||||
if ($searchCount < $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
foreach ($campaigns as $campaignID => $values) {
|
||||
foreach ($selectorCols as $col) {
|
||||
$searchRows[$campaignID][$col] = CRM_Utils_Array::value($col, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectorElements = $selectorCols;
|
||||
|
||||
$iFilteredTotal = $iTotal;
|
||||
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*/
|
||||
public function surveyList() {
|
||||
//get the search criteria params.
|
||||
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$searchParams = explode(',', $searchCriteria);
|
||||
|
||||
$params = $searchRows = array();
|
||||
foreach ($searchParams as $param) {
|
||||
if (!empty($_POST[$param])) {
|
||||
$params[$param] = $_POST[$param];
|
||||
}
|
||||
}
|
||||
|
||||
//this is sequence columns on datatable.
|
||||
$selectorCols = array(
|
||||
'id',
|
||||
'title',
|
||||
'campaign_id',
|
||||
'campaign',
|
||||
'activity_type_id',
|
||||
'activity_type',
|
||||
'release_frequency',
|
||||
'default_number_of_contacts',
|
||||
'max_number_of_contacts',
|
||||
'is_default',
|
||||
'is_active',
|
||||
'isActive',
|
||||
'result_id',
|
||||
'action',
|
||||
'voterLinks',
|
||||
);
|
||||
|
||||
// get the data table params.
|
||||
$dataTableParams = array(
|
||||
'sEcho' => array(
|
||||
'name' => 'sEcho',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'offset' => array(
|
||||
'name' => 'iDisplayStart',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'rowCount' => array(
|
||||
'name' => 'iDisplayLength',
|
||||
'type' => 'Integer',
|
||||
'default' => 25,
|
||||
),
|
||||
'sort' => array(
|
||||
'name' => 'iSortCol_0',
|
||||
'type' => 'Integer',
|
||||
'default' => 'created_date',
|
||||
),
|
||||
'sortOrder' => array(
|
||||
'name' => 'sSortDir_0',
|
||||
'type' => 'String',
|
||||
'default' => 'desc',
|
||||
),
|
||||
);
|
||||
foreach ($dataTableParams as $pName => $pValues) {
|
||||
$$pName = $pValues['default'];
|
||||
if (!empty($_POST[$pValues['name']])) {
|
||||
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
|
||||
if ($pName == 'sort') {
|
||||
$$pName = $selectorCols[$$pName];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (array(
|
||||
'sort',
|
||||
'offset',
|
||||
'rowCount',
|
||||
'sortOrder',
|
||||
) as $sortParam) {
|
||||
$params[$sortParam] = $$sortParam;
|
||||
}
|
||||
|
||||
$surveys = CRM_Campaign_Page_DashBoard::getSurveySummary($params);
|
||||
$searchCount = CRM_Campaign_BAO_Survey::getSurveySummary($params, TRUE);
|
||||
$iTotal = $searchCount;
|
||||
|
||||
if ($searchCount > 0) {
|
||||
if ($searchCount < $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
foreach ($surveys as $surveyID => $values) {
|
||||
foreach ($selectorCols as $col) {
|
||||
$searchRows[$surveyID][$col] = CRM_Utils_Array::value($col, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectorElements = $selectorCols;
|
||||
|
||||
$iFilteredTotal = $iTotal;
|
||||
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*/
|
||||
public function petitionList() {
|
||||
//get the search criteria params.
|
||||
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$searchParams = explode(',', $searchCriteria);
|
||||
|
||||
$params = $searchRows = array();
|
||||
foreach ($searchParams as $param) {
|
||||
if (!empty($_POST[$param])) {
|
||||
$params[$param] = $_POST[$param];
|
||||
}
|
||||
}
|
||||
|
||||
//this is sequence columns on datatable.
|
||||
$selectorCols = array(
|
||||
'id',
|
||||
'title',
|
||||
'campaign_id',
|
||||
'campaign',
|
||||
'activity_type_id',
|
||||
'activity_type',
|
||||
'is_default',
|
||||
'is_active',
|
||||
'isActive',
|
||||
'action',
|
||||
);
|
||||
|
||||
// get the data table params.
|
||||
$dataTableParams = array(
|
||||
'sEcho' => array(
|
||||
'name' => 'sEcho',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'offset' => array(
|
||||
'name' => 'iDisplayStart',
|
||||
'type' => 'Integer',
|
||||
'default' => 0,
|
||||
),
|
||||
'rowCount' => array(
|
||||
'name' => 'iDisplayLength',
|
||||
'type' => 'Integer',
|
||||
'default' => 25,
|
||||
),
|
||||
'sort' => array(
|
||||
'name' => 'iSortCol_0',
|
||||
'type' => 'Integer',
|
||||
'default' => 'created_date',
|
||||
),
|
||||
'sortOrder' => array(
|
||||
'name' => 'sSortDir_0',
|
||||
'type' => 'String',
|
||||
'default' => 'desc',
|
||||
),
|
||||
);
|
||||
foreach ($dataTableParams as $pName => $pValues) {
|
||||
$$pName = $pValues['default'];
|
||||
if (!empty($_POST[$pValues['name']])) {
|
||||
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
|
||||
if ($pName == 'sort') {
|
||||
$$pName = $selectorCols[$$pName];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (array(
|
||||
'sort',
|
||||
'offset',
|
||||
'rowCount',
|
||||
'sortOrder',
|
||||
) as $sortParam) {
|
||||
$params[$sortParam] = $$sortParam;
|
||||
}
|
||||
|
||||
$petitions = CRM_Campaign_Page_DashBoard::getPetitionSummary($params);
|
||||
$searchCount = CRM_Campaign_BAO_Petition::getPetitionSummary($params, TRUE);
|
||||
$iTotal = $searchCount;
|
||||
|
||||
if ($searchCount > 0) {
|
||||
if ($searchCount < $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
foreach ($petitions as $petitionID => $values) {
|
||||
foreach ($selectorCols as $col) {
|
||||
$searchRows[$petitionID][$col] = CRM_Utils_Array::value($col, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectorElements = $selectorCols;
|
||||
|
||||
$iFilteredTotal = $iTotal;
|
||||
|
||||
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
|
||||
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
}
|
511
sites/all/modules/civicrm/CRM/Campaign/Page/DashBoard.php
Normal file
511
sites/all/modules/civicrm/CRM/Campaign/Page/DashBoard.php
Normal file
|
@ -0,0 +1,511 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying Campaigns.
|
||||
*/
|
||||
class CRM_Campaign_Page_DashBoard extends CRM_Core_Page {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_campaignActionLinks;
|
||||
private static $_surveyActionLinks;
|
||||
private static $_petitionActionLinks;
|
||||
|
||||
/**
|
||||
* Get the action links for this page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function campaignActionLinks() {
|
||||
// check if variable _actionsLinks is populated
|
||||
if (!isset(self::$_campaignActionLinks)) {
|
||||
self::$_campaignActionLinks = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/campaign/add',
|
||||
'qs' => 'reset=1&action=update&id=%%id%%',
|
||||
'title' => ts('Update Campaign'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'title' => ts('Disable Campaign'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'title' => ts('Enable Campaign'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/campaign/add',
|
||||
'qs' => 'action=delete&reset=1&id=%%id%%',
|
||||
'title' => ts('Delete Campaign'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return self::$_campaignActionLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function surveyActionLinks() {
|
||||
// check if variable _actionsLinks is populated
|
||||
if (!isset(self::$_surveyActionLinks)) {
|
||||
self::$_surveyActionLinks = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/survey/configure/main',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Update Survey'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Survey'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Survey'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/survey/delete',
|
||||
'qs' => 'id=%%id%%&reset=1',
|
||||
'title' => ts('Delete Survey'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return self::$_surveyActionLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function petitionActionLinks() {
|
||||
if (!isset(self::$_petitionActionLinks)) {
|
||||
self::$_petitionActionLinks = self::surveyActionLinks();
|
||||
self::$_petitionActionLinks[CRM_Core_Action::UPDATE] = array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/petition/add',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Update Petition'),
|
||||
);
|
||||
self::$_petitionActionLinks[CRM_Core_Action::DISABLE] = array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Petition'),
|
||||
);
|
||||
self::$_petitionActionLinks[CRM_Core_Action::ENABLE] = array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Petition'),
|
||||
);
|
||||
self::$_petitionActionLinks[CRM_Core_Action::DELETE] = array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/petition/add',
|
||||
'qs' => 'action=delete&id=%%id%%&reset=1',
|
||||
'title' => ts('Delete Petition'),
|
||||
);
|
||||
self::$_petitionActionLinks[CRM_Core_Action::PROFILE] = array(
|
||||
'name' => ts('Sign'),
|
||||
'url' => 'civicrm/petition/sign',
|
||||
'qs' => 'sid=%%id%%&reset=1',
|
||||
'title' => ts('Sign Petition'),
|
||||
'fe' => TRUE,
|
||||
//CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
|
||||
);
|
||||
self::$_petitionActionLinks[CRM_Core_Action::BROWSE] = array(
|
||||
'name' => ts('Signatures'),
|
||||
'url' => 'civicrm/activity/search',
|
||||
'qs' => 'survey=%%id%%&force=1',
|
||||
'title' => ts('List the signatures'),
|
||||
//CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
|
||||
);
|
||||
}
|
||||
|
||||
return self::$_petitionActionLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function browseCampaign() {
|
||||
// ensure valid javascript (these must have a value set)
|
||||
$this->assign('searchParams', json_encode(NULL));
|
||||
$this->assign('campaignTypes', json_encode(NULL));
|
||||
$this->assign('campaignStatus', json_encode(NULL));
|
||||
|
||||
$this->assign('addCampaignUrl', CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
|
||||
$campaignCount = CRM_Campaign_BAO_Campaign::getCampaignCount();
|
||||
//don't load find interface when no campaigns in db.
|
||||
if (!$campaignCount) {
|
||||
$this->assign('hasCampaigns', FALSE);
|
||||
return;
|
||||
}
|
||||
$this->assign('hasCampaigns', TRUE);
|
||||
|
||||
//build the ajaxify campaign search and selector.
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Campaign', ts('Search Campaigns'));
|
||||
$controller->set('searchTab', 'campaign');
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCampaignSummary($params = array()) {
|
||||
$campaignsData = array();
|
||||
|
||||
//get the campaigns.
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaignSummary($params);
|
||||
if (!empty($campaigns)) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$campaignType = CRM_Campaign_PseudoConstant::campaignType();
|
||||
$campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus();
|
||||
$properties = array(
|
||||
'id',
|
||||
'name',
|
||||
'title',
|
||||
'status_id',
|
||||
'description',
|
||||
'campaign_type_id',
|
||||
'is_active',
|
||||
'start_date',
|
||||
'end_date',
|
||||
);
|
||||
foreach ($campaigns as $cmpid => $campaign) {
|
||||
foreach ($properties as $prop) {
|
||||
$campaignsData[$cmpid][$prop] = CRM_Utils_Array::value($prop, $campaign);
|
||||
}
|
||||
$statusId = CRM_Utils_Array::value('status_id', $campaign);
|
||||
$campaignsData[$cmpid]['status'] = CRM_Utils_Array::value($statusId, $campaignStatus);
|
||||
$campaignsData[$cmpid]['campaign_id'] = $campaign['id'];
|
||||
$campaignsData[$cmpid]['campaign_type'] = $campaignType[$campaign['campaign_type_id']];
|
||||
|
||||
$action = array_sum(array_keys(self::campaignActionLinks()));
|
||||
if ($campaign['is_active']) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
|
||||
$isActive = ts('No');
|
||||
if ($campaignsData[$cmpid]['is_active']) {
|
||||
$isActive = ts('Yes');
|
||||
}
|
||||
$campaignsData[$cmpid]['isActive'] = $isActive;
|
||||
|
||||
if (!empty($campaignsData[$cmpid]['start_date'])) {
|
||||
$campaignsData[$cmpid]['start_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['start_date'],
|
||||
$config->dateformatFull
|
||||
);
|
||||
}
|
||||
if (!empty($campaignsData[$cmpid]['end_date'])) {
|
||||
$campaignsData[$cmpid]['end_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['end_date'],
|
||||
$config->dateformatFull
|
||||
);
|
||||
}
|
||||
$campaignsData[$cmpid]['action'] = CRM_Core_Action::formLink(self::campaignActionLinks(),
|
||||
$action,
|
||||
array('id' => $campaign['id']),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'campaign.dashboard.row',
|
||||
'Campaign',
|
||||
$campaign['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $campaignsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function browseSurvey() {
|
||||
// ensure valid javascript - this must have a value set
|
||||
$this->assign('searchParams', json_encode(NULL));
|
||||
$this->assign('surveyTypes', json_encode(NULL));
|
||||
$this->assign('surveyCampaigns', json_encode(NULL));
|
||||
|
||||
$this->assign('addSurveyUrl', CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add'));
|
||||
|
||||
$surveyCount = CRM_Campaign_BAO_Survey::getSurveyCount();
|
||||
//don't load find interface when no survey in db.
|
||||
if (!$surveyCount) {
|
||||
$this->assign('hasSurveys', FALSE);
|
||||
return;
|
||||
}
|
||||
$this->assign('hasSurveys', TRUE);
|
||||
|
||||
//build the ajaxify survey search and selector.
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Survey', ts('Search Survey'));
|
||||
$controller->set('searchTab', 'survey');
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSurveySummary($params = array()) {
|
||||
$surveysData = array();
|
||||
|
||||
//get the survey.
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$surveys = CRM_Campaign_BAO_Survey::getSurveySummary($params);
|
||||
if (!empty($surveys)) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
|
||||
$surveyType = CRM_Campaign_BAO_Survey::getSurveyActivityType();
|
||||
foreach ($surveys as $sid => $survey) {
|
||||
$surveysData[$sid] = $survey;
|
||||
$campaignId = CRM_Utils_Array::value('campaign_id', $survey);
|
||||
$surveysData[$sid]['campaign'] = CRM_Utils_Array::value($campaignId, $campaigns);
|
||||
$surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']];
|
||||
if (!empty($survey['release_frequency'])) {
|
||||
$surveysData[$sid]['release_frequency'] = ts('1 Day', array('plural' => '%count Days', 'count' => $survey['release_frequency']));
|
||||
}
|
||||
|
||||
$action = array_sum(array_keys(self::surveyActionLinks($surveysData[$sid]['activity_type'])));
|
||||
if ($survey['is_active']) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
|
||||
$isActive = ts('No');
|
||||
if ($surveysData[$sid]['is_active']) {
|
||||
$isActive = ts('Yes');
|
||||
}
|
||||
$surveysData[$sid]['isActive'] = $isActive;
|
||||
|
||||
$isDefault = NULL;
|
||||
if ($surveysData[$sid]['is_default']) {
|
||||
$isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />';
|
||||
}
|
||||
$surveysData[$sid]['is_default'] = $isDefault;
|
||||
|
||||
if ($surveysData[$sid]['result_id']) {
|
||||
$resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set') . '">' . ts('Result Set') . '</a>';
|
||||
$surveysData[$sid]['result_id'] = $resultSet;
|
||||
}
|
||||
else {
|
||||
$resultUrl = CRM_Utils_System::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1");
|
||||
$surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>';
|
||||
}
|
||||
$surveysData[$sid]['action'] = CRM_Core_Action::formLink(self::surveyActionLinks($surveysData[$sid]['activity_type']),
|
||||
$action,
|
||||
array('id' => $sid),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'survey.dashboard.row',
|
||||
'Survey',
|
||||
$sid
|
||||
);
|
||||
|
||||
if (CRM_Utils_Array::value('activity_type', $surveysData[$sid]) != 'Petition') {
|
||||
$surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey::buildPermissionLinks($sid,
|
||||
TRUE,
|
||||
ts('more')
|
||||
);
|
||||
}
|
||||
|
||||
if ($reportID = CRM_Campaign_BAO_Survey::getReportID($sid)) {
|
||||
$url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
|
||||
$surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $surveysData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse petitions.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function browsePetition() {
|
||||
// Ensure valid javascript - this must have a value set
|
||||
$this->assign('searchParams', json_encode(NULL));
|
||||
$this->assign('petitionCampaigns', json_encode(NULL));
|
||||
|
||||
$this->assign('addPetitionUrl', CRM_Utils_System::url('civicrm/petition/add', 'reset=1&action=add'));
|
||||
|
||||
$petitionCount = CRM_Campaign_BAO_Petition::getPetitionCount();
|
||||
//don't load find interface when no petition in db.
|
||||
if (!$petitionCount) {
|
||||
$this->assign('hasPetitions', FALSE);
|
||||
return NULL;
|
||||
}
|
||||
$this->assign('hasPetitions', TRUE);
|
||||
|
||||
// Build the ajax petition search and selector.
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Petition', ts('Search Petition'));
|
||||
$controller->set('searchTab', 'petition');
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getPetitionSummary($params = array()) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$petitionsData = array();
|
||||
|
||||
//get the petitions.
|
||||
$petitions = CRM_Campaign_BAO_Petition::getPetitionSummary($params);
|
||||
if (!empty($petitions)) {
|
||||
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
|
||||
$petitionType = CRM_Campaign_BAO_Survey::getSurveyActivityType('label', TRUE);
|
||||
foreach ($petitions as $pid => $petition) {
|
||||
$petitionsData[$pid] = $petition;
|
||||
$camapignId = CRM_Utils_Array::value('campaign_id', $petition);
|
||||
$petitionsData[$pid]['campaign'] = CRM_Utils_Array::value($camapignId, $campaigns);
|
||||
$petitionsData[$pid]['activity_type'] = $petitionType[$petition['activity_type_id']];
|
||||
|
||||
$action = array_sum(array_keys(self::petitionActionLinks()));
|
||||
|
||||
if ($petition['is_active']) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
|
||||
$isActive = ts('No');
|
||||
if ($petitionsData[$pid]['is_active']) {
|
||||
$isActive = ts('Yes');
|
||||
}
|
||||
$petitionsData[$pid]['isActive'] = $isActive;
|
||||
$isDefault = NULL;
|
||||
if ($petitionsData[$pid]['is_default']) {
|
||||
$isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />';
|
||||
}
|
||||
$petitionsData[$pid]['is_default'] = $isDefault;
|
||||
|
||||
$petitionsData[$pid]['action'] = CRM_Core_Action::formLink(self::petitionActionLinks(),
|
||||
$action,
|
||||
array('id' => $pid),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'petition.dashboard.row',
|
||||
'Petition',
|
||||
$pid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $petitionsData;
|
||||
}
|
||||
|
||||
public function browse() {
|
||||
$this->_tabs = array(
|
||||
'campaign' => ts('Campaigns'),
|
||||
'survey' => ts('Surveys'),
|
||||
'petition' => ts('Petitions'),
|
||||
);
|
||||
|
||||
$subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
|
||||
if ($subPageType) {
|
||||
if (!isset($this->_tabs[$subPageType])) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
//load the data in tabs.
|
||||
$this->{'browse' . ucfirst($subPageType)}();
|
||||
$this->assign('subPageType', ucfirst($subPageType));
|
||||
}
|
||||
else {
|
||||
//build the tabs.
|
||||
$this->buildTabs();
|
||||
}
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'tabSettings' => array(
|
||||
'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'campaign')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function run() {
|
||||
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
|
||||
CRM_Utils_System::permissionDenied();
|
||||
}
|
||||
|
||||
$this->browse();
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
public function buildTabs() {
|
||||
$allTabs = array();
|
||||
foreach ($this->_tabs as $name => $title) {
|
||||
$allTabs[$name] = array(
|
||||
'title' => $title,
|
||||
'valid' => TRUE,
|
||||
'active' => TRUE,
|
||||
'link' => CRM_Utils_System::url('civicrm/campaign', "reset=1&type=$name"),
|
||||
);
|
||||
}
|
||||
$allTabs['campaign']['class'] = 'livePage';
|
||||
$this->assign('tabHeader', $allTabs);
|
||||
}
|
||||
|
||||
}
|
61
sites/all/modules/civicrm/CRM/Campaign/Page/Petition.php
Normal file
61
sites/all/modules/civicrm/CRM/Campaign/Page/Petition.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying Petition Signatures.
|
||||
*/
|
||||
class CRM_Campaign_Page_Petition extends CRM_Core_Page {
|
||||
public function browse() {
|
||||
|
||||
//get the survey id
|
||||
$surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
|
||||
|
||||
$signatures = CRM_Campaign_BAO_Petition::getPetitionSignature($surveyId);
|
||||
|
||||
$this->assign('signatures', $signatures);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function run() {
|
||||
$action = CRM_Utils_Request::retrieve('action', 'String',
|
||||
$this, FALSE, 0
|
||||
);
|
||||
$this->assign('action', $action);
|
||||
$this->browse();
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
}
|
133
sites/all/modules/civicrm/CRM/Campaign/Page/Petition/Confirm.php
Normal file
133
sites/all/modules/civicrm/CRM/Campaign/Page/Petition/Confirm.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page {
|
||||
/**
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function run() {
|
||||
CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
|
||||
|
||||
$contact_id = CRM_Utils_Request::retrieve('cid', 'Integer');
|
||||
$subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer');
|
||||
$hash = CRM_Utils_Request::retrieve('h', 'String');
|
||||
$activity_id = CRM_Utils_Request::retrieve('a', 'String');
|
||||
$petition_id = CRM_Utils_Request::retrieve('pid', 'String');
|
||||
if (!$petition_id) {
|
||||
$petition_id = CRM_Utils_Request::retrieve('p', 'String');
|
||||
}
|
||||
|
||||
if (!$contact_id ||
|
||||
!$subscribe_id ||
|
||||
!$hash
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts("Missing input parameters"));
|
||||
}
|
||||
|
||||
$result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id);
|
||||
if ($result === FALSE) {
|
||||
$this->assign('success', $result);
|
||||
}
|
||||
else {
|
||||
$this->assign('success', TRUE);
|
||||
// $this->assign( 'group' , $result );
|
||||
}
|
||||
|
||||
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
|
||||
$this->assign('display_name', $displayName);
|
||||
$this->assign('email', $email);
|
||||
$this->assign('petition_id', $petition_id);
|
||||
|
||||
$this->assign('survey_id', $petition_id);
|
||||
|
||||
$pparams['id'] = $petition_id;
|
||||
$this->petition = array();
|
||||
CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition);
|
||||
$this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
|
||||
$this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition));
|
||||
$this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition));
|
||||
CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition));
|
||||
|
||||
// send thank you email
|
||||
$params['contactId'] = $contact_id;
|
||||
$params['email-Primary'] = $email;
|
||||
$params['sid'] = $petition_id;
|
||||
$params['activityId'] = $activity_id;
|
||||
CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK);
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm email verification.
|
||||
*
|
||||
* @param int $contact_id
|
||||
* The id of the contact.
|
||||
* @param int $subscribe_id
|
||||
* The id of the subscription event.
|
||||
* @param string $hash
|
||||
* The hash.
|
||||
*
|
||||
* @param int $activity_id
|
||||
* @param int $petition_id
|
||||
*
|
||||
* @return bool
|
||||
* True on success
|
||||
*/
|
||||
public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) {
|
||||
$se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
|
||||
|
||||
if (!$se) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
$ce = new CRM_Mailing_Event_BAO_Confirm();
|
||||
$ce->event_subscribe_id = $se->id;
|
||||
$ce->time_stamp = date('YmdHis');
|
||||
$ce->save();
|
||||
|
||||
CRM_Contact_BAO_GroupContact::addContactsToGroup(
|
||||
array($contact_id),
|
||||
$se->group_id,
|
||||
'Email',
|
||||
'Added',
|
||||
$ce->id
|
||||
);
|
||||
|
||||
$bao = new CRM_Campaign_BAO_Petition();
|
||||
$bao->confirmSignature($activity_id, $contact_id, $petition_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_Page_Petition_ThankYou extends CRM_Core_Page {
|
||||
/**
|
||||
* Run page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function run() {
|
||||
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$petition_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this);
|
||||
$params['id'] = $petition_id;
|
||||
$this->petition = array();
|
||||
CRM_Campaign_BAO_Survey::retrieve($params, $this->petition);
|
||||
$this->assign('petitionTitle', $this->petition['title']);
|
||||
$this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition));
|
||||
$this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition));
|
||||
$this->assign('survey_id', $petition_id);
|
||||
$this->assign('status_id', $id);
|
||||
$this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
|
||||
CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition));
|
||||
|
||||
// send thank you or email verification emails
|
||||
/*
|
||||
* sendEmailMode
|
||||
* 1 = connected user via login/pwd - thank you
|
||||
* or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you
|
||||
* login using fb connect - thank you + click to add msg to fb wall
|
||||
* 2 = send a confirmation request email
|
||||
*/
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
}
|
209
sites/all/modules/civicrm/CRM/Campaign/Page/SurveyType.php
Normal file
209
sites/all/modules/civicrm/CRM/Campaign/Page/SurveyType.php
Normal file
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of Gender.
|
||||
*/
|
||||
class CRM_Campaign_Page_SurveyType extends CRM_Core_Page_Basic {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* The option group name.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_gName;
|
||||
|
||||
/**
|
||||
* The option group name in display format (capitalized, without underscores...etc)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_GName;
|
||||
|
||||
/**
|
||||
* The option group id.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_gid = NULL;
|
||||
|
||||
/**
|
||||
* Obtains the group name from url and sets the title.
|
||||
*/
|
||||
public function preProcess() {
|
||||
$this->_gName = 'activity_type';
|
||||
|
||||
$this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name');
|
||||
|
||||
$this->_GName = 'Survey Type';
|
||||
|
||||
$this->assign('gName', $this->_gName);
|
||||
$this->assign('GName', $this->_GName);
|
||||
|
||||
CRM_Utils_System::setTitle(ts('%1 Options', array(1 => $this->_GName)));
|
||||
|
||||
$this->assign('addSurveyType', array("civicrm/admin/campaign/surveyType", "reset=1&action=add"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Core_BAO_OptionValue';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/campaign/surveyType',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit %1', array(1 => $this->_gName)),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable %1', array(1 => $this->_gName)),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable %1', array(1 => $this->_gName)),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/campaign/surveyType',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete %1 Type', array(1 => $this->_gName)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the basic page (run essentially starts execution for that page).
|
||||
*/
|
||||
public function run() {
|
||||
$this->preProcess();
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all options.
|
||||
*/
|
||||
public function browse() {
|
||||
$campaingCompId = CRM_Core_Component::getComponentID('CiviCampaign');
|
||||
$groupParams = array('name' => $this->_gName);
|
||||
$optionValues = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
|
||||
|
||||
foreach ($optionValues as $key => $optionValue) {
|
||||
if (CRM_Utils_Array::value('component_id', $optionValue) != $campaingCompId) {
|
||||
unset($optionValues[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$returnURL = CRM_Utils_System::url("civicrm/admin/campaign/surveyType",
|
||||
"reset=1"
|
||||
);
|
||||
$filter = "option_group_id = " . $this->_gid;
|
||||
CRM_Utils_Weight::addOrder($optionValues, 'CRM_Core_DAO_OptionValue',
|
||||
'id', $returnURL, $filter
|
||||
);
|
||||
$this->assign('rows', $optionValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Campaign_Form_SurveyType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return $this->_GName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/campaign/surveyType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userContext params.
|
||||
*
|
||||
* @param int $mode
|
||||
* Mode that we are in.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function userContextParams($mode = NULL) {
|
||||
return 'reset=1';
|
||||
}
|
||||
|
||||
}
|
145
sites/all/modules/civicrm/CRM/Campaign/Page/Vote.php
Normal file
145
sites/all/modules/civicrm/CRM/Campaign/Page/Vote.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for voting tab interface.
|
||||
*/
|
||||
class CRM_Campaign_Page_Vote extends CRM_Core_Page {
|
||||
private $_surveyId;
|
||||
private $_interviewerId;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function reserve() {
|
||||
//build ajax voter search and selector.
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents'));
|
||||
$controller->set('votingTab', TRUE);
|
||||
$controller->set('subVotingTab', 'searchANDReserve');
|
||||
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function interview() {
|
||||
//build interview and release voter interface.
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents'));
|
||||
$controller->set('votingTab', TRUE);
|
||||
$controller->set('subVotingTab', 'searchANDInterview');
|
||||
if ($this->_surveyId) {
|
||||
$controller->set('surveyId', $this->_surveyId);
|
||||
}
|
||||
if ($this->_interviewerId) {
|
||||
$controller->set('interviewerId', $this->_interviewerId);
|
||||
}
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
public function browse() {
|
||||
$this->_tabs = array(
|
||||
'reserve' => ts('Reserve Respondents'),
|
||||
'interview' => ts('Interview Respondents'),
|
||||
);
|
||||
|
||||
$this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
|
||||
$this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
|
||||
|
||||
$subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
|
||||
if ($subPageType) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}"));
|
||||
//load the data in tabs.
|
||||
$this->{$subPageType}();
|
||||
}
|
||||
else {
|
||||
//build the tabs.
|
||||
$this->buildTabs();
|
||||
}
|
||||
$this->assign('subPageType', $subPageType);
|
||||
|
||||
CRM_Core_Resources::singleton()
|
||||
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
|
||||
->addSetting(array(
|
||||
'tabSettings' => array(
|
||||
'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function run() {
|
||||
$this->browse();
|
||||
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
public function buildTabs() {
|
||||
$allTabs = array();
|
||||
foreach ($this->_tabs as $name => $title) {
|
||||
// check for required permissions.
|
||||
if (!CRM_Core_Permission::check(array(
|
||||
array(
|
||||
'manage campaign',
|
||||
'administer CiviCampaign',
|
||||
"{$name} campaign contacts",
|
||||
),
|
||||
))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$urlParams = "type={$name}";
|
||||
if ($this->_surveyId) {
|
||||
$urlParams .= "&sid={$this->_surveyId}";
|
||||
}
|
||||
if ($this->_interviewerId) {
|
||||
$urlParams .= "&cid={$this->_interviewerId}";
|
||||
}
|
||||
$allTabs[$name] = array(
|
||||
'title' => $title,
|
||||
'valid' => TRUE,
|
||||
'active' => TRUE,
|
||||
'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
|
||||
);
|
||||
}
|
||||
|
||||
$this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
|
||||
}
|
||||
|
||||
}
|
155
sites/all/modules/civicrm/CRM/Campaign/PseudoConstant.php
Normal file
155
sites/all/modules/civicrm/CRM/Campaign/PseudoConstant.php
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class holds all the Pseudo constants those
|
||||
* are specific to Campaign and Survey.
|
||||
*/
|
||||
class CRM_Campaign_PseudoConstant extends CRM_Core_PseudoConstant {
|
||||
|
||||
/**
|
||||
* Activity types
|
||||
* @var array
|
||||
*/
|
||||
private static $activityType;
|
||||
|
||||
/**
|
||||
* Campaign Type
|
||||
* @var array
|
||||
*/
|
||||
private static $campaignType = array();
|
||||
|
||||
/**
|
||||
* Campaign Status
|
||||
* @var array
|
||||
*/
|
||||
private static $campaignStatus = array();
|
||||
|
||||
/**
|
||||
* Engagement Level
|
||||
*/
|
||||
private static $engagementLevel;
|
||||
|
||||
/**
|
||||
* @deprecated. Please use the buildOptions() method in the appropriate BAO object.
|
||||
* Get all the survey activity types
|
||||
*
|
||||
* @param string $returnColumn
|
||||
*
|
||||
* @return array
|
||||
* array reference of all survey activity types.
|
||||
*/
|
||||
public static function &activityType($returnColumn = 'name') {
|
||||
$cacheKey = $returnColumn;
|
||||
if (!isset(self::$activityType[$cacheKey])) {
|
||||
$campaingCompId = CRM_Core_Component::getComponentID('CiviCampaign');
|
||||
if ($campaingCompId) {
|
||||
self::$activityType[$cacheKey] = CRM_Core_OptionGroup::values('activity_type',
|
||||
FALSE, FALSE, FALSE,
|
||||
" AND v.component_id={$campaingCompId}",
|
||||
$returnColumn
|
||||
);
|
||||
}
|
||||
}
|
||||
asort(self::$activityType[$cacheKey]);
|
||||
return self::$activityType[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated. Please use the buildOptions() method in the appropriate BAO object.
|
||||
* Get all campaign types.
|
||||
*
|
||||
* The static array campaignType is returned
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* array reference of all campaign types.
|
||||
*/
|
||||
public static function &campaignType() {
|
||||
if (!self::$campaignType) {
|
||||
self::$campaignType = CRM_Core_OptionGroup::values('campaign_type');
|
||||
}
|
||||
asort(self::$campaignType);
|
||||
return self::$campaignType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated. Please use the buildOptions() method in the appropriate BAO object.
|
||||
* Get all campaign status.
|
||||
*
|
||||
* The static array campaignStatus is returned
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* array reference of all campaign status.
|
||||
*/
|
||||
public static function &campaignStatus() {
|
||||
if (!self::$campaignStatus) {
|
||||
self::$campaignStatus = CRM_Core_OptionGroup::values('campaign_status');
|
||||
}
|
||||
asort(self::$campaignStatus);
|
||||
return self::$campaignStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated. Please use the buildOptions() method in the appropriate BAO object.
|
||||
* Get all Engagement Level.
|
||||
*
|
||||
* The static array Engagement Level is returned
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
* array reference of all Engagement Level.
|
||||
*/
|
||||
public static function &engagementLevel() {
|
||||
if (!isset(self::$engagementLevel)) {
|
||||
self::$engagementLevel = CRM_Core_OptionGroup::values('engagement_index');
|
||||
}
|
||||
|
||||
return self::$engagementLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush given pseudoconstant so it can be reread from db
|
||||
* next time it's requested.
|
||||
*
|
||||
*
|
||||
* @param bool|string $name pseudoconstant to be flushed
|
||||
*/
|
||||
public static function flush($name = 'cache') {
|
||||
if (isset(self::$$name)) {
|
||||
self::$$name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
382
sites/all/modules/civicrm/CRM/Campaign/Selector/Search.php
Normal file
382
sites/all/modules/civicrm/CRM/Campaign/Selector/Search.php
Normal file
|
@ -0,0 +1,382 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to retrieve and display a range of contacts that match the given criteria.
|
||||
*/
|
||||
class CRM_Campaign_Selector_Search extends CRM_Core_Selector_Base implements CRM_Core_Selector_API {
|
||||
|
||||
/**
|
||||
* This defines two actions- View and Edit.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* We use desc to remind us what that column is, name is used in the tpl
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_columnHeaders;
|
||||
|
||||
/**
|
||||
* Properties of contact we're interested in displaying
|
||||
* @var array
|
||||
*/
|
||||
static $_properties = array(
|
||||
'contact_id',
|
||||
'sort_name',
|
||||
'street_unit',
|
||||
'street_name',
|
||||
'street_number',
|
||||
'street_address',
|
||||
'city',
|
||||
'postal_code',
|
||||
'state_province',
|
||||
'country',
|
||||
'email',
|
||||
'phone',
|
||||
'campaign_id',
|
||||
'survey_activity_id',
|
||||
'survey_activity_target_id',
|
||||
'survey_activity_target_contact_id',
|
||||
);
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_single = FALSE;
|
||||
|
||||
/**
|
||||
* Are we restricting ourselves to a single contact
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_limit = NULL;
|
||||
|
||||
/**
|
||||
* What context are we being invoked from
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = NULL;
|
||||
|
||||
/**
|
||||
* QueryParams is the array returned by exportValues called on
|
||||
* the HTML_QuickForm_Controller for that page.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_queryParams;
|
||||
|
||||
/**
|
||||
* Represent the type of selector.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_action;
|
||||
|
||||
/**
|
||||
* The additional clause that we restrict the search with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_surveyClause = NULL;
|
||||
|
||||
/**
|
||||
* The query object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_query;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $queryParams
|
||||
* Array of parameters for query.
|
||||
* @param \const|int $action - action of search basic or advanced.
|
||||
* @param string $surveyClause
|
||||
* If the caller wants to further restrict the search.
|
||||
* @param bool $single
|
||||
* Are we dealing only with one contact?.
|
||||
* @param int $limit
|
||||
* How many voters do we want returned.
|
||||
*
|
||||
* @param string $context
|
||||
*
|
||||
* @return \CRM_Campaign_Selector_Search
|
||||
*/
|
||||
public function __construct(
|
||||
&$queryParams,
|
||||
$action = CRM_Core_Action::NONE,
|
||||
$surveyClause = NULL,
|
||||
$single = FALSE,
|
||||
$limit = NULL,
|
||||
$context = 'search'
|
||||
) {
|
||||
// submitted form values
|
||||
$this->_queryParams = &$queryParams;
|
||||
|
||||
$this->_single = $single;
|
||||
$this->_limit = $limit;
|
||||
$this->_context = $context;
|
||||
|
||||
$this->_campaignClause = $surveyClause;
|
||||
$this->_campaignFromClause = CRM_Utils_Array::value('fromClause', $surveyClause);
|
||||
$this->_campaignWhereClause = CRM_Utils_Array::value('whereClause', $surveyClause);
|
||||
|
||||
// type of selector
|
||||
$this->_action = $action;
|
||||
|
||||
$this->_query = new CRM_Contact_BAO_Query($this->_queryParams,
|
||||
NULL, NULL, FALSE, FALSE,
|
||||
CRM_Contact_BAO_Query::MODE_CAMPAIGN,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the links that are given for each search row.
|
||||
* currently the links added for each row are
|
||||
*
|
||||
* - View
|
||||
* - Edit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function &links() {
|
||||
return self::$_links = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for array of the parameters required for creating pager.
|
||||
*
|
||||
* @param $action
|
||||
* @param array $params
|
||||
*/
|
||||
public function getPagerParams($action, &$params) {
|
||||
$params['csvString'] = NULL;
|
||||
$params['status'] = ts('Respondents') . ' %%StatusMessage%%';
|
||||
$params['rowCount'] = ($this->_limit) ? $this->_limit : CRM_Utils_Pager::ROWCOUNT;
|
||||
$params['buttonTop'] = 'PagerTopButton';
|
||||
$params['buttonBottom'] = 'PagerBottomButton';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total number of rows for the query.
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @return int
|
||||
* Total number of rows
|
||||
*/
|
||||
public function getTotalCount($action) {
|
||||
return $this->_query->searchQuery(0, 0, NULL,
|
||||
TRUE, FALSE,
|
||||
FALSE, FALSE, FALSE,
|
||||
$this->_campaignWhereClause,
|
||||
NULL,
|
||||
$this->_campaignFromClause
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the rows in the given offset and rowCount.
|
||||
*
|
||||
* @param string $action
|
||||
* The action being performed.
|
||||
* @param int $offset
|
||||
* The row number to start from.
|
||||
* @param int $rowCount
|
||||
* The number of rows to return.
|
||||
* @param string $sort
|
||||
* The sql string that describes the sort order.
|
||||
* @param string $output
|
||||
* What should the result set include (web/email/csv).
|
||||
*
|
||||
* @return int
|
||||
* the total number of rows for this action
|
||||
*/
|
||||
public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
|
||||
$result = $this->_query->searchQuery($offset, $rowCount, $sort,
|
||||
FALSE, FALSE,
|
||||
FALSE, FALSE,
|
||||
FALSE, $this->_campaignWhereClause,
|
||||
NULL,
|
||||
$this->_campaignFromClause
|
||||
);
|
||||
|
||||
// process the result of the query
|
||||
$rows = array();
|
||||
|
||||
while ($result->fetch()) {
|
||||
$this->_query->convertToPseudoNames($result);
|
||||
$row = array();
|
||||
// the columns we are interested in
|
||||
foreach (self::$_properties as $property) {
|
||||
if (property_exists($result, $property)) {
|
||||
$row[$property] = $result->$property;
|
||||
}
|
||||
}
|
||||
$row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contact_id;
|
||||
$row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_type, FALSE, $result->contact_id);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
$this->buildPrevNextCache($sort);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sort
|
||||
*/
|
||||
public function buildPrevNextCache($sort) {
|
||||
//for prev/next pagination
|
||||
$crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer');
|
||||
|
||||
if (!$crmPID) {
|
||||
$cacheKey = "civicrm search {$this->_key}";
|
||||
CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact');
|
||||
|
||||
$sql = $this->_query->searchQuery(0, 0, $sort,
|
||||
FALSE, FALSE,
|
||||
FALSE, FALSE,
|
||||
TRUE, $this->_campaignWhereClause,
|
||||
NULL,
|
||||
$this->_campaignFromClause
|
||||
);
|
||||
list($select, $from) = explode(' FROM ', $sql);
|
||||
$insertSQL = "
|
||||
INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
|
||||
SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name
|
||||
FROM {$from}
|
||||
";
|
||||
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
|
||||
$result = CRM_Core_DAO::executeQuery($insertSQL);
|
||||
unset($errorScope);
|
||||
|
||||
if (is_a($result, 'DB_Error')) {
|
||||
return;
|
||||
}
|
||||
// also record an entry in the cache key table, so we can delete it periodically
|
||||
CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* which contains an array of strings
|
||||
*/
|
||||
public function getQILL() {
|
||||
return $this->_query->qill();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the column headers as an array of tuples:
|
||||
* (name, sortName (key to the sort array))
|
||||
*
|
||||
* @param string $action
|
||||
* The action being performed.
|
||||
* @param string $output
|
||||
* What should the result set include (web/email/csv).
|
||||
*
|
||||
* @return array
|
||||
* the column headers that need to be displayed
|
||||
*/
|
||||
public function &getColumnHeaders($action = NULL, $output = NULL) {
|
||||
self::$_columnHeaders = array();
|
||||
|
||||
if (!$this->_single) {
|
||||
$contactDetails = array(
|
||||
array(
|
||||
'name' => ts('Contact Name'),
|
||||
'sort' => 'sort_name',
|
||||
'direction' => CRM_Utils_Sort::ASCENDING,
|
||||
),
|
||||
array(
|
||||
'name' => ts('Street Number'),
|
||||
'sort' => 'street_number',
|
||||
),
|
||||
array(
|
||||
'name' => ts('Street Name'),
|
||||
'sort' => 'street_name',
|
||||
),
|
||||
array('name' => ts('Street Address')),
|
||||
array(
|
||||
'name' => ts('City'),
|
||||
'sort' => 'city',
|
||||
),
|
||||
array(
|
||||
'name' => ts('Postal Code'),
|
||||
'sort' => 'postal_code',
|
||||
),
|
||||
array(
|
||||
'name' => ts('State'),
|
||||
'sort' => 'state_province_name',
|
||||
),
|
||||
array('name' => ts('Country')),
|
||||
array('name' => ts('Email')),
|
||||
array('name' => ts('Phone')),
|
||||
);
|
||||
self::$_columnHeaders = array_merge($contactDetails, self::$_columnHeaders);
|
||||
}
|
||||
|
||||
return self::$_columnHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function &getQuery() {
|
||||
return $this->_query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of export file.
|
||||
*
|
||||
* @param string $output
|
||||
* Type of output.
|
||||
*
|
||||
* @return string
|
||||
* name of the file
|
||||
*/
|
||||
public function getExportFileName($output = 'csv') {
|
||||
return ts('CiviCRM Respondent Search');
|
||||
}
|
||||
|
||||
}
|
104
sites/all/modules/civicrm/CRM/Campaign/StateMachine/Search.php
Normal file
104
sites/all/modules/civicrm/CRM/Campaign/StateMachine/Search.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
class CRM_Campaign_StateMachine_Search extends CRM_Core_StateMachine {
|
||||
|
||||
/**
|
||||
* The task that the wizard is currently processing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_task;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param object $controller
|
||||
* @param \const|int $action
|
||||
*/
|
||||
public function __construct($controller, $action = CRM_Core_Action::NONE) {
|
||||
parent::__construct($controller, $action);
|
||||
|
||||
$this->_pages = array();
|
||||
|
||||
$this->_pages['CRM_Campaign_Form_Search'] = NULL;
|
||||
list($task, $result) = $this->taskName($controller, 'Search');
|
||||
$this->_task = $task;
|
||||
if (is_array($task)) {
|
||||
foreach ($task as $t) {
|
||||
$this->_pages[$t] = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->_pages[$task] = NULL;
|
||||
}
|
||||
if ($result) {
|
||||
$this->_pages['CRM_Campaign_Form_Task_Result'] = NULL;
|
||||
}
|
||||
|
||||
$this->addSequentialPages($this->_pages, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the form name based on the action. This allows us
|
||||
* to avoid using conditional state machine, much more efficient
|
||||
* and simpler
|
||||
*
|
||||
* @param CRM_Core_Controller $controller
|
||||
* The controller object.
|
||||
*
|
||||
* @param string $formName
|
||||
*
|
||||
* @return string
|
||||
* the name of the form that will handle the task
|
||||
*/
|
||||
public function taskName($controller, $formName = 'Search') {
|
||||
// total hack, check POST vars and then session to determine stuff
|
||||
$value = CRM_Utils_Array::value('task', $_POST);
|
||||
if (!isset($value)) {
|
||||
$value = $this->_controller->get('task');
|
||||
}
|
||||
$this->_controller->set('task', $value);
|
||||
|
||||
return CRM_Campaign_Task::getTask($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form name of the task.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTaskFormName() {
|
||||
return CRM_Utils_String::getClassName($this->_task);
|
||||
}
|
||||
|
||||
}
|
156
sites/all/modules/civicrm/CRM/Campaign/Task.php
Normal file
156
sites/all/modules/civicrm/CRM/Campaign/Task.php
Normal file
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* class to represent the actions that can be performed on a group of voters.
|
||||
*
|
||||
* Used by the search forms.
|
||||
*/
|
||||
class CRM_Campaign_Task {
|
||||
const INTERVIEW = 1, RESERVE = 2, RELEASE = 3, PRINT_VOTERS = 4;
|
||||
|
||||
/**
|
||||
* The task array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_tasks = NULL;
|
||||
|
||||
/**
|
||||
* The optional task array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_optionalTasks = NULL;
|
||||
|
||||
/**
|
||||
* These tasks are the core set of tasks that the user can perform
|
||||
* on a voter / group of voters
|
||||
*
|
||||
* @return array
|
||||
* the set of tasks for a group of voters.
|
||||
*/
|
||||
public static function &tasks() {
|
||||
if (!(self::$_tasks)) {
|
||||
self::$_tasks = array(
|
||||
1 => array(
|
||||
'title' => ts('Record Respondents Interview'),
|
||||
'class' => array(
|
||||
'CRM_Campaign_Form_Task_Interview',
|
||||
'CRM_Campaign_Form_Task_Release',
|
||||
),
|
||||
'result' => FALSE,
|
||||
),
|
||||
2 => array(
|
||||
'title' => ts('Reserve Respondents'),
|
||||
'class' => array(
|
||||
'CRM_Campaign_Form_Task_Reserve',
|
||||
'CRM_Campaign_Form_Task_Interview',
|
||||
'CRM_Campaign_Form_Task_Release',
|
||||
),
|
||||
'result' => FALSE,
|
||||
),
|
||||
3 => array(
|
||||
'title' => ts('Release Respondents'),
|
||||
'class' => 'CRM_Campaign_Form_Task_Release',
|
||||
'result' => FALSE,
|
||||
),
|
||||
4 => array(
|
||||
'title' => ts('Print Respondents'),
|
||||
'class' => 'CRM_Campaign_Form_Task_Print',
|
||||
'result' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
CRM_Utils_Hook::searchTasks('campaign', self::$_tasks);
|
||||
asort(self::$_tasks);
|
||||
}
|
||||
|
||||
return self::$_tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tasks are the core set of task titles
|
||||
* on voters.
|
||||
*
|
||||
* @return array
|
||||
* the set of task titles
|
||||
*/
|
||||
public static function &taskTitles() {
|
||||
self::tasks();
|
||||
$titles = array();
|
||||
foreach (self::$_tasks as $id => $value) {
|
||||
$titles[$id] = $value['title'];
|
||||
}
|
||||
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show tasks selectively based on the permission level
|
||||
* of the user
|
||||
*
|
||||
* @param int $permission
|
||||
*
|
||||
* @return array
|
||||
* set of tasks that are valid for the user
|
||||
*/
|
||||
public static function &permissionedTaskTitles($permission) {
|
||||
$tasks = self::taskTitles();
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tasks are the core set of tasks that the user can perform
|
||||
* on voters.
|
||||
*
|
||||
* @param int $value
|
||||
*
|
||||
* @return array
|
||||
* the set of tasks for a group of voters.
|
||||
*/
|
||||
public static function getTask($value) {
|
||||
self::tasks();
|
||||
if (!$value || !CRM_Utils_Array::value($value, self::$_tasks)) {
|
||||
// make the interview task by default
|
||||
$value = 1;
|
||||
}
|
||||
|
||||
return array(
|
||||
self::$_tasks[$value]['class'],
|
||||
self::$_tasks[$value]['result'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
173
sites/all/modules/civicrm/CRM/Campaign/xml/Menu/Campaign.xml
Normal file
173
sites/all/modules/civicrm/CRM/Campaign/xml/Menu/Campaign.xml
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||
|
||||
<menu>
|
||||
<item>
|
||||
<path>civicrm/campaign</path>
|
||||
<title>Campaign Dashboard</title>
|
||||
<page_callback>CRM_Campaign_Page_DashBoard</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/campaign/add</path>
|
||||
<title>New Campaign</title>
|
||||
<page_callback>CRM_Campaign_Form_Campaign</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/add</path>
|
||||
<title>New Survey</title>
|
||||
<page_callback>CRM_Campaign_Form_Survey_Main</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/campaign/vote</path>
|
||||
<title>Conduct Survey</title>
|
||||
<page_callback>CRM_Campaign_Page_Vote</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;reserve campaign contacts;interview campaign contacts</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/campaign/surveyType</path>
|
||||
<title>Survey Types</title>
|
||||
<page_callback>CRM_Campaign_Page_SurveyType</page_callback>
|
||||
<access_arguments>administer CiviCampaign</access_arguments>
|
||||
<icon>admin/small/05.png</icon>
|
||||
<adminGroup>CiviCampaign</adminGroup>
|
||||
<component>CiviCampaign</component>
|
||||
<weight>1</weight>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/options/campaign_type</path>
|
||||
<title>Campaign Types</title>
|
||||
<desc>categorize your campaigns using campaign types.</desc>
|
||||
<page_callback>CRM_Admin_Page_Options</page_callback>
|
||||
<adminGroup>CiviCampaign</adminGroup>
|
||||
<icon>admin/small/05.png</icon>
|
||||
<weight>2</weight>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/options/campaign_status</path>
|
||||
<title>Campaign Status</title>
|
||||
<desc>Define statuses for campaign here.</desc>
|
||||
<page_callback>CRM_Admin_Page_Options</page_callback>
|
||||
<adminGroup>CiviCampaign</adminGroup>
|
||||
<icon>admin/small/05.png</icon>
|
||||
<weight>3</weight>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/options/engagement_index</path>
|
||||
<title>Engagement Index</title>
|
||||
<desc>Engagement levels.</desc>
|
||||
<page_callback>CRM_Admin_Page_Options</page_callback>
|
||||
<adminGroup>CiviCampaign</adminGroup>
|
||||
<icon>admin/small/05.png</icon>
|
||||
<weight>4</weight>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/admin/setting/preferences/campaign</path>
|
||||
<title>CiviCampaign Component Settings</title>
|
||||
<page_callback>CRM_Admin_Form_Preferences_Campaign</page_callback>
|
||||
<desc>Configure global CiviCampaign behaviors.</desc>
|
||||
<adminGroup>CiviCampaign</adminGroup>
|
||||
<weight>10</weight>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/search</path>
|
||||
<title>Reserve Respondents</title>
|
||||
<path_arguments>op=reserve</path_arguments>
|
||||
<page_callback>CRM_Campaign_Controller_Search</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;reserve campaign contacts</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/search</path>
|
||||
<title>Release Respondents</title>
|
||||
<path_arguments>op=release</path_arguments>
|
||||
<page_callback>CRM_Campaign_Controller_Search</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;release campaign contacts</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/search</path>
|
||||
<title>Record Respondents Interview</title>
|
||||
<path_arguments>op=interview</path_arguments>
|
||||
<page_callback>CRM_Campaign_Controller_Search</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;interview campaign contacts</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/campaign/gotv</path>
|
||||
<title>GOTV (Track Voters)</title>
|
||||
<page_callback>CRM_Campaign_Form_Gotv</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;release campaign contacts;gotv campaign contacts</access_arguments>
|
||||
<component>CiviCampaign</component>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/petition/add</path>
|
||||
<title>New Petition</title>
|
||||
<page_callback>CRM_Campaign_Form_Petition</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/petition/sign</path>
|
||||
<title>Sign Petition</title>
|
||||
<page_callback>CRM_Campaign_Form_Petition_Signature</page_callback>
|
||||
<access_arguments>sign CiviCRM Petition</access_arguments>
|
||||
<is_public>true</is_public>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/petition/browse</path>
|
||||
<title>View Petition Signatures</title>
|
||||
<page_callback>CRM_Campaign_Page_Petition</page_callback>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/petition/confirm</path>
|
||||
<title>Email address verified</title>
|
||||
<page_callback>CRM_Campaign_Page_Petition_Confirm</page_callback>
|
||||
<access_arguments>sign CiviCRM Petition</access_arguments>
|
||||
<is_public>true</is_public>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/petition/thankyou</path>
|
||||
<title>Thank You</title>
|
||||
<page_callback>CRM_Campaign_Page_Petition_ThankYou</page_callback>
|
||||
<access_arguments>sign CiviCRM Petition</access_arguments>
|
||||
<is_public>true</is_public>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/campaign/registerInterview</path>
|
||||
<page_callback>CRM_Campaign_Page_AJAX::registerInterview</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign;interview campaign contacts</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/configure/main</path>
|
||||
<title>Configure Survey</title>
|
||||
<page_callback>CRM_Campaign_Form_Survey_Main</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/configure/questions</path>
|
||||
<title>Configure Survey</title>
|
||||
<page_callback>CRM_Campaign_Form_Survey_Questions</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/configure/results</path>
|
||||
<title>Configure Survey</title>
|
||||
<page_callback>CRM_Campaign_Form_Survey_Results</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
</item>
|
||||
<item>
|
||||
<path>civicrm/survey/delete</path>
|
||||
<title>Delete Survey</title>
|
||||
<page_callback>CRM_Campaign_Form_Survey_Delete</page_callback>
|
||||
<access_arguments>administer CiviCampaign;manage campaign</access_arguments>
|
||||
</item>
|
||||
</menu>
|
Loading…
Add table
Add a link
Reference in a new issue