function _petreference_potential_references_standard in Previewable email templates 6
Helper function for _petreference_potential_references(): referenceable PETS defined by content types.
1 call to _petreference_potential_references_standard()
- _petreference_potential_references in modules/
petreference/ petreference.module - Fetch an array of all candidate referenced pets.
File
- modules/
petreference/ petreference.module, line 843 - Defines a field type for referencing pet template to a node.
Code
function _petreference_potential_references_standard($field, $string = '', $match = 'contains', $ids = array(), $limit = NULL) {
$where = array();
$args = array();
if ($string !== '') {
$like = $GLOBALS["db_type"] == 'pgsql' ? "ILIKE" : "LIKE";
$match_clauses = array(
'contains' => "{$like} '%%%s%%'",
'equals' => "= '%s'",
'starts_with' => "{$like} '%s%%'",
);
$where[] = 'p.title ' . (isset($match_clauses[$match]) ? $match_clauses[$match] : $match_clauses['contains']);
$args[] = $string;
}
elseif ($ids) {
$where[] = 'p.pid IN (' . db_placeholders($ids) . ')';
$args = array_merge($args, $ids);
}
$where_clause = $where ? 'WHERE (' . implode(') AND (', $where) . ')' : '';
$query = "SELECT p.pid, p.title AS pet_title FROM {pets} p " . $where_clause . " ORDER BY p.title";
$sql = db_rewrite_sql($query);
$result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args);
$references = array();
while ($pet = db_fetch_object($result)) {
$references[$pet->pid] = array(
'title' => $pet->pet_title,
'rendered' => check_plain($pet->pet_title),
);
}
return $references;
}