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.'));
98 $surveyDetails = array();
99 $params = array('id' => $this->_surveyId
);
100 $this->_surveyDetails
= CRM_Campaign_BAO_Survey
::retrieve($params, $surveyDetails);
102 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
103 $statusIds = array();
107 if ($statusId = array_search($name, $activityStatus)) {
108 $statusIds[] = $statusId;
111 //fetch the target survey activities.
112 $this->_surveyActivities
= CRM_Campaign_BAO_Survey
::voterActivityDetails($this->_surveyId
,
114 $this->_interviewerId
,
117 if (count($this->_surveyActivities
) < 1) {
118 CRM_Core_Error
::statusBounce(ts('We could not found respondent for this survey to release.'));
121 $this->assign('surveyTitle', $surveyDetails['title']);
123 //append breadcrumb to survey dashboard.
124 if (CRM_Campaign_BAO_Campaign
::accessCampaign()) {
125 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
126 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
130 CRM_Utils_System
::setTitle(ts('Release Respondents'));
134 * Build the form object.
136 public function buildQuickForm() {
138 $this->addDefaultButtons(ts('Release Respondents'), 'done');
141 public function postProcess() {
142 $deleteActivityIds = array();
143 foreach ($this->_contactIds
as $cid) {
144 if (array_key_exists($cid, $this->_surveyActivities
)) {
145 $deleteActivityIds[] = $this->_surveyActivities
[$cid]['activity_id'];
149 //set survey activities as deleted = true.
150 if (!empty($deleteActivityIds)) {
151 $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )';
152 CRM_Core_DAO
::executeQuery($query);
154 if ($deleteActivityIds) {
155 $status = ts("Respondent has been released.", array(
156 'count' => count($deleteActivityIds),
157 'plural' => '%count respondents have been released.',
159 CRM_Core_Session
::setStatus($status, ts('Released'), 'success');
162 if (count($this->_contactIds
) > count($deleteActivityIds)) {
163 $status = ts('1 respondent did not release.',
165 'count' => (count($this->_contactIds
) - count($deleteActivityIds)),
166 'plural' => '%count respondents did not release.',
169 CRM_Core_Session
::setStatus($status, ts('Notice'), 'alert');