View source
<?php
module_load_include('inc', 'webform_civicrm', 'includes/utils');
abstract class wf_crm_webform_base {
protected $node;
protected $settings = array();
protected $enabled = array();
protected $data = array();
protected $ent = array();
protected $events = array();
protected $line_items = array();
protected $membership_types = array();
protected $loadedContacts = array();
private $_payment_processor;
private $_contribution_page;
private $_tax_rate;
const MULTIVALUE_FIELDSET_MODE_CREATE_OR_EDIT = 0, MULTIVALUE_FIELDSET_MODE_CREATE_ONLY = 1;
function __get($name) {
switch ($name) {
case 'payment_processor':
$payment_processor_id = wf_crm_aval($this->data, 'contribution:1:contribution:1:payment_processor_id');
if ($payment_processor_id && !$this->_payment_processor) {
$this->_payment_processor = wf_civicrm_api('payment_processor', 'getsingle', array(
'id' => $payment_processor_id,
));
}
return $this->_payment_processor;
case 'contribution_page':
$contribution_page_id = wf_crm_aval($this->data, 'contribution:1:contribution:1:contribution_page_id');
if ($contribution_page_id && !$this->_contribution_page) {
$this->_contribution_page = wf_civicrm_api('contribution_page', 'getsingle', array(
'id' => $contribution_page_id,
));
}
return $this->_contribution_page;
case 'tax_rate':
$taxSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
if (is_array($taxSettings) && !empty($taxSettings['invoicing'])) {
if ($this->contribution_page) {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$this->_tax_rate = isset($taxRates[$this->_contribution_page['financial_type_id']]) ? $taxRates[$this->_contribution_page['financial_type_id']] : NULL;
}
return $this->_tax_rate;
}
return NULL;
case 'civicrm_version':
return CRM_Utils_System::version();
default:
throw new Exception('Unknown property');
}
}
protected function loadContact($c, $exclude = array()) {
if (!empty($this->loadedContacts[$c])) {
return $this->loadedContacts[$c];
}
$info = array();
$cid = $this->ent['contact'][$c]['id'];
if (!$cid) {
return $info;
}
$contact = $this->data['contact'][$c];
$prefix = 'civicrm_' . $c . '_contact_1_';
$existing_contact_field = $this
->getComponent($prefix . 'contact_existing');
$exclude = array_merge($exclude, wf_crm_aval($existing_contact_field['extra'], 'no_autofill', array()));
foreach (array_merge(array(
'contact',
), wf_crm_location_fields()) as $ent) {
if (!empty($contact['number_of_' . $ent]) && !in_array($ent, $exclude) || $ent == 'contact') {
$params = array(
'contact_id' => $cid,
);
if ($ent != 'contact' && $ent != 'website') {
$params['options']['sort'] = 'is_primary DESC';
}
$result = wf_civicrm_api($ent, 'get', $params);
if (in_array($ent, wf_crm_location_fields())) {
$result['values'] = $this
->reorderByLocationType($c, $ent, $result['values']);
}
if (!empty($result['values'])) {
$result = array_merge(array(
0,
), array_values($result['values']));
unset($result[0]);
if ($ent == 'contact') {
if (in_array('name', $exclude)) {
unset($result[1]['first_name'], $result[1]['middle_name'], $result[1]['last_name'], $result[1]['formal_title'], $result[1]['prefix_id'], $result[1]['suffix_id'], $result[1]['nick_name'], $result[1]['organization_name'], $result[1]['household_name']);
}
if (isset($this->enabled[$prefix . 'contact_privacy'])) {
foreach (array_keys(wf_crm_get_privacy_options()) as $key) {
if (!empty($result[1][$key])) {
$result[1]['privacy'][] = $key;
}
}
}
if (isset($this->enabled[$prefix . 'contact_user_id'])) {
$result[1]['user_id'] = wf_crm_user_cid($cid, 'contact');
}
$gender_field = $this
->getComponent("civicrm_{$c}_contact_1_contact_gender_id");
if ($gender_field && $gender_field['type'] == 'textfield') {
$result[1]['gender_id'] = wf_crm_aval($result[1], 'gender');
}
}
if ($ent == 'address') {
foreach ($result as &$address) {
if (!empty($address['state_province_id'])) {
$address['state_province_id'] = wf_crm_state_abbr($address['state_province_id']);
}
if (isset($address['id'])) {
$custom = $this
->getCustomData($address['id'], 'address');
if (!empty($custom['address'])) {
$address += $custom['address'][1];
}
}
}
}
$info[$ent] = $result;
}
}
}
foreach ($contact as $k => $v) {
if (substr($k, 0, 12) == 'number_of_cg' && !empty($v)) {
if (!in_array(substr($k, 10), $exclude)) {
$info += $this
->getCustomData($cid);
break;
}
}
}
if (!in_array('other', $exclude)) {
$api = array(
'tag' => 'entity_tag',
'group' => 'group_contact',
);
foreach (array_keys($this->enabled) as $fid) {
if (strpos($fid, $prefix . 'other') !== FALSE) {
list(, , , , , $ent) = explode('_', $fid);
list(, , , , , $field) = explode('_', $fid, 6);
if (!is_array($api[$ent])) {
$api[$ent] = wf_civicrm_api($api[$ent], 'get', array(
'contact_id' => $cid,
));
}
foreach (wf_crm_aval($api[$ent], 'values') as $val) {
$info['other'][1][$field][] = $val[$ent . '_id'];
}
}
}
}
if (!in_array('relationship', $exclude) && !empty($contact['number_of_relationship'])) {
$this->enabled = wf_crm_enabled_fields($this->node);
for ($r = 1; $r <= $contact['number_of_relationship']; ++$r) {
$types = array();
$prefix = "civicrm_{$c}_contact_{$r}_relationship_";
if (!empty($this->ent['contact'][$r]['id'])) {
if (!empty($contact['relationship'][$r]['relationship_type_id']) && $contact['relationship'][$r]['relationship_type_id'] != 'create_civicrm_webform_element') {
$types = (array) $contact['relationship'][$r]['relationship_type_id'];
}
if (!empty($this->enabled[$prefix . 'relationship_type_id'])) {
$types += array_keys($this
->getExposedOptions($prefix . 'relationship_type_id'));
}
}
$rel = $this
->getRelationship($types, $cid, wf_crm_aval($this->ent['contact'], "{$r}:id"));
if ($rel) {
$info['relationship'][$r] = $rel;
$len = strlen($prefix . 'custom_');
foreach ($this->enabled as $k => $v) {
if (substr($k, 0, $len) == $prefix . 'custom_') {
$custom = wf_civicrm_api('custom_value', 'get', array(
'entity_id' => $rel['id'],
'entity_table' => 'Relationship',
));
foreach ($custom['values'] as $k => $v) {
if (isset($v[0])) {
$info['relationship'][$r]["custom_{$k}"] = $v[0];
}
}
break;
}
}
}
}
}
$this->loadedContacts[$c] = $info;
return $info;
}
protected function findContact($component) {
module_load_include('inc', 'webform_civicrm', 'includes/contact_component');
list(, $c, ) = explode('_', $component['form_key'], 3);
$filters = wf_crm_search_filters($this->node, $component);
if (isset($_GET["cid{$c}"]) || $c == 1 && isset($_GET['cid'])) {
$cid = isset($_GET["cid{$c}"]) ? $_GET["cid{$c}"] : $_GET['cid'];
if (wf_crm_is_positive($cid) || $cid === '0' || $cid === 0) {
$cid = (int) $cid;
if ($cid === 0) {
$this->ent['contact'][$c]['id'] = $cid;
return;
}
elseif (wf_crm_aval($component['extra'], 'allow_url_autofill', TRUE, TRUE)) {
if (wf_crm_contact_access($component, $filters, $cid) !== FALSE) {
$this->ent['contact'][$c]['id'] = $cid;
}
}
}
}
if (empty($this->ent['contact'][$c]['id'])) {
$found = array();
switch ($component['extra']['default']) {
case 'user':
$cid = wf_crm_user_cid();
$found = $c == 1 && $cid ? array(
$cid,
) : array();
break;
case 'contact_id':
if ($component['extra']['default_contact_id']) {
$found = array(
$component['extra']['default_contact_id'],
);
}
break;
case 'relationship':
$to = $component['extra']['default_relationship_to'];
if (!empty($this->ent['contact'][$to]['id']) && !empty($component['extra']['default_relationship'])) {
$found = wf_crm_find_relations($this->ent['contact'][$to]['id'], $component['extra']['default_relationship']);
}
break;
case 'custom_ref':
$to = $component['extra']['default_relationship_to'];
if (!empty($this->ent['contact'][$to]['id'])) {
$found = wf_crm_find_custom_refs($this->ent['contact'][$to]['id'], $component['extra']['default_custom_ref']);
}
break;
case 'case_roles':
$to = $component['extra']['default_relationship_to'];
$case = $component['extra']['default_for_case'];
if (empty($this->ent['contact'][$c]['id'])) {
$this
->findCaseClientForDefaultContact($c);
}
if (!empty($this->ent['contact'][$to]['id']) && !empty($this->ent['case'][$case]['id'])) {
$found = wf_crm_find_case_roles($this->ent['contact'][$to]['id'], $this->ent['case'][$case]['id'], $component['extra']['default_case_roles']);
unset($this->ent['contact'][$c]['reload']);
}
else {
$this->ent['contact'][$c]['reload'] = TRUE;
}
break;
case 'auto':
$component['extra']['allow_create'] = FALSE;
$found = array_keys(wf_crm_contact_search($this->node, $component, $filters, wf_crm_aval($this->ent, 'contact', array())));
break;
}
if ($component['extra']['randomize']) {
shuffle($found);
}
if (in_array($component['extra']['default'], array(
'user',
'contact_id',
))) {
$dupes_allowed = TRUE;
}
else {
$dupes_allowed = $component['extra']['dupes_allowed'];
}
foreach ($found as $cid) {
if (!$dupes_allowed) {
foreach ($this->ent['contact'] as $contact) {
if (!empty($contact['id']) && $cid == $contact['id']) {
continue 2;
}
}
}
if ($component['extra']['default'] == 'auto' || wf_crm_contact_access($component, $filters, $cid) !== FALSE) {
$this->ent['contact'][$c]['id'] = $cid;
break;
}
}
}
}
protected function reorderByLocationType($c, $ent, $values = array()) {
$reorderedArray = array();
if (isset($this->settings['data']['contact'][$c][$ent])) {
if ($ent == 'website') {
$reorderedArray = $this
->matchWebsiteTypes($c, $ent, $values);
}
else {
$reorderedArray = $this
->matchLocationTypes($c, $ent, $values);
}
$reorderedArray = $this
->handleRemainingValues($reorderedArray, $values);
return $reorderedArray;
}
else {
return $values;
}
}
protected function matchLocationTypes($c, $ent, &$values) {
$settingsArray = $this
->add_user_select_field_placeholder($ent, $this->settings['data']['contact'][$c]);
$userSelectIndex = 0;
foreach ($settingsArray[$ent] as $setting) {
$valueFound = false;
foreach ($values as $key => $value) {
if (in_array($ent, array(
'address',
'email',
)) && $value['location_type_id'] == $setting['location_type_id'] || $value['location_type_id'] == $setting['location_type_id'] && (!isset($setting[$ent . '_type_id']) || $value[$ent . '_type_id'] == $setting[$ent . '_type_id'])) {
$reorderedArray[$key] = $value;
$valueFound = true;
unset($values[$key]);
break;
}
else {
if (empty($setting['location_type_id'])) {
$valueFound = true;
$reorderedArray['us' . $userSelectIndex] = 'user-select';
$userSelectIndex++;
break;
}
}
}
if (!$valueFound) {
$reorderedArray[] = array();
}
}
return $reorderedArray;
}
protected function matchWebsiteTypes($c, $ent, &$values) {
$settingsArray = $this
->add_user_select_field_placeholder($ent, $this->settings['data']['contact'][$c]);
$userSelectIndex = 0;
foreach ($settingsArray[$ent] as $setting) {
$valueFound = FALSE;
foreach ($values as $key => $value) {
if ($value[$ent . '_type_id'] == $setting[$ent . '_type_id']) {
$reorderedArray[$key] = $value;
$valueFound = TRUE;
unset($values[$key]);
break;
}
else {
if (empty($setting['website_type_id'])) {
$valueFound = TRUE;
$reorderedArray['us' . $userSelectIndex] = 'user-select';
$userSelectIndex++;
break;
}
}
}
if (!$valueFound) {
$reorderedArray[] = array();
}
}
return $reorderedArray;
}
protected function handleRemainingValues($reorderedArray, &$values) {
foreach ($reorderedArray as $key => $value) {
if ($reorderedArray[$key] == 'user-select') {
$reorderedArray[$key] = !empty($values) ? array_shift($values) : '';
}
}
return $reorderedArray;
}
protected function add_user_select_field_placeholder($ent, $settings = array()) {
if ($settings['number_of_' . $ent] > count($settings[$ent])) {
for ($i = 1; $i <= $settings['number_of_' . $ent]; $i++) {
if (!array_key_exists($i, $settings[$ent])) {
$settings[$ent][$i]['location_type_id'] = NULL;
}
}
ksort($settings[$ent]);
}
return $settings;
}
protected function getRelationship($r_types, $cid1, $cid2) {
$found = array();
$active_clause = '';
if (!empty($this->settings['create_new_relationship'])) {
$active_clause = 'AND is_active = 1 AND (end_date IS NULL OR end_date >= now())';
}
if ($r_types && $cid1 && $cid2) {
$types = array();
foreach ($r_types as $r_type) {
list($type, $side) = explode('_', $r_type);
$types[$type] = $type;
}
$sql = "SELECT * FROM civicrm_relationship\n WHERE relationship_type_id IN (" . implode(',', $types) . ")\n AND ((contact_id_a = {$cid1} AND contact_id_b = {$cid2}) OR (contact_id_a = {$cid2} AND contact_id_b = {$cid1})) {$active_clause}\n ORDER BY is_active DESC, IF(end_date, 1, 0), end_date DESC";
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao
->fetch()) {
$type = $dao->relationship_type_id;
$side = $dao->contact_id_a == $cid1 ? 'a' : 'b';
if (in_array("{$type}_{$side}", $r_types) || in_array("{$type}_r", $r_types)) {
foreach ((array) $dao as $k => $v) {
if ($k[0] != '_' && $k != 'N' && $k != 'relationship_type_id') {
$found[$k] = $v;
}
}
$found['relationship_type_id'][] = in_array("{$type}_r", $r_types) ? "{$type}_r" : "{$type}_{$side}";
$found['relationship_permission'] = ($found['is_permission_a_b'] ? 1 : 0) + ($found['is_permission_b_a'] ? 2 : 0);
}
}
$dao
->free();
}
return $found;
}
protected function getExposedOptions($field_key, $exclude = array()) {
$field = $this
->getComponent($field_key);
if ($field && $field['type'] == 'hidden') {
$exposed = wf_crm_field_options($field, 'live_options', $this->data);
foreach ($exclude as $i) {
unset($exposed[$i]);
}
return $exposed;
}
if ($field && $field['type'] == 'select') {
if (empty($field['extra']['civicrm_live_options'])) {
$exposed = wf_crm_str2array($field['extra']['items']);
}
else {
$exposed = wf_crm_field_options($field, 'live_options', $this->data);
}
foreach ($exclude as $i) {
unset($exposed[$i]);
}
return $exposed;
}
return array();
}
protected function getComponent($field_key) {
if ($field_key && isset($this->enabled[$field_key])) {
return wf_crm_aval($this->node->webform, 'components:' . $this->enabled[$field_key]);
}
return NULL;
}
protected function findMemberships($cid) {
static $status_types;
static $membership_types;
if (!isset($membership_types)) {
$membership_types = array_keys(wf_crm_apivalues('membershipType', 'get', array(
'is_active' => 1,
'return' => 'id',
)));
}
$existing = wf_crm_apivalues('membership', 'get', array(
'contact_id' => $cid,
'membership_type_id' => array(
'IN' => $membership_types,
),
));
if (!$existing) {
return array();
}
if (!$status_types) {
$status_types = wf_crm_apivalues('membership_status', 'get');
}
$active = $expired = array();
foreach ($existing as $membership) {
$membership['is_active'] = $status_types[$membership['status_id']]['is_current_member'];
$membership['status'] = $status_types[$membership['status_id']]['label'];
$list = $membership['is_active'] ? 'active' : 'expired';
array_unshift(${$list}, $membership);
}
return array_merge($active, $expired);
}
protected function loadEvents() {
if (!empty($this->events)) {
$now = time();
$dao = CRM_Core_DAO::executeQuery('SELECT id, title, start_date, end_date, event_type_id, max_participants, financial_type_id
FROM civicrm_event WHERE id IN (' . implode(',', array_keys($this->events)) . ')');
while ($dao
->fetch()) {
$this->events[$dao->id]['title'] = $dao->title;
$this->events[$dao->id]['start_date'] = $dao->start_date;
$this->events[$dao->id]['end_date'] = $dao->end_date;
$this->events[$dao->id]['event_type_id'] = $dao->event_type_id;
$this->events[$dao->id]['financial_type_id'] = $dao->financial_type_id;
$this->events[$dao->id]['full'] = FALSE;
$this->events[$dao->id]['ended'] = $dao->end_date && strtotime($dao->end_date) < $now;
if ($this->events[$dao->id]['max_participants'] = $dao->max_participants) {
$remaining = CRM_Event_BAO_Participant::eventFull($dao->id, TRUE, FALSE);
if (is_string($remaining)) {
$this->events[$dao->id]['full'] = TRUE;
$this->events[$dao->id]['remaining'] = 0;
$this->events[$dao->id]['full_message'] = $remaining;
}
else {
$this->events[$dao->id]['remaining'] = $remaining ? $remaining : $dao->max_participants;
}
}
}
$dao
->free();
}
}
protected function getCustomData($entity_id, $entity_type = NULL, $normalize = TRUE) {
static $parents = array();
if (empty($parents)) {
foreach (wf_crm_get_fields() as $key => $value) {
list($group, $field) = explode('_', $key, 2);
if (substr($field, 0, 7) == 'custom_') {
$parents[$field] = $group;
}
}
}
$params = array(
'entityID' => $entity_id,
);
if ($entity_type) {
$params['entityType'] = ucfirst($entity_type);
}
$result = CRM_Core_BAO_CustomValueTable::getValues($params);
if (!empty($result['is_error'])) {
return array();
}
unset($result['is_error'], $result['entityID']);
$values = array();
foreach ($result as $key => $value) {
$pieces = explode('_', $key);
if ($pieces[0] == 'custom') {
$name = 'custom_' . $pieces[1];
if (empty($pieces[2])) {
$pieces[2] = $normalize ? 1 : 0;
}
if (isset($parents[$name])) {
$values[$parents[$name]][$pieces[2]][$name] = $value;
}
}
}
if ($normalize) {
foreach ($values as &$value) {
array_unshift($value, 0);
unset($value[0]);
}
}
return $values;
}
protected function saveCustomData($entity, $entity_id, $entity_type, $known = TRUE, $contact_index = 1) {
$existing = FALSE;
$params = array(
'entityID' => $entity_id,
);
$createMultiValues = array();
foreach ($entity as $table => $values) {
if (substr($table, 0, 2) == 'cg' && is_array($values)) {
if ($existing === FALSE) {
$existing = $this
->getCustomData($entity_id, $entity_type, FALSE);
}
$existing += array(
$table => array(),
);
$insert = 0;
foreach ($values as $valuesIndex => $custom) {
if ($id = each($existing[$table])) {
$suf = $id['key'];
}
else {
$suf = --$insert;
}
$multivaluesCreateMode = NULL;
if ($entity_type === 'Contact') {
$createModeKey = 'civicrm_' . $contact_index . '_contact_' . $valuesIndex . '_' . $table . '_createmode';
$multivaluesCreateMode = isset($this->data['config']['create_mode'][$createModeKey]) ? (int) $this->data['config']['create_mode'][$createModeKey] : NULL;
}
$multiValueSuffix = '_' . $suf;
if ($multivaluesCreateMode === self::MULTIVALUE_FIELDSET_MODE_CREATE_ONLY) {
$multiValueSuffix = '';
}
$customGroupParams = array();
foreach ($custom as $k => $v) {
if ($v !== '' || $suf >= 0 && $known) {
$customGroupParams[$k . $multiValueSuffix] = $v;
}
}
if ($multivaluesCreateMode === self::MULTIVALUE_FIELDSET_MODE_CREATE_ONLY) {
$createMultiValues[] = $customGroupParams;
}
else {
$params = array_merge($params, $customGroupParams);
}
}
}
}
if (count($params) > 1) {
$this
->saveCustomValues($entity_id, $params);
}
if (!empty($createMultiValues)) {
foreach ($createMultiValues as $multiValuesSet) {
$this
->saveCustomValues($entity_id, array_merge($multiValuesSet, array(
'entityID' => $entity_id,
)), TRUE);
}
}
}
protected function saveCustomValues($entity_id, array $params, $skipEmpty = FALSE) {
if ($skipEmpty) {
foreach ($params as $key => $value) {
$checkValue = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $value);
if (empty($checkValue)) {
unset($params[$key]);
}
}
}
$result = CRM_Core_BAO_CustomValueTable::setValues($params);
if (!empty($result['is_error'])) {
$bt = debug_backtrace();
array_shift($params);
foreach ($params as $k => $v) {
$single_param = array(
'entityID' => $entity_id,
$k => $v,
);
$result = CRM_Core_BAO_CustomValueTable::setValues($single_param);
if (!empty($result['is_error'])) {
$file = explode('/', $bt[0]['file']);
watchdog('webform_civicrm', 'The CiviCRM "CustomValueTable::setValues" function returned the error: "%msg" when called by line !line of !file with the following parameters: "!params"', array(
'%msg' => $result['error_message'],
'!line' => $bt[0]['line'],
'!file' => array_pop($file),
'!params' => print_r($single_param, TRUE),
), WATCHDOG_ERROR);
}
}
}
}
protected function getData($fid, $default = NULL, $strict = FALSE) {
if ($pieces = wf_crm_explode_key($fid)) {
list(, $c, $ent, $n, $table, $name) = $pieces;
return wf_crm_aval($this->data, "{$ent}:{$c}:{$table}:{$n}:{$name}", $default, $strict);
}
}
function findCaseForContact($cid, $filters) {
$case = NULL;
foreach (wf_crm_apivalues('case', 'get', array(
'client_id' => $cid,
)) as $item) {
if (empty($item['is_deleted'])) {
$match = TRUE;
foreach (array_filter($filters) as $filter => $value) {
if (!array_intersect((array) $item[$filter], (array) $value)) {
$match = FALSE;
}
}
if ($match) {
$case = $item;
}
}
}
return $case;
}
protected function getMembershipTypeField($type, $field) {
if (!$this->membership_types) {
$this->membership_types = wf_crm_apivalues('membership_type', 'get');
}
return wf_crm_aval($this->membership_types, $type . ':' . $field);
}
function addPaymentJs() {
$currentVer = CRM_Core_BAO_Domain::version();
if (version_compare($currentVer, '5.8') <= 0 && method_exists('CRM_Core_Payment_Form', 'getCreditCardCSSNames')) {
$credit_card_types = CRM_Core_Payment_Form::getCreditCardCSSNames();
CRM_Core_Resources::singleton()
->addCoreResources()
->addSetting(array(
'config' => array(
'creditCardTypes' => $credit_card_types,
),
))
->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', -10, 'html-header');
}
else {
CRM_Core_Resources::singleton()
->addCoreResources();
CRM_Financial_Form_Payment::addCreditCardJs(NULL, 'html-header');
}
}
public static function saveDrupalFileToCivi($id) {
$file = file_load($id);
if ($file) {
$config = CRM_Core_Config::singleton();
$path = file_unmanaged_copy($file->uri, $config->customFileUploadDir);
if ($path) {
$result = wf_civicrm_api('file', 'create', array(
'uri' => str_replace($config->customFileUploadDir, '', $path),
'mime_type' => $file->filemime,
));
return wf_crm_aval($result, 'id');
}
}
return NULL;
}
function getFileInfo($fieldName, $val, $entity, $n) {
if (!$val) {
return NULL;
}
if ($fieldName === 'image_URL') {
return array(
'data_type' => 'File',
'name' => NULL,
'icon' => $val,
);
}
$file = wf_crm_apivalues('file', 'get', $val);
$entity_id = '';
if ($entity && $n && (strpos($fieldName, 'custom_') === 0 || strpos($fieldName, 'file_') === 0)) {
$entity_id = $this->ent[$entity][$n]['id'];
}
if (!empty($file[$val])) {
$fileHash = is_callable(array(
'CRM_Core_BAO_File',
'generateFileHash',
)) ? '&fcs=' . CRM_Core_BAO_File::generateFileHash($entity_id, $val) : '';
return array(
'data_type' => 'File',
'name' => CRM_Utils_File::cleanFileName($file[$val]['uri']),
'file_url' => CRM_Utils_System::url('civicrm/file', "reset=1&id={$val}&eid={$entity_id}{$fileHash}", TRUE),
'icon' => file_icon_url((object) array(
'filemime' => $file[$val]['mime_type'],
)),
);
}
return NULL;
}
function getDrupalFileUrl($id) {
$file = file_load($id);
return $file ? file_create_url($file->uri) : FALSE;
}
public function getAttachments($ent, $id) {
$n = 1;
$attachments = array();
$dao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_entity_file WHERE entity_table = 'civicrm_{$ent}' AND entity_id = {$id}");
while ($dao
->fetch()) {
$attachments[$n++] = array(
'id' => $dao->id,
'file_id' => $dao->file_id,
);
}
return $attachments;
}
public function getQfKey() {
return CRM_Core_Key::get('CRM_Contribute_Controller_Contribution', TRUE);
}
}