3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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.
79 $this->{"_$fld"} = $this->get($fld);
82 if (!empty($this->_contactIds
)) {
83 $this->assign('totalSelectedContacts', count($this->_contactIds
));
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'));
93 if (!$this->_surveyId
) {
94 CRM_Core_Error
::statusBounce(ts("Please search with 'Survey', to apply this action."));
96 if (!$this->_interviewerId
) {
97 CRM_Core_Error
::statusBounce(ts('Missing Interviewer contact.'));
99 if (!is_array($this->_contactIds
) ||
empty($this->_contactIds
)) {
100 CRM_Core_Error
::statusBounce(ts('Could not find respondents to release.'));
103 $surveyDetails = array();
104 $params = array('id' => $this->_surveyId
);
105 $this->_surveyDetails
= CRM_Campaign_BAO_Survey
::retrieve($params, $surveyDetails);
107 $activityStatus = CRM_Core_PseudoConstant
::activityStatus('name');
108 $statusIds = array();
112 if ($statusId = array_search($name, $activityStatus)) {
113 $statusIds[] = $statusId;
116 //fetch the target survey activities.
117 $this->_surveyActivities
= CRM_Campaign_BAO_Survey
::voterActivityDetails($this->_surveyId
,
119 $this->_interviewerId
,
122 if (count($this->_surveyActivities
) < 1) {
123 CRM_Core_Error
::statusBounce(ts('We could not found respondent for this survey to release.'));
126 $this->assign('surveyTitle', $surveyDetails['title']);
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)));
135 CRM_Utils_System
::setTitle(ts('Release Respondents'));
139 * Build the form object
144 public function buildQuickForm() {
146 $this->addDefaultButtons(ts('Release Respondents'), 'done');
149 public function postProcess() {
150 $deleteActivityIds = array();
151 foreach ($this->_contactIds
as $cid) {
152 if (array_key_exists($cid, $this->_surveyActivities
)) {
153 $deleteActivityIds[] = $this->_surveyActivities
[$cid]['activity_id'];
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);
162 $status = array(ts("%1 respondent(s) have been released.", array(1 => count($deleteActivityIds))));
163 if (count($this->_contactIds
) > count($deleteActivityIds)) {
164 $status[] = ts("%1 respondents did not release.",
165 array(1 => (count($this->_contactIds
) - count($deleteActivityIds)))
168 CRM_Core_Session
::setStatus(implode(' ', $status), '', 'info');