function _merci_staff_potential_references_standard in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6.2
Same name and namespace in other branches
- 8.2 modules/merci_staff/merci_staff.module \_merci_staff_potential_references_standard()
- 7.2 modules/merci_staff/merci_staff.module \_merci_staff_potential_references_standard()
Helper function for _civicrm_cck_potential_references(): referenceable nodes defined by content types.
1 call to _merci_staff_potential_references_standard()
- _merci_staff_potential_references in modules/
merci_staff/ merci_staff.module
File
- modules/
merci_staff/ merci_staff.module, line 208 - merci_staff functions
Code
function _merci_staff_potential_references_standard($field, $string = '', $exact_string = FALSE, $limit = '10') {
$args = $whereClause = $contactTypes = $contactSubTypes = array();
if (!civicrm_initialize()) {
return;
}
require_once 'CRM/Contact/BAO/ContactType.php';
require_once 'CRM/Core/BAO/UFMatch.php';
$basicTypes = CRM_Contact_BAO_ContactType::basicTypePairs();
foreach ($basicTypes as $name => $label) {
if (is_array($field[$name])) {
$contactNames = array_filter($field[$name]);
if (!empty($contactNames)) {
if (in_array($name, $contactNames)) {
$contactTypes[] = $name;
}
else {
$contactSubTypes = array_merge($contactSubTypes, array_keys($contactNames));
}
}
}
}
if (!empty($contactTypes)) {
$contactTypes = implode("','", $contactTypes);
$whereClause[] = "contact_type IN ( '{$contactTypes}' )";
}
if (!empty($contactSubTypes)) {
$contactSubTypes = implode("','", $contactSubTypes);
$whereClause[] = "contact_sub_type IN ( '{$contactSubTypes}' )";
}
$whereClause = empty($whereClause) ? '' : '(' . implode(' OR ', $whereClause) . ') AND';
$related_clause = "";
if (isset($string)) {
if ($exact_string) {
$string_clause = " AND display_name = %1";
$args[] = $string;
}
else {
$string_clause = " AND display_name LIKE %1";
$args[] = "%%" . $string . "%";
}
}
$q = "\n SELECT civicrm_contact.id, display_name\n FROM civicrm_contact\n JOIN civicrm_uf_match ON civicrm_contact.id = civicrm_uf_match.contact_id\n WHERE {$whereClause}\n display_name IS NOT NULL\n AND display_name NOT LIKE ''\n AND display_name NOT LIKE '<Last>%%'\n AND display_name NOT LIKE '%@%%'\n AND display_name NOT LIKE '--%%'\n AND display_name NOT LIKE '- -%%'\n AND display_name NOT LIKE ',%%'\n AND display_name NOT LIKE '..%%'\n " . $string_clause . " LIMIT {$limit}";
$params = array(
1 => array(
$args[0],
"String",
),
);
$dao = CRM_Core_DAO::executeQuery($q, $params);
$references = array();
while ($dao
->fetch()) {
$uid = CRM_Core_BAO_UFMatch::getUFId($dao->id);
$username = db_result(db_query("SELECT name FROM {users} WHERE uid=%d", $uid));
$references[$dao->id] = array(
'title' => $username,
'rendered' => $dao->display_name,
);
}
return $references;
}