예제 #1
0
 /**
  * @return array
  */
 public function voterClause()
 {
     $params = array('campaign_search_voter_for' => $this->_operation);
     $clauseFields = array('surveyId' => 'campaign_survey_id', 'interviewerId' => 'survey_interviewer_id');
     foreach ($clauseFields as $param => $key) {
         $params[$key] = CRM_Utils_Array::value($key, $this->_formValues);
         if (!$params[$key]) {
             $params[$key] = $this->get($param);
         }
     }
     //build the clause.
     $voterClause = CRM_Campaign_BAO_Query::voterClause($params);
     return $voterClause;
 }
예제 #2
0
 public function voterList()
 {
     //get the search criteria params.
     $searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
     $searchParams = explode(',', $searchCriteria);
     $params = $searchRows = array();
     foreach ($searchParams as $param) {
         if (!empty($_POST[$param])) {
             $params[$param] = $_POST[$param];
         }
     }
     //format multi-select group and contact types.
     foreach (array('group', 'contact_type') as $param) {
         $paramValue = CRM_Utils_Array::value($param, $params);
         if ($paramValue) {
             unset($params[$param]);
             $paramValue = explode(',', $paramValue);
             foreach ($paramValue as $key => $value) {
                 $params[$param][$value] = 1;
             }
         }
     }
     $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 (!empty($params['campaign_survey_id'])) {
             $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;
             //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', $params);
             if ($campaignId && CRM_Utils_System::isNull($groups)) {
                 $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
                 foreach ($campaignGroups as $id => $group) {
                     $params['group'][$id] = 1;
                 }
             }
             //apply filter of survey contact type for search.
             $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId);
             if ($contactType) {
                 $params['contact_type'][$contactType] = 1;
             }
             unset($params['campaign_survey_id']);
         }
         unset($params['survey_interviewer_id']);
     } else {
         //get the survey status in where clause.
         $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 (!empty($_POST[$pValues['name']])) {
             ${$pName} = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
             if ($pName == 'sort') {
                 ${$pName} = $selectorCols[${$pName}];
             }
         }
     }
     $queryParams = CRM_Contact_BAO_Query::convertFormValues($params);
     $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CAMPAIGN, TRUE);
     //get the voter clause to restrict and validate search.
     $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams);
     $searchCount = $query->searchQuery(0, 0, NULL, TRUE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), NULL, CRM_Utils_Array::value('fromClause', $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;
         }
         $config = CRM_Core_Config::singleton();
         // get the result of the search
         $result = $query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, CRM_Utils_Array::value('whereClause', $voterClause), $sortOrder, CRM_Utils_Array::value('fromClause', $voterClause));
         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 .= "&nbsp;<span id='success_msg_{$contactID}' class='ok' style='display:none;'>{$msg}</span>";
             } elseif ($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 .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>{$msg}</span>";
             }
             $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml;
         }
     }
     $selectorElements = array_merge($selectorCols, array($extraVoterColName));
     $iFilteredTotal = $iTotal;
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }
예제 #3
0
 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 .= "&nbsp;<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 .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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();
 }