/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_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')); }
public function processVoterData() { $status = NULL; $operation = CRM_Utils_Type::escape($_POST['operation'], 'String'); if ($operation == 'release') { $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String')); if ($activityId && CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', $isDelete)) { $status = 'success'; } } elseif ($operation == 'reserve') { $activityId = NULL; $createActivity = TRUE; if (!empty($_POST['activity_id'])) { $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); if ($activityId) { $createActivity = FALSE; $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', 0); if ($activityUpdated) { $status = 'success'; } } } if ($createActivity) { $ids = array('source_record_id', 'source_contact_id', 'target_contact_id', 'assignee_contact_id'); $activityParams = array(); foreach ($ids as $id) { $val = CRM_Utils_Array::value($id, $_POST); if (!$val) { $createActivity = FALSE; break; } $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer'); } } if ($createActivity) { $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String')); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); if ($isReserved) { $surveyValues = array(); $surveyParams = array('id' => $activityParams['source_record_id']); CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey', $surveyParams, $surveyValues, array('title', 'activity_type_id', 'campaign_id')); $activityTypeId = $surveyValues['activity_type_id']; $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST); if (!$surveytitle) { $surveytitle = $surveyValues['title']; } $subject = $surveytitle . ' - ' . ts('Respondent Reservation'); $activityParams['subject'] = $subject; $activityParams['status_id'] = $scheduledStatusId; $activityParams['skipRecentView'] = 1; $activityParams['activity_date_time'] = date('YmdHis'); $activityParams['activity_type_id'] = $activityTypeId; $activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL; $activity = CRM_Activity_BAO_Activity::create($activityParams); if ($activity->id) { $status = 'success'; } } else { //delete reserved activity for given voter. $voterIds = array($activityParams['target_contact_id']); $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], $voterIds, $activityParams['source_contact_id'], array($scheduledStatusId)); foreach ($activities as $voterId => $values) { $activityId = CRM_Utils_Array::value('activity_id', $values); if ($activityId && $values['status_id'] == $scheduledStatusId) { CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', TRUE); $status = 'success'; break; } } } } } elseif ($operation == 'gotv') { $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String')); if ($activityId) { if ($hasVoted) { $statusValue = 2; } else { $statusValue = 1; } CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'status_id', $statusValue); $status = 'success'; } } CRM_Utils_JSON::output(array('status' => $status)); }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_votingTab = $this->get('votingTab'); $this->_reserveToInterview = $this->get('reserveToInterview'); if ($this->_reserveToInterview || $this->_votingTab) { //user came from voting tab / reserve form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } //get the target voter ids. if ($this->_votingTab) { $this->getVoterIds(); } } 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) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails); } $orderClause = FALSE; $buttonName = $this->controller->getButtonName(); if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) { $orderByParams = CRM_Utils_Array::value('order_bys', $_POST); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) { $orderByParams = array(1 => array('column' => 'civicrm_address.street_name', 'order' => 'ASC'), 2 => array('column' => 'civicrm_address.street_number%2', 'order' => 'ASC'), 3 => array('column' => 'civicrm_address.street_number', 'order' => 'ASC'), 4 => array('column' => 'contact_a.sort_name', 'order' => 'ASC')); } $orderBy = array(); if (!empty($orderByParams)) { foreach ($orderByParams as $key => $val) { if (!empty($val['column'])) { $orderBy[] = "{$val['column']} {$val['order']}"; } } if (!empty($orderBy)) { $orderClause = "ORDER BY " . implode(', ', $orderBy); } } $this->_contactIds = array_unique($this->_contactIds); if (!empty($this->_contactIds) && $orderClause) { $clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) '; $sql = "\nSELECT contact_a.id\nFROM civicrm_contact contact_a\nLEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id\nWHERE {$clause}\n{$orderClause}"; $this->_contactIds = array(); $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $this->_contactIds[] = $dao->id; } } //get the contact read only fields to display. $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name'))); //get the read only field data. $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); $returnProperties['contact_sub_type'] = TRUE; //validate all voters for required activity. //get the survey activities for given voters. $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); $activityIds = array(); foreach ($this->_contactIds as $key => $voterId) { $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds); $statusId = CRM_Utils_Array::value('status_id', $actVals); $activityId = CRM_Utils_Array::value('activity_id', $actVals); if ($activityId && $statusId && $scheduledStatusId == $statusId) { $activityIds["activity_id_{$voterId}"] = $activityId; } else { unset($this->_contactIds[$key]); } } //retrieve the contact details. $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties); $this->_allowAjaxReleaseButton = FALSE; if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) { $this->_allowAjaxReleaseButton = TRUE; } //validate voter ids across profile. $this->filterVoterIds(); $this->assign('votingTab', $this->_votingTab); $this->assign('componentIds', $this->_contactIds); $this->assign('componentIdsJson', json_encode($this->_contactIds)); $this->assign('voterDetails', $voterDetails); $this->assign('readOnlyFields', $readOnlyFields); $this->assign('interviewerId', $this->_interviewerId); $this->assign('surveyActivityIds', json_encode($activityIds)); $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton); //get the survey values. $this->_surveyValues = $this->get('surveyValues'); if (!is_array($this->_surveyValues)) { $this->_surveyValues = array(); if ($this->_surveyId) { $surveyParams = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues); } $this->set('surveyValues', $this->_surveyValues); } $this->assign('surveyValues', $this->_surveyValues); $result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId); $this->assign("instanceId", $result); //get the survey result options. $this->_resultOptions = $this->get('resultOptions'); if (!is_array($this->_resultOptions)) { $this->_resultOptions = array(); if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) { $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId); } $this->set('resultOptions', $this->_resultOptions); } //validate the required ids. $this->validateIds(); //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. $activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues); CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId]))); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $this->_votingTab = $this->get('votingTab'); $this->_reserveToInterview = $this->get('reserveToInterview'); if ($this->_reserveToInterview || $this->_votingTab) { //user came from voting tab / reserve form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } //get the target voter ids. if ($this->_votingTab) { $this->getVoterIds(); } } 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')); } //get the contact read only fields to display. require_once 'CRM/Core/BAO/Preferences.php'; $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name'))); //get the read only field data. $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); $returnProperties['contact_sub_type'] = true; //get the profile id. require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_id' => $this->_surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign'); $this->_ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $this->assign('ufGroupId', $this->_ufGroupId); //validate all voters for required activity. //get the survey activities for given voters. require_once 'CRM/Campaign/BAO/Survey.php'; $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId); require_once 'CRM/Core/PseudoConstant.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); $activityIds = array(); foreach ($this->_contactIds as $key => $voterId) { $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds); $statusId = CRM_Utils_Array::value('status_id', $actVals); $activityId = CRM_Utils_Array::value('activity_id', $actVals); if ($activityId && $statusId && $scheduledStatusId == $statusId) { $activityIds["activity_id_{$voterId}"] = $activityId; } else { unset($this->_contactIds[$key]); } } //retrieve the contact details. $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties); $this->_allowAjaxReleaseButton = false; if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) { $this->_allowAjaxReleaseButton = true; } $this->assign('votingTab', $this->_votingTab); $this->assign('componentIds', $this->_contactIds); $this->assign('voterDetails', $voterDetails); $this->assign('readOnlyFields', $readOnlyFields); $this->assign('interviewerId', $this->_interviewerId); $this->assign('surveyActivityIds', json_encode($activityIds)); $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton); //get the survey values. $this->_surveyValues = $this->get('surveyValues'); if (!is_array($this->_surveyValues)) { $this->_surveyValues = array(); if ($this->_surveyId) { require_once 'CRM/Campaign/BAO/Survey.php'; $surveyParams = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues); } $this->set('surveyValues', $this->_surveyValues); } $this->assign('surveyValues', $this->_surveyValues); //get the survey result options. $this->_resultOptions = $this->get('resultOptions'); if (!is_array($this->_resultOptions)) { $this->_resultOptions = array(); if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) { require_once 'CRM/Core/OptionGroup.php'; $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId); } $this->set('resultOptions', $this->_resultOptions); } //validate the required ids. $this->validateIds(); //append breadcrumb to survey dashboard. require_once 'CRM/Campaign/BAO/Campaign.php'; if (CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) { $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. require_once 'CRM/Core/PseudoConstant.php'; $activityTypes = CRM_Core_PseudoConstant::activityType(false, true, false, 'label', true); $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues); CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId]))); }
function processVoterData() { $status = null; $operation = CRM_Utils_Type::escape($_POST['operation'], 'String'); if ($operation == 'release') { require_once 'CRM/Utils/String.php'; $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String')); if ($activityId && CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', $isDelete)) { $status = 'success'; } } else { if ($operation == 'reserve') { $activityId = null; $createActivity = true; if (CRM_Utils_Array::value('activity_id', $_POST)) { $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); if ($activityId) { $createActivity = false; $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', 0); if ($activityUpdated) { $status = 'success'; } } } if ($createActivity) { $ids = array('source_record_id', 'source_contact_id', 'target_contact_id', 'assignee_contact_id'); $activityParams = array(); foreach ($ids as $id) { $val = CRM_Utils_Array::value($id, $_POST); if (!$val) { $createActivity = false; break; } $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer'); } } if ($createActivity) { $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String')); require_once 'CRM/Core/PseudoConstant.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); if ($isReserved) { $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $activityParams['source_record_id'], 'activity_type_id'); $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST); if (!$surveytitle) { $surveytitle = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $activityParams['source_record_id'], 'title'); } $subject = ts('%1', array(1 => $surveytitle)) . ' - ' . ts('Respondent Reservation'); $activityParams['subject'] = $subject; $activityParams['status_id'] = $scheduledStatusId; $activityParams['skipRecentView'] = 1; $activityParams['activity_date_time'] = date('YmdHis'); $activityParams['activity_type_id'] = $activityTypeId; require_once 'CRM/Activity/BAO/Activity.php'; $activity = CRM_Activity_BAO_Activity::create($activityParams); if ($activity->id) { $status = 'success'; } } else { //delete reserved activity for given voter. require_once 'CRM/Campaign/BAO/Survey.php'; $voterIds = array($activityParams['target_contact_id']); $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], $voterIds, $activityParams['source_contact_id'], array($scheduledStatusId)); foreach ($activities as $voterId => $values) { $activityId = CRM_Utils_Array::value('activity_id', $values); if ($activityId && $values['status_id'] == $scheduledStatusId) { CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'is_deleted', true); $status = 'success'; break; } } } } } else { if ($operation == 'gotv') { require_once 'CRM/Utils/String.php'; $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String')); if ($activityId) { if ($hasVoted) { $statusValue = 2; } else { $statusValue = 1; } CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', $activityId, 'status_id', $statusValue); $status = 'success'; } } } } echo json_encode(array('status' => $status)); CRM_Utils_System::civiExit(); }