3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality to add contacts for voter reservation.
21 class CRM_Campaign_Form_Task_Release
extends CRM_Campaign_Form_Task
{
35 protected $_interviewerId;
42 protected $_surveyDetails;
44 protected $_surveyActivities;
47 * Build all the data structures needed to build the form.
49 public function preProcess() {
50 $this->_interviewToRelease
= $this->get('interviewToRelease');
51 if ($this->_interviewToRelease
) {
52 //user came from interview form.
58 $this->{"_$fld"} = $this->get($fld);
61 if (!empty($this->_contactIds
)) {
62 $this->assign('totalSelectedContacts', count($this->_contactIds
));
67 //get the survey id from user submitted values.
68 $this->_surveyId
= CRM_Utils_Array
::value('campaign_survey_id', $this->get('formValues'));
69 $this->_interviewerId
= CRM_Utils_Array
::value('survey_interviewer_id', $this->get('formValues'));
72 if (!$this->_surveyId
) {
73 CRM_Core_Error
::statusBounce(ts("Please search with 'Survey', to apply this action."));
75 if (!$this->_interviewerId
) {
76 CRM_Core_Error
::statusBounce(ts('Missing Interviewer contact.'));
78 if (!is_array($this->_contactIds
) ||
empty($this->_contactIds
)) {
79 CRM_Core_Error
::statusBounce(ts('Could not find respondents to release.'));
83 $params = ['id' => $this->_surveyId
];
84 $this->_surveyDetails
= CRM_Campaign_BAO_Survey
::retrieve($params, $surveyDetails);
86 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
88 foreach (['Scheduled'] as $name) {
89 if ($statusId = array_search($name, $activityStatus)) {
90 $statusIds[] = $statusId;
93 //fetch the target survey activities.
94 $this->_surveyActivities
= CRM_Campaign_BAO_Survey
::voterActivityDetails($this->_surveyId
,
96 $this->_interviewerId
,
99 if (count($this->_surveyActivities
) < 1) {
100 CRM_Core_Error
::statusBounce(ts('We could not found respondent for this survey to release.'));
103 $this->assign('surveyTitle', $surveyDetails['title']);
105 //append breadcrumb to survey dashboard.
106 if (CRM_Campaign_BAO_Campaign
::accessCampaign()) {
107 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
108 CRM_Utils_System
::appendBreadCrumb([['title' => ts('Survey(s)'), 'url' => $url]]);
112 CRM_Utils_System
::setTitle(ts('Release Respondents'));
116 * Build the form object.
118 public function buildQuickForm() {
120 $this->addDefaultButtons(ts('Release Respondents'), 'done');
123 public function postProcess() {
124 $deleteActivityIds = [];
125 foreach ($this->_contactIds
as $cid) {
126 if (array_key_exists($cid, $this->_surveyActivities
)) {
127 $deleteActivityIds[] = $this->_surveyActivities
[$cid]['activity_id'];
131 //set survey activities as deleted = true.
132 if (!empty($deleteActivityIds)) {
133 $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )';
134 CRM_Core_DAO
::executeQuery($query);
136 if ($deleteActivityIds) {
137 $status = ts("Respondent has been released.", [
138 'count' => count($deleteActivityIds),
139 'plural' => '%count respondents have been released.',
141 CRM_Core_Session
::setStatus($status, ts('Released'), 'success');
144 if (count($this->_contactIds
) > count($deleteActivityIds)) {
145 $status = ts('1 respondent did not release.',
147 'count' => (count($this->_contactIds
) - count($deleteActivityIds)),
148 'plural' => '%count respondents did not release.',
151 CRM_Core_Session
::setStatus($status, ts('Notice'), 'alert');