public function campaignGroups() { $surveyId = CRM_Utils_Request::retrieve('survey_id', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'); $campGroups = array(); if ($surveyId) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'campaign_id'); if ($campaignId) { $campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); } } //CRM-7406 --If there is no campaign or no group associated with //campaign of given survey, lets allow to search across all groups. if (empty($campGroups)) { $campGroups = CRM_Core_PseudoConstant::group(); } $groups = array(array('value' => '', 'title' => ts('- select -'))); foreach ($campGroups as $grpId => $title) { $groups[] = array('value' => $grpId, 'title' => $title); } $results = array('status' => 'success', 'groups' => $groups); CRM_Utils_JSON::output($results); }
public function formatParams() { $interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->_formValues); if ($interviewerId) { $this->set('interviewerId', $interviewerId); } //format multi-select group and contact types. foreach (array('group', 'contact_type') as $param) { if ($this->_force) { continue; } $paramValue = CRM_Utils_Array::value($param, $this->_formValues); if ($paramValue && is_array($paramValue)) { unset($this->_formValues[$param]); foreach ($paramValue as $key => $value) { $this->_formValues[$param][$value] = 1; } } } //apply filter of survey contact type for search. $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType(CRM_Utils_Array::value('campaign_survey_id', $this->_formValues)); if ($contactType && in_array($this->_operation, array('reserve', 'interview'))) { $this->_formValues['contact_type'][$contactType] = 1; } if ($this->_operation == 'reserve') { if (!empty($this->_formValues['campaign_survey_id'])) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_formValues['campaign_survey_id'], 'campaign_id'); //allow voter search in sub-part of given constituents, //but make sure in case user does not select any group. //get all associated campaign groups in where filter, CRM-7406 $groups = CRM_Utils_Array::value('group', $this->_formValues); if ($campaignId && CRM_Utils_System::isNull($groups)) { $campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); foreach ($campGroups as $id => $title) { $this->_formValues['group'][$id] = 1; } } //carry servey id w/ this. $this->set('surveyId', $this->_formValues['campaign_survey_id']); unset($this->_formValues['campaign_survey_id']); } unset($this->_formValues['survey_interviewer_id']); } elseif ($this->_operation == 'interview' || $this->_operation == 'release') { //to conduct interview / release activity status should be scheduled. $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); if ($scheduledStatusId = array_search('Scheduled', $activityStatus)) { $this->_formValues['survey_status_id'] = $scheduledStatusId; } } //pass voter search operation. $this->_formValues['campaign_search_voter_for'] = $this->_operation; }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $existingVoterIds = $campGrpContacts = $reservedVoterIds = array(); foreach ($this->_surveyActivities as $actId => $actVals) { $voterId = $actVals['voter_id']; $existingVoterIds[$voterId] = $voterId; } $campaignId = CRM_Utils_Array::value('campaign_id', $this->_surveyDetails); require_once 'CRM/Campaign/BAO/Campaign.php'; require_once 'CRM/Contact/DAO/Group.php'; require_once 'CRM/Contact/BAO/GroupContact.php'; $campGrps = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); foreach ($campGrps as $grpId => $grpVals) { $group = new CRM_Contact_DAO_Group(); $group->id = $grpVals['entity_id']; $contacts = CRM_Contact_BAO_GroupContact::getGroupContacts($group); foreach ($contacts as $contact) { $campContacts[$contact->contact_id] = $contact->contact_id; } } //add reservation. require_once 'CRM/Core/PseudoConstant.php'; $countVoters = 0; $maxVoters = $surveyDetails['max_number_of_contacts']; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $statusHeld = array_search('Scheduled', $activityStatus); require_once 'CRM/Activity/BAO/Activity.php'; foreach ($this->_contactIds as $cid) { //apply filter for existing voters //and do check across campaign contacts. if (in_array($cid, $existingVoterIds) || !empty($campContacts) && !in_array($cid, $campContacts)) { continue; } $subject = ts('%1', array(1 => $this->_surveyDetails['title'])) . ' - ' . ts('Respondent Reservation'); $session =& CRM_Core_Session::singleton(); $activityParams = array('source_contact_id' => $session->get('userID'), 'assignee_contact_id' => array($this->_interviewerId), 'target_contact_id' => array($cid), 'source_record_id' => $this->_surveyId, 'activity_type_id' => $this->_surveyDetails['activity_type_id'], 'subject' => $subject, 'activity_date_time' => date('YmdHis'), 'status_id' => $statusHeld, 'skipRecentView' => 1); $activity = CRM_Activity_BAO_Activity::create($activityParams); if ($activity->id) { $countVoters++; $reservedVoterIds[$cid] = $cid; } if ($maxVoters && $maxVoters <= $this->_numVoters + $countVoters) { break; } } $status = array(); if ($countVoters > 0) { $status[] = ts('Reservation has been added for %1 Contact(s).', array(1 => $countVoters)); } if (count($this->_contactIds) > $countVoters) { $status[] = ts('Reservation did not add for %1 Contact(s).', array(1 => count($this->_contactIds) - $countVoters)); } if (!empty($status)) { CRM_Core_Session::setStatus(implode(' ', $status)); } //get ready to jump to voter interview form. $buttonName = $this->controller->getButtonName(); if (!empty($reservedVoterIds) && $buttonName == '_qf_Reserve_next_reserveToInterview') { $this->controller->set('surveyId', $this->_surveyId); $this->controller->set('contactIds', $reservedVoterIds); $this->controller->set('interviewerId', $this->_interviewerId); $this->controller->set('reserveToInterview', true); } }
function formatParams() { $interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->_formValues); if (!$interviewerId) { $session =& CRM_Core_Session::singleton(); $this->_formValues['survey_interviewer_id'] = $interviewerId = $session->get('userID'); } $this->set('interviewerId', $interviewerId); if (!CRM_Utils_Array::value('survey_interviewer_name', $this->_formValues)) { $this->_formValues['survey_interviewer_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $interviewerId, 'sort_name', 'id'); } if ($this->_operation == 'reserve') { if (CRM_Utils_Array::value('campaign_survey_id', $this->_formValues)) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_formValues['campaign_survey_id'], 'campaign_id'); if ($campaignId) { require_once 'CRM/Campaign/BAO/Campaign.php'; $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); foreach ($campaignGroups as $id => $group) { if ($group['entity_table'] == 'civicrm_group') { $this->_formValues['group'][$group['entity_id']] = 1; } } } //carry servey id w/ this. $this->set('surveyId', $this->_formValues['campaign_survey_id']); unset($this->_formValues['campaign_survey_id']); } unset($this->_formValues['survey_interviewer_id']); } else { if ($this->_operation == 'interview' || $this->_operation == 'release') { //to conduct interview / release activity status should be scheduled. $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); if ($scheduledStatusId = array_search('Scheduled', $activityStatus)) { $this->_formValues['survey_status_id'] = $scheduledStatusId; } } } //pass voter search operation. $this->_formValues['campaign_search_voter_for'] = $this->_operation; }
function voterList() { $searchParams = array('city', 'sort_name', 'street_unit', 'street_name', 'postal_code', 'street_number', 'street_address', 'survey_interviewer_id', 'campaign_survey_id', 'campaign_search_voter_for'); $params = $searchRows = array(); foreach ($searchParams as $param) { if (CRM_Utils_Array::value($param, $_POST)) { $params[$param] = $_POST[$param]; } } $voterClauseParams = array(); foreach (array('campaign_survey_id', 'survey_interviewer_id', 'campaign_search_voter_for') as $fld) { $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params); } $interviewerId = $surveyTypeId = $surveyId = null; $searchVoterFor = $params['campaign_search_voter_for']; if ($searchVoterFor == 'reserve') { if (CRM_Utils_Array::value('campaign_survey_id', $params)) { require_once 'CRM/Campaign/DAO/Survey.php'; $survey = new CRM_Campaign_DAO_Survey(); $survey->id = $surveyId = $params['campaign_survey_id']; $survey->selectAdd('campaign_id, activity_type_id'); $survey->find(true); $campaignId = $survey->campaign_id; $surveyTypeId = $survey->activity_type_id; if ($campaignId) { require_once 'CRM/Campaign/BAO/Campaign.php'; $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); foreach ($campaignGroups as $id => $group) { if ($group['entity_table'] == 'civicrm_group') { $params['group'][$group['entity_id']] = 1; } } } unset($params['campaign_survey_id']); } unset($params['survey_interviewer_id']); } else { //get the survey status in where clause. require_once 'CRM/Core/PseudoConstant.php'; $scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name')); if ($scheduledStatusId) { $params['survey_status_id'] = $scheduledStatusId; } //BAO/Query knows reserve/release/interview processes. if ($params['campaign_search_voter_for'] == 'gotv') { $params['campaign_search_voter_for'] = 'release'; } } $selectorCols = array('sort_name', 'street_address', 'street_name', 'street_number', 'street_unit'); // get the data table params. $dataTableParams = array('sEcho' => array('name' => 'sEcho', 'type' => 'Integer', 'default' => 0), 'offset' => array('name' => 'iDisplayStart', 'type' => 'Integer', 'default' => 0), 'rowCount' => array('name' => 'iDisplayLength', 'type' => 'Integer', 'default' => 25), 'sort' => array('name' => 'iSortCol_0', 'type' => 'Integer', 'default' => 'sort_name'), 'sortOrder' => array('name' => 'sSortDir_0', 'type' => 'String', 'default' => 'asc')); foreach ($dataTableParams as $pName => $pValues) { ${$pName} = $pValues['default']; if (CRM_Utils_Array::value($pValues['name'], $_POST)) { ${$pName} = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); if ($pName == 'sort') { ${$pName} = $selectorCols[${$pName}]; } } } require_once 'CRM/Contact/BAO/Query.php'; $queryParams = CRM_Contact_BAO_Query::convertFormValues($params); $query = new CRM_Contact_BAO_Query($queryParams, null, null, false, false, CRM_Contact_BAO_Query::MODE_CAMPAIGN); //get the voter clause to restrict and validate search. require_once 'CRM/Campaign/BAO/Query.php'; $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams); $searchCount = $query->searchQuery(0, 0, null, true, false, false, false, false, $voterClause); $iTotal = $searchCount; $selectorCols = array('contact_type', 'sort_name', 'street_address', 'street_name', 'street_number', 'street_unit'); $extraVoterColName = 'is_interview_conducted'; if ($params['campaign_search_voter_for'] = 'reserve') { $extraVoterColName = 'reserve_voter'; } if ($searchCount > 0) { if ($searchCount < $offset) { $offset = 0; } require_once 'CRM/Contact/BAO/Contact/Utils.php'; $config = CRM_Core_Config::singleton(); // get the result of the search $result = $query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $voterClause, $sortOrder); while ($result->fetch()) { $contactID = $result->contact_id; $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, false, $result->contact_id); $searchRows[$contactID] = array('id' => $contactID); foreach ($selectorCols as $col) { $val = $result->{$col}; if ($col == 'contact_type') { $val = $typeImage; } $searchRows[$contactID][$col] = $val; } if ($searchVoterFor == 'reserve') { $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />'; $msg = ts('Respondent Reserved.'); $voterExtraColHtml .= " <span id='success_msg_{$contactID}' class='ok' style='display:none;'>{$msg}</span>"; } else { if ($searchVoterFor == 'gotv') { $surveyActId = $result->survey_activity_id; $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />'; $msg = ts('Vote Recorded'); $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>"; } else { $surveyActId = $result->survey_activity_id; $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />'; $msg = ts('Vote Recorded'); $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>"; } } $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml; } } require_once "CRM/Utils/JSON.php"; $selectorElements = array_merge($selectorCols, array($extraVoterColName)); $iFilteredTotal = $iTotal; echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); CRM_Utils_System::civiExit(); }