3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class provides the functionality to add contacts for
40 class CRM_Campaign_Form_Task_Release
extends CRM_Campaign_Form_Task
{
54 protected $_interviewerId;
61 protected $_surveyDetails;
63 protected $_surveyActivities;
66 * build all the data structures needed to build the form
70 */ function preProcess() {
71 $this->_interviewToRelease
= $this->get('interviewToRelease');
72 if ($this->_interviewToRelease
) {
73 //user came from interview form.
75 'surveyId', 'contactIds', 'interviewerId') as $fld) {
76 $this->{"_$fld"} = $this->get($fld);
79 if (!empty($this->_contactIds
)) {
80 $this->assign('totalSelectedContacts', count($this->_contactIds
));
85 //get the survey id from user submitted values.
86 $this->_surveyId
= CRM_Utils_Array
::value('campaign_survey_id', $this->get('formValues'));
87 $this->_interviewerId
= CRM_Utils_Array
::value('survey_interviewer_id', $this->get('formValues'));
90 if (!$this->_surveyId
) {
91 CRM_Core_Error
::statusBounce(ts("Please search with 'Survey', to apply this action."));
93 if (!$this->_interviewerId
) {
94 CRM_Core_Error
::statusBounce(ts('Missing Interviewer contact.'));
96 if (!is_array($this->_contactIds
) ||
empty($this->_contactIds
)) {
97 CRM_Core_Error
::statusBounce(ts('Could not find respondents to release.'));
100 $surveyDetails = array();
101 $params = array('id' => $this->_surveyId
);
102 $this->_surveyDetails
= CRM_Campaign_BAO_Survey
::retrieve($params, $surveyDetails);
104 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
105 $statusIds = array();
107 'Scheduled') as $name) {
108 if ($statusId = array_search($name, $activityStatus)) {
109 $statusIds[] = $statusId;
112 //fetch the target survey activities.
113 $this->_surveyActivities
= CRM_Campaign_BAO_Survey
::voterActivityDetails($this->_surveyId
,
115 $this->_interviewerId
,
118 if (count($this->_surveyActivities
) < 1) {
119 CRM_Core_Error
::statusBounce(ts('We could not found respondent for this survey to release.'));
122 $this->assign('surveyTitle', $surveyDetails['title']);
124 //append breadcrumb to survey dashboard.
125 if (CRM_Campaign_BAO_Campaign
::accessCampaign()) {
126 $url = CRM_Utils_System
::url('civicrm/campaign', 'reset=1&subPage=survey');
127 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url)));
131 CRM_Utils_System
::setTitle(ts('Release Respondents'));
141 function buildQuickForm() {
143 $this->addDefaultButtons(ts('Release Respondents'), 'done');
146 function postProcess() {
147 $deleteActivityIds = array();
148 foreach ($this->_contactIds
as $cid) {
149 if (array_key_exists($cid, $this->_surveyActivities
)) {
150 $deleteActivityIds[] = $this->_surveyActivities
[$cid]['activity_id'];
154 //set survey activites as deleted = true.
155 if (!empty($deleteActivityIds)) {
156 $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )';
157 CRM_Core_DAO
::executeQuery($query);
159 $status = array(ts("%1 respondent(s) have been released.", array(1 => count($deleteActivityIds))));
160 if (count($this->_contactIds
) > count($deleteActivityIds)) {
161 $status[] = ts("%1 respondents did not release.",
162 array(1 => (count($this->_contactIds
) - count($deleteActivityIds)))
165 CRM_Core_Session
::setStatus(implode(' ', $status), '', 'info');