class wf_crm_webform_ajax in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 7.4 includes/wf_crm_webform_ajax.inc \wf_crm_webform_ajax
Hierarchy
- class \wf_crm_webform_base
- class \wf_crm_webform_ajax
Expanded class hierarchy of wf_crm_webform_ajax
File
- includes/
wf_crm_webform_ajax.inc, line 10
View source
class wf_crm_webform_ajax extends wf_crm_webform_base {
function __construct() {
civicrm_initialize();
}
/**
* Populate a state list based on chosen country
* @param string $input
*/
function stateProvince($input) {
if (!$input || intval($input) != $input && $input != 'default') {
drupal_json_output([
'' => t('- first choose a country -'),
]);
exit;
}
drupal_json_output(wf_crm_get_states($input));
exit;
}
/**
* Populate a county list based on chosen state
* @param string $input
*/
function county($input) {
if (strpos($input, '-')) {
list($state, $country) = explode('-', $input);
$params = [
'field' => 'county_id',
'state_province_id' => wf_crm_state_abbr($state, 'id', $country),
];
drupal_json_output(wf_crm_apivalues('address', 'getoptions', $params));
exit;
}
}
/**
* Load one or more contacts via ajax
* @param $key
*/
function contactAjax($key) {
module_load_include('inc', 'webform_civicrm', 'includes/contact_component');
if (empty($_GET['str']) && (empty($_GET['load']) || empty($_GET['cid']))) {
exit;
}
list($nid, $fid) = explode('-', $key, 2);
$this->node = node_load($nid);
$this->settings = $this->node->webform_civicrm;
if (!self::autocompleteAccess($this->node, $fid)) {
drupal_access_denied();
}
$this->data = $this->node->webform_civicrm['data'];
$component = $this->node->webform['components'][$fid];
$filters = wf_crm_search_filters($this->node, $component);
// Populate other contact ids for related data
$this->ent += [
'contact' => [],
];
foreach ($_GET as $k => $v) {
if (substr($k, 0, 3) == 'cid' && $v && is_numeric($v)) {
$this->ent['contact'][substr($k, 3)]['id'] = (int) $v;
}
}
// Bypass filters when choosing contact on component edit form
if (!empty($_GET['admin']) && wf_crm_admin_access($this->node)) {
$filters = [
'check_permissions' => 1,
'is_deleted' => 0,
'contact_type' => $filters['contact_type'],
];
$component['extra']['allow_create'] = 0;
}
// Autocomplete contact names
if (!empty($_GET['str'])) {
if ($str = trim($_GET['str'])) {
drupal_json_output(wf_crm_contact_search($this->node, $component, $filters, $this->ent['contact'], $str));
}
exit;
}
// Load contact by id
$data = [];
if ($name = wf_crm_contact_access($component, $filters, $_GET['cid'])) {
if ($_GET['load'] == 'name') {
if ($_GET['cid'][0] === '-') {
// HTML hack to get prompt to show up different than search results
$data = '<em><i>' . filter_xss($component['extra']['none_prompt']) . '</i></em>';
}
else {
$data = $name;
}
}
// Fetch entire contact to populate form via ajax
if ($_GET['load'] == 'full') {
$sp = CRM_Core_DAO::VALUE_SEPARATOR;
$this->enabled = wf_crm_enabled_fields($this->node);
list(, $c, ) = explode('_', $component['form_key'], 3);
$this->ent['contact'][$c]['id'] = (int) $_GET['cid'];
// Redact fields if they are to be hidden unconditionally, otherwise they are needed on the client side
$to_hide = wf_crm_aval($component['extra'], 'hide_method', 'hide') == 'hide' && !wf_crm_aval($component['extra'], 'no_hide_blank') ? $component['extra']['hide_fields'] : [];
$contact = $this
->loadContact($c, $to_hide);
$states = $countries = [];
// Format as json array
foreach ($this->enabled as $fid => $f) {
list(, $i, $ent, $n, $table, $field) = explode('_', $fid, 6);
if ($i == $c && $ent == 'contact' && isset($contact[$table][$n][$field])) {
$type = $table == 'contact' && strpos($field, 'name') ? 'name' : $table;
// Exclude blank and hidden fields
if ($contact[$table][$n][$field] !== '' && $contact[$table][$n][$field] !== [] && !in_array($type, $to_hide)) {
$dataType = wf_crm_aval(wf_crm_get_field("{$table}_{$field}"), 'data_type');
$val = [
'val' => $contact[$table][$n][$field],
];
// Retrieve file info
if ($dataType === 'File') {
$val = $this
->getFileInfo($field, $val['val'], $ent, $n);
}
elseif (is_string($val['val']) && strpos($val['val'], $sp) !== FALSE) {
$val['val'] = wf_crm_explode_multivalue_str($val['val']);
}
$val['fid'] = $fid;
if ($dataType) {
$val['data_type'] = $dataType;
}
if ($field == 'state_province_id') {
$states[] = $val;
}
elseif ($field == 'country_id') {
$countries[] = $val;
}
else {
$data[] = $val;
}
}
}
elseif ($i > $c && $field == 'existing') {
$related_component = $this
->getComponent($fid);
if (wf_crm_aval($related_component['extra'], 'default') == 'relationship') {
$old_related_cid = wf_crm_aval($this->ent, "contact:{$i}:id");
// Don't be fooled by old data
$related_component['extra']['allow_url_autofill'] = FALSE;
unset($this->ent['contact'][$i]);
$this
->findContact($related_component);
$related_cid = wf_crm_aval($this->ent, "contact:{$i}:id");
if ($related_cid && $related_cid != $old_related_cid) {
$data[] = [
'fid' => $fid,
'val' => $related_cid,
'display' => wf_crm_contact_access($related_component, wf_crm_search_filters($this->node, $related_component), $related_cid),
];
}
}
}
}
// We want counties, states and countries in that order to avoid race-conditions client-side
$data = array_merge($data, $states, $countries);
}
}
drupal_json_output($data);
exit;
}
/**
* Access callback. Check if user has permission to view autocomplete results.
*
* @param stdClass $node
* @param int $fid
* Webform component id
* @return bool
*/
public static function autocompleteAccess($node, $fid) {
global $user;
if (!$fid || empty($node->webform_civicrm)) {
return FALSE;
}
if (empty($node->webform['components'][$fid]) || !node_access('view', $node)) {
return FALSE;
}
if ($user->uid === 1 || webform_results_access($node)) {
return TRUE;
}
if (!empty($node->webform['components'][$fid]['private'])) {
return FALSE;
}
if (variable_get('webform_submission_access_control', 1)) {
$allowed_roles = [];
foreach ($node->webform['roles'] as $rid) {
$allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
}
if (array_search(TRUE, $allowed_roles) === FALSE) {
return FALSE;
}
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
wf_crm_webform_ajax:: |
public static | function | Access callback. Check if user has permission to view autocomplete results. | |
wf_crm_webform_ajax:: |
function | Load one or more contacts via ajax | ||
wf_crm_webform_ajax:: |
function | Populate a county list based on chosen state | ||
wf_crm_webform_ajax:: |
function | Populate a state list based on chosen country | ||
wf_crm_webform_ajax:: |
function | |||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
protected | property | ||
wf_crm_webform_base:: |
private | property | ||
wf_crm_webform_base:: |
private | property | ||
wf_crm_webform_base:: |
private | property | ||
wf_crm_webform_base:: |
function | CiviCRM JS can't be attached to a drupal form so have to manually re-add this during validation | ||
wf_crm_webform_base:: |
protected | function | Add location_type_id = NULL for user-select fields for identification later | |
wf_crm_webform_base:: |
function | Find a case matching criteria | ||
wf_crm_webform_base:: |
protected | function | Find an existing contact based on matching criteria Used to populate a webform existing contact field | |
wf_crm_webform_base:: |
protected | function | Get memberships for a contact | |
wf_crm_webform_base:: |
protected | function | Historically webform_civicrm was configured with the live payment processor ID and the is_test flag. But this is not how CiviCRM expects it to work and this can cause problems where payments use the live processor instead of test. So we… | |
wf_crm_webform_base:: |
public | function | FIXME: Use the api for this | |
wf_crm_webform_base:: |
protected | function | Fetch a webform component given its civicrm field key | |
wf_crm_webform_base:: |
protected | function | Get custom data for an entity | |
wf_crm_webform_base:: |
protected | function | ||
wf_crm_webform_base:: |
function | Fetch the public url of a file in the Drupal file system | ||
wf_crm_webform_base:: |
protected | function | For a given field, find the options that are exposed to the webform. | |
wf_crm_webform_base:: |
function | Retrieve info needed for pre-filling a webform file field | ||
wf_crm_webform_base:: |
protected | function | ||
wf_crm_webform_base:: |
public | function | Generate the quickform key needed to access a contribution form | |
wf_crm_webform_base:: |
protected | function | Fetch relationship for a pair of contacts | |
wf_crm_webform_base:: |
protected | function | Put remaining values in 'user-select' fields | |
wf_crm_webform_base:: |
protected | function | Fetch all relevant data for a given contact Used to load contacts for pre-filling a webform, and also to fill in a contact via ajax | |
wf_crm_webform_base:: |
protected | function | Fetch info and remaining spaces for events | |
wf_crm_webform_base:: |
protected | function | Organize values according to location types | |
wf_crm_webform_base:: |
protected | function | Organize values according to website types | |
wf_crm_webform_base:: |
constant | |||
wf_crm_webform_base:: |
protected | function | Reorder returned results according to settings chosen in wf_civicrm backend | |
wf_crm_webform_base:: |
public static | function | Copies a drupal file into the Civi file system | |
wf_crm_webform_base:: |
function | Magic method to retrieve otherwise inaccessible properties |