/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; if ($this->_surveyId) { if (!empty($defaults['result_id']) && !empty($defaults['recontact_interval'])) { $resultId = $defaults['result_id']; $recontactInterval = unserialize($defaults['recontact_interval']); unset($defaults['recontact_interval']); $defaults['option_group_id'] = $resultId; } } if (!isset($defaults['is_active'])) { $defaults['is_active'] = 1; } $defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE); if (!isset($defaults['is_default']) && empty($defaultSurveys)) { $defaults['is_default'] = 1; } return $defaults; }
/** * Add all the elements shared between, * normal voter search and voter listing (GOTV form) * * @param CRM_Core_Form $form */ public 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('Postal Code'), $attributes['postal_code']); //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form // this is loaded onto then replace with something like '__' & test $separator = CRM_Core_DAO::VALUE_SEPARATOR; $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, $separator); $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2')); $groups = CRM_Core_PseudoConstant::nestedGroup(); $form->add('select', 'group', ts('Groups'), $groups, FALSE, array('multiple' => 'multiple', 'class' => 'crm-select2')); $showInterviewer = FALSE; if (CRM_Core_Permission::check('administer CiviCampaign')) { $showInterviewer = TRUE; } $form->assign('showInterviewer', $showInterviewer); if ($showInterviewer || $className == 'CRM_Campaign_Form_Gotv') { $form->addEntityRef('survey_interviewer_id', ts('Interviewer'), array('class' => 'big')); $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; $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); 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 ) $props = array('class' => 'crm-select2'); if ($form->get('searchVoterFor') == 'reserve') { $props['onChange'] = "buildCampaignGroups( );return false;"; } $form->add('select', 'campaign_survey_id', ts('Survey'), $surveys, TRUE, $props); }
/** * Add all the elements shared between case activity search and advanced search. * * * @param CRM_Core_Form $form * @return void */ public static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); $form->addSelect('activity_type_id', array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $followUpActivity = array(1 => ts('Yes'), 2 => ts('No')); $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $activityRoles = array(3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by')); $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); $form->setDefaults(array('activity_role' => 3)); $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); $form->addSelect('status_id', array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addYesNo('activity_test', ts('Activity is a Test?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), array('' => ts('- none -')) + $surveys, FALSE, array('class' => 'crm-select2')); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); $resultOptions = array(); foreach ($optionGroups as $gid => $name) { if ($name) { $value = array(); $value = CRM_Core_OptionGroup::values($name); if (!empty($value)) { while (list($k, $v) = each($value)) { $resultOptions[$v] = $v; } } } } // If no survey result options have been created, don't build // the field to avoid clutter. if (count($resultOptions) > 0) { $buildSurveyResult = TRUE; asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2')); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); }
/** * Alter display of rows. * * Iterate through the rows retrieved via SQL and make changes for display purposes, * such as rendering contacts as links. * * @param array $rows * Rows generated by SQL, with an array for each row. */ public function alterDisplay(&$rows) { $this->_formatSurveyResult($rows); $this->_formatSurveyResponseData($rows); $entryFound = FALSE; foreach ($rows as $rowNum => $row) { // handle state province if (array_key_exists('civicrm_address_state_province_id', $row)) { if ($value = $row['civicrm_address_state_province_id']) { $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value); } $entryFound = TRUE; } // handle country if (array_key_exists('civicrm_address_country_id', $row)) { if ($value = $row['civicrm_address_country_id']) { $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value); } $entryFound = TRUE; } // convert display name to links if (array_key_exists('civicrm_contact_sort_name', $row) && array_key_exists('civicrm_contact_id', $row)) { $url = CRM_Report_Utils_Report::getNextUrl('contact/detail', 'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'], $this->_absoluteUrl, $this->_id, $this->_drilldownReport); $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url; $entryFound = TRUE; } if (array_key_exists('civicrm_activity_contact_contact_id', $row)) { $rows[$rowNum]['civicrm_activity_contact_contact_id'] = CRM_Utils_Array::value($row['civicrm_activity_contact_contact_id'], CRM_Campaign_BAO_Survey::getInterviewers()); $entryFound = TRUE; } if (array_key_exists('civicrm_activity_survey_id', $row)) { $rows[$rowNum]['civicrm_activity_survey_id'] = CRM_Utils_Array::value($row['civicrm_activity_survey_id'], CRM_Campaign_BAO_Survey::getSurveys()); $entryFound = TRUE; } // skip looking further in rows, if first row itself doesn't // have the column we need if (!$entryFound) { break; } } }
public function validateIds() { $errorMessages = array(); //check for required permissions. if (!CRM_Core_Permission::check('manage campaign') && !CRM_Core_Permission::check('administer CiviCampaign') && !CRM_Core_Permission::check("{$this->_searchVoterFor} campaign contacts")) { $errorMessages[] = ts('You are not authorized to access this page.'); } $surveys = CRM_Campaign_BAO_Survey::getSurveys(); if (empty($surveys)) { $errorMessages[] = ts("Oops. It looks like no surveys have been created. <a href='%1'>Click here to create a new survey.</a>", array(1 => CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add'))); } if ($this->_force && !$this->_surveyId) { $errorMessages[] = ts('Could not find Survey.'); } $this->assign('errorMessages', empty($errorMessages) ? FALSE : $errorMessages); }
public function fixFormValues() { // if this search has been forced // then see if there are any get values, and if so over-ride the post values // note that this means that GET over-rides POST :) //since we have qfKey, no need to manipulate set defaults. $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject); if (!$this->_force || CRM_Utils_Rule::qfKey($qfKey)) { return; } // get survey id $surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', CRM_Core_DAO::$_nullObject); if ($surveyId) { $surveyId = CRM_Utils_Type::escape($surveyId, 'Integer'); } else { // use default survey id $surveyId = key(CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE)); } if (!$surveyId) { CRM_Core_Error::fatal('Could not find valid Survey Id.'); } $this->_formValues['campaign_survey_id'] = $this->_formValues['campaign_survey_id'] = $surveyId; $session = CRM_Core_Session::singleton(); $userId = $session->get('userID'); // get interviewer id $cid = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, $userId); //to force other contact as interviewer, user should be admin. if ($cid != $userId && !CRM_Core_Permission::check('administer CiviCampaign')) { CRM_Utils_System::permissionDenied(); CRM_Utils_System::civiExit(); } $this->_formValues['survey_interviewer_id'] = $cid; //get all in defaults. $this->_defaults = $this->_formValues; $this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this); }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { $defaults = $this->_values; $ufContactJoinParams = array('entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 2); if ($ufContactGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufContactJoinParams)) { $defaults['contact_profile_id'] = $ufContactGroupId; } $ufActivityJoinParams = array('entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 1); if ($ufActivityGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufActivityJoinParams)) { $defaults['profile_id'] = $ufActivityGroupId; } if (!isset($defaults['is_active'])) { $defaults['is_active'] = 1; } $defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE); if (!isset($defaults['is_default']) && empty($defaultSurveys)) { $defaults['is_default'] = 1; } return $defaults; }
/** * 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', 'class' => 'crm-select2')); $groups = CRM_Core_PseudoConstant::group(); $form->add('select', 'group', ts('Groups'), $groups, FALSE, array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')); $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); }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @param null * * @return array array of default values * @access public */ function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; if ($this->_surveyId) { if (CRM_Utils_Array::value('result_id', $defaults) && CRM_Utils_Array::value('recontact_interval', $defaults)) { $resultId = $defaults['result_id']; $recontactInterval = unserialize($defaults['recontact_interval']); unset($defaults['recontact_interval']); $defaults['option_group_id'] = $resultId; } $ufJoinParams = array('entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId, 'weight' => 1); if ($ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams)) { $defaults['profile_id'] = $ufGroupId; } } if (!isset($defaults['is_active'])) { $defaults['is_active'] = 1; } // set defaults for weight. for ($i = 1; $i <= self::NUM_OPTION; $i++) { $defaults["option_weight[{$i}]"] = $i; } $defaultSurveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, TRUE); if (!isset($defaults['is_default']) && empty($defaultSurveys)) { $defaults['is_default'] = 1; } return $defaults; }
/** * add all the elements shared between case activity search and advanaced search * * @access public * * @return void * @static */ static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); asort($activityOptions); foreach ($activityOptions as $activityID => $activity) { $form->_activityElement =& $form->addElement('checkbox', "activity_type_id[{$activityID}]", NULL, $activity, array('onClick' => 'showCustomData( this.id );')); } CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $activityRoles = array(1 => ts('Created by'), 2 => ts('Assigned to')); $form->addRadio('activity_role', NULL, $activityRoles, NULL, '<br />'); $form->addElement('text', 'activity_contact_name', ts('Contact Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $activityStatus = CRM_Core_PseudoConstant::activityStatus(); foreach ($activityStatus as $activityStatusID => $activityStatusName) { $activity_status[] = $form->createElement('checkbox', $activityStatusID, NULL, $activityStatusName); } $form->addGroup($activity_status, 'activity_status', ts('Activity Status')); $form->setDefaults(array('activity_status[1]' => 1, 'activity_status[2]' => 1)); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addElement('checkbox', 'activity_test', ts('Find Test Activities?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey'), array('' => ts('- none -')) + $surveys, FALSE); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->add('select', 'activity_engagement_level', ts('Engagement Index'), array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel()); } $form->assign('buildEngagementLevel', $buildEngagementLevel); }