_interviewToRelease = $this->get('interviewToRelease'); if ($this->_interviewToRelease) { //user came from interview form. foreach (array( 'surveyId', 'contactIds', 'interviewerId', ) as $fld) { $this->{"_$fld"} = $this->get($fld); } if (!empty($this->_contactIds)) { $this->assign('totalSelectedContacts', count($this->_contactIds)); } } else { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); } if (!$this->_surveyId) { CRM_Core_Error::statusBounce(ts("Please search with 'Survey', to apply this action.")); } if (!$this->_interviewerId) { CRM_Core_Error::statusBounce(ts('Missing Interviewer contact.')); } if (!is_array($this->_contactIds) || empty($this->_contactIds)) { CRM_Core_Error::statusBounce(ts('Could not find respondents to release.')); } $surveyDetails = array(); $params = array('id' => $this->_surveyId); $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $statusIds = array(); foreach (array( 'Scheduled', ) as $name) { if ($statusId = array_search($name, $activityStatus)) { $statusIds[] = $statusId; } } //fetch the target survey activities. $this->_surveyActivities = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId, $statusIds ); if (count($this->_surveyActivities) < 1) { CRM_Core_Error::statusBounce(ts('We could not found respondent for this survey to release.')); } $this->assign('surveyTitle', $surveyDetails['title']); //append breadcrumb to survey dashboard. if (CRM_Campaign_BAO_Campaign::accessCampaign()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. CRM_Utils_System::setTitle(ts('Release Respondents')); } /** * Build the form object * * * @return void */ public function buildQuickForm() { $this->addDefaultButtons(ts('Release Respondents'), 'done'); } public function postProcess() { $deleteActivityIds = array(); foreach ($this->_contactIds as $cid) { if (array_key_exists($cid, $this->_surveyActivities)) { $deleteActivityIds[] = $this->_surveyActivities[$cid]['activity_id']; } } //set survey activites as deleted = true. if (!empty($deleteActivityIds)) { $query = 'UPDATE civicrm_activity SET is_deleted = 1 WHERE id IN ( ' . implode(', ', $deleteActivityIds) . ' )'; CRM_Core_DAO::executeQuery($query); $status = array(ts("%1 respondent(s) have been released.", array(1 => count($deleteActivityIds)))); if (count($this->_contactIds) > count($deleteActivityIds)) { $status[] = ts("%1 respondents did not release.", array(1 => (count($this->_contactIds) - count($deleteActivityIds))) ); } CRM_Core_Session::setStatus(implode(' ', $status), '', 'info'); } } }