/** * add all the elements shared between, * normal voter search and voter listing (GOTV form) * * @access public * @return void * @static */ static function buildSearchForm(&$form) { require_once 'CRM/Campaign/BAO/Survey.php'; $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $className = CRM_Utils_System::getClassName($form); $form->add('text', 'sort_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->add('text', 'street_name', ts('Street Name'), $attributes['street_name']); $form->add('text', 'street_number', ts('Street Number'), $attributes['street_number']); $form->add('text', 'street_unit', ts('Street Unit'), $attributes['street_unit']); $form->add('text', 'street_address', ts('Street Address'), $attributes['street_address']); $form->add('text', 'city', ts('City'), $attributes['city']); $form->add('text', 'postal_code', ts('Zip / Postal Code'), $attributes['postal_code']); $showInterviewer = false; if (CRM_Core_Permission::check('administer CiviCampaign')) { $showInterviewer = true; } $form->assign('showInterviewer', $showInterviewer); if ($showInterviewer || $className == 'CRM_Campaign_Form_Gotv') { //autocomplete url $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1', false, null, false); $form->assign('dataUrl', $dataUrl); $form->add('text', 'survey_interviewer_name', ts('Select Interviewer')); $form->add('hidden', 'survey_interviewer_id', '', array('id' => 'survey_interviewer_id')); $userId = null; if (isset($form->_interviewerId) && $form->_interviewerId) { $userId = $form->_interviewerId; } if (!$userId) { $session = CRM_core_Session::singleton(); $userId = $session->get('userID'); } if ($userId) { $defaults = array(); $defaults['survey_interviewer_id'] = $userId; $defaults['survey_interviewer_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userId, 'sort_name', 'id'); $form->setDefaults($defaults); } } //build ward and precinct custom fields. $query = ' SELECT fld.id, fld.label FROM civicrm_custom_field fld INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id WHERE grp.name = %1'; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array('Voter_Info', 'String'))); $customSearchFields = array(); require_once 'CRM/Core/BAO/CustomField.php'; while ($dao->fetch()) { foreach (array('ward', 'precinct') as $name) { if (stripos($name, $dao->label) !== false) { $fieldId = $dao->id; $fieldName = 'custom_' . $dao->id; $customSearchFields[$name] = $fieldName; CRM_Core_BAO_CustomField::addQuickFormElement($form, $fieldName, $fieldId, false, false); break; } } } $form->assign('customSearchFields', $customSearchFields); $surveys = CRM_Campaign_BAO_Survey::getSurveyList(); if (empty($surveys) && $className == 'CRM_Campaign_Form_Search') { CRM_Core_Error::statusBounce(ts('Could not find survey for %1 respondents.', array(1 => $form->get('op'))), CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } $form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, true); }
/** * add all the elements shared between, * normal voter search and voter listing (GOTV form) * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $className = CRM_Utils_System::getClassName($form); $form->add('text', 'sort_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->add('text', 'street_name', ts('Street Name'), $attributes['street_name']); $form->add('text', 'street_number', ts('Street Number'), $attributes['street_number']); $form->add('text', 'street_unit', ts('Street Unit'), $attributes['street_unit']); $form->add('text', 'street_address', ts('Street Address'), $attributes['street_address']); $form->add('text', 'city', ts('City'), $attributes['city']); $form->add('text', 'postal_code', ts('Zip / Postal Code'), $attributes['postal_code']); $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'title' => ts('- select -'))); $groups = CRM_Core_PseudoConstant::group(); $form->add('select', 'group', ts('Groups'), $groups, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -'))); $showInterviewer = FALSE; if (CRM_Core_Permission::check('administer CiviCampaign')) { $showInterviewer = TRUE; } $form->assign('showInterviewer', $showInterviewer); if ($showInterviewer || $className == 'CRM_Campaign_Form_Gotv') { //autocomplete url $dataUrl = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&reset=1', FALSE, NULL, FALSE); $form->assign('dataUrl', $dataUrl); $form->add('text', 'survey_interviewer_name', ts('Interviewer')); $form->add('hidden', 'survey_interviewer_id', '', array('id' => 'survey_interviewer_id')); $userId = NULL; if (isset($form->_interviewerId) && $form->_interviewerId) { $userId = $form->_interviewerId; } if (!$userId) { $session = CRM_core_Session::singleton(); $userId = $session->get('userID'); } if ($userId) { $defaults = array(); $defaults['survey_interviewer_id'] = $userId; $defaults['survey_interviewer_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userId, 'sort_name', 'id'); $form->setDefaults($defaults); } } //build ward and precinct custom fields. $query = ' SELECT fld.id, fld.label FROM civicrm_custom_field fld INNER JOIN civicrm_custom_group grp on fld.custom_group_id = grp.id WHERE grp.name = %1'; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array('Voter_Info', 'String'))); $customSearchFields = array(); while ($dao->fetch()) { foreach (array('ward', 'precinct') as $name) { if (stripos($name, $dao->label) !== FALSE) { $fieldId = $dao->id; $fieldName = 'custom_' . $dao->id; $customSearchFields[$name] = $fieldName; CRM_Core_BAO_CustomField::addQuickFormElement($form, $fieldName, $fieldId, FALSE, FALSE); break; } } } $form->assign('customSearchFields', $customSearchFields); $surveys = CRM_Campaign_BAO_Survey::getSurveys(); if (empty($surveys) && $className == 'CRM_Campaign_Form_Search') { CRM_Core_Error::statusBounce(ts('Could not find survey for %1 respondents.', array(1 => $form->get('op'))), CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } //CRM-7406 -- //If survey had associated campaign and //campaign has some contact groups, don't //allow to search the contacts those are not //in given campaign groups ( ie not in constituents ) $groupJs = NULL; if ($form->get('searchVoterFor') == 'reserve') { $groupJs = array('onChange' => "buildCampaignGroups( );return false;"); } $form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, TRUE, $groupJs); }