3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class provides the functionality to add contacts for voter reservation.
37 class CRM_Campaign_Form_Task_Release
extends CRM_Campaign_Form_Task
{
51 protected $_interviewerId;
58 protected $_surveyDetails;
60 protected $_surveyActivities;
63 * Build all the data structures needed to build the form.
65 public function preProcess() {
66 $this->_interviewToRelease
= $this->get('interviewToRelease');
67 if ($this->_interviewToRelease
) {
68 //user came from interview form.
74 $this->{"_$fld"} = $this->get($fld);
77 if (!empty($this->_contactIds
)) {
78 $this->assign('totalSelectedContacts', count($this->_contactIds
));
83 //get the survey id from user submitted values.
84 $this->_surveyId
= CRM_Utils_Array
::value('campaign_survey_id', $this->get('formValues'));
85 $this->_interviewerId
= CRM_Utils_Array
::value('survey_interviewer_id', $this->get('formValues'));
88 if (!$this->_surveyId
) {
89 CRM_Core_Error
::statusBounce(ts("Please search with 'Survey', to apply this action."));
91 if (!$this->_interviewerId
) {
92 CRM_Core_Error
::statusBounce(ts('Missing Interviewer contact.'));
94 if (!is_array($this->_contactIds
) ||
empty($this->_contactIds
)) {
95 CRM_Core_Error
::statusBounce(ts('Could not find respondents to release.'));
99 $params = ['id' => $this->_surveyId
];
100 $this->_surveyDetails
= CRM_Campaign_BAO_Survey
::retrieve($params, $surveyDetails);
102 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
104 foreach (['Scheduled'] as $name) {
105 if ($statusId = array_search($name, $activityStatus)) {
106 $statusIds[] = $statusId;
109 //fetch the target survey activities.
110 $this->_surveyActivities
= CRM_Campaign_BAO_Survey
::voterActivityDetails($this->_surveyId
,
112 $this->_interviewerId
,
115 if (count($this->_surveyActivities
) < 1) {
116 CRM_Core_Error
::statusBounce(ts('We could not found respondent for this survey to release.'));
119 $this->assign('surveyTitle', $surveyDetails['title']);
121 //append breadcrumb to survey dashboard.
122 if (CRM_Campaign_BAO_Campaign
::accessCampaign()) {
123 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
124 CRM_Utils_System
::appendBreadCrumb([['title' => ts('Survey(s)'), 'url' => $url]]);
128 CRM_Utils_System
::setTitle(ts('Release Respondents'));
132 * Build the form object.
134 public function buildQuickForm() {
136 $this->addDefaultButtons(ts('Release Respondents'), 'done');
139 public function postProcess() {
140 $deleteActivityIds = [];
141 foreach ($this->_contactIds
as $cid) {
142 if (array_key_exists($cid, $this->_surveyActivities
)) {
143 $deleteActivityIds[] = $this->_surveyActivities
[$cid]['activity_id'];
147 //set survey activities as deleted = true.
148 if (!empty($deleteActivityIds)) {
149 $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )';
150 CRM_Core_DAO
::executeQuery($query);
152 if ($deleteActivityIds) {
153 $status = ts("Respondent has been released.", [
154 'count' => count($deleteActivityIds),
155 'plural' => '%count respondents have been released.',
157 CRM_Core_Session
::setStatus($status, ts('Released'), 'success');
160 if (count($this->_contactIds
) > count($deleteActivityIds)) {
161 $status = ts('1 respondent did not release.',
163 'count' => (count($this->_contactIds
) - count($deleteActivityIds)),
164 'plural' => '%count respondents did not release.',
167 CRM_Core_Session
::setStatus($status, ts('Notice'), 'alert');