First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
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,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue