Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class provides the functionality to add contacts for | |
38 | * voter reservation. | |
39 | */ | |
40 | class CRM_Campaign_Form_Task_Release extends CRM_Campaign_Form_Task { | |
41 | ||
42 | /** | |
100fef9d | 43 | * Survet id |
6a488035 TO |
44 | * |
45 | * @var int | |
46 | */ | |
47 | protected $_surveyId; | |
48 | ||
49 | /** | |
100fef9d | 50 | * Number of voters |
6a488035 TO |
51 | * |
52 | * @var int | |
53 | */ | |
54 | protected $_interviewerId; | |
55 | ||
56 | /** | |
100fef9d | 57 | * Survey details |
6a488035 TO |
58 | * |
59 | * @var object | |
60 | */ | |
61 | protected $_surveyDetails; | |
62 | ||
63 | protected $_surveyActivities; | |
64 | ||
65 | /** | |
fe482240 | 66 | * Build all the data structures needed to build the form. |
6a488035 TO |
67 | * |
68 | * @return void | |
95ea96be | 69 | */ |
28a04ea9 | 70 | public function preProcess() { |
6a488035 TO |
71 | $this->_interviewToRelease = $this->get('interviewToRelease'); |
72 | if ($this->_interviewToRelease) { | |
73 | //user came from interview form. | |
74 | foreach (array( | |
353ffa53 TO |
75 | 'surveyId', |
76 | 'contactIds', | |
28a04ea9 | 77 | 'interviewerId', |
353ffa53 | 78 | ) as $fld) { |
6a488035 TO |
79 | $this->{"_$fld"} = $this->get($fld); |
80 | } | |
81 | ||
82 | if (!empty($this->_contactIds)) { | |
83 | $this->assign('totalSelectedContacts', count($this->_contactIds)); | |
84 | } | |
85 | } | |
86 | else { | |
87 | parent::preProcess(); | |
88 | //get the survey id from user submitted values. | |
89 | $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); | |
90 | $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); | |
91 | } | |
92 | ||
93 | if (!$this->_surveyId) { | |
94 | CRM_Core_Error::statusBounce(ts("Please search with 'Survey', to apply this action.")); | |
95 | } | |
96 | if (!$this->_interviewerId) { | |
97 | CRM_Core_Error::statusBounce(ts('Missing Interviewer contact.')); | |
98 | } | |
99 | if (!is_array($this->_contactIds) || empty($this->_contactIds)) { | |
100 | CRM_Core_Error::statusBounce(ts('Could not find respondents to release.')); | |
101 | } | |
102 | ||
103 | $surveyDetails = array(); | |
104 | $params = array('id' => $this->_surveyId); | |
105 | $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); | |
106 | ||
107 | $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); | |
108 | $statusIds = array(); | |
109 | foreach (array( | |
28a04ea9 | 110 | 'Scheduled', |
353ffa53 | 111 | ) as $name) { |
6a488035 TO |
112 | if ($statusId = array_search($name, $activityStatus)) { |
113 | $statusIds[] = $statusId; | |
114 | } | |
115 | } | |
116 | //fetch the target survey activities. | |
117 | $this->_surveyActivities = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, | |
118 | $this->_contactIds, | |
119 | $this->_interviewerId, | |
120 | $statusIds | |
121 | ); | |
122 | if (count($this->_surveyActivities) < 1) { | |
123 | CRM_Core_Error::statusBounce(ts('We could not found respondent for this survey to release.')); | |
124 | } | |
125 | ||
126 | $this->assign('surveyTitle', $surveyDetails['title']); | |
127 | ||
128 | //append breadcrumb to survey dashboard. | |
129 | if (CRM_Campaign_BAO_Campaign::accessCampaign()) { | |
130 | $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); | |
131 | CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); | |
132 | } | |
133 | ||
134 | //set the title. | |
135 | CRM_Utils_System::setTitle(ts('Release Respondents')); | |
136 | } | |
137 | ||
138 | /** | |
fe482240 | 139 | * Build the form object. |
6a488035 | 140 | * |
6a488035 TO |
141 | * |
142 | * @return void | |
143 | */ | |
00be9182 | 144 | public function buildQuickForm() { |
6a488035 TO |
145 | |
146 | $this->addDefaultButtons(ts('Release Respondents'), 'done'); | |
147 | } | |
148 | ||
00be9182 | 149 | public function postProcess() { |
6a488035 TO |
150 | $deleteActivityIds = array(); |
151 | foreach ($this->_contactIds as $cid) { | |
152 | if (array_key_exists($cid, $this->_surveyActivities)) { | |
153 | $deleteActivityIds[] = $this->_surveyActivities[$cid]['activity_id']; | |
154 | } | |
155 | } | |
156 | ||
157 | //set survey activites as deleted = true. | |
158 | if (!empty($deleteActivityIds)) { | |
159 | $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )'; | |
160 | CRM_Core_DAO::executeQuery($query); | |
161 | ||
99483ce8 CW |
162 | if ($deleteActivityIds) { |
163 | $status = ts("Respondent has been released.", array( | |
164 | 'count' => count($deleteActivityIds), | |
165 | 'plural' => '%count respondents have been released.', | |
166 | )); | |
167 | CRM_Core_Session::setStatus($status, ts('Released'), 'success'); | |
168 | } | |
169 | ||
6a488035 | 170 | if (count($this->_contactIds) > count($deleteActivityIds)) { |
99483ce8 CW |
171 | $status = ts('1 respondent did not release.', |
172 | array( | |
173 | 'count' => (count($this->_contactIds) - count($deleteActivityIds)), | |
174 | 'plural' => '%count respondents did not release.', | |
175 | ) | |
6a488035 | 176 | ); |
99483ce8 | 177 | CRM_Core_Session::setStatus($status, ts('Notice'), 'alert'); |
6a488035 | 178 | } |
6a488035 TO |
179 | } |
180 | } | |
96025800 | 181 | |
6a488035 | 182 | } |