-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_mails.query.inc
More file actions
52 lines (48 loc) · 1.36 KB
/
send_mails.query.inc
File metadata and controls
52 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @file
* Database querys and Autocomplete json handlers.
*/
/**
* Custom function to process database operations.
*/
function send_mails_query($type, $condition) {
if ($type == 'mailid_from_role') {
$query = db_select('users', 'u')
->fields('u', array('mail'));
$query->condition('u.mail', '', '<>');
// If Authenticated user.
if ($condition != 2) {
$query->join('users_roles', 'ur', 'ur.uid = u.uid');
$query->condition('ur.rid', $condition);
}
$result = $query->execute()->fetchAll();
}
return $result;
}
/**
* Custom Autocomplete field.
*/
function send_mails_mailids_autocomplete($string) {
$matches = array();
if ($string) {
$array = drupal_explode_tags($string);
// Fetch last string from user entered string.
$last_string = trim(array_pop($array));
$result = db_select('users')
->fields('users', array('mail'))
->condition('mail', '%' . db_like($last_string) . '%', 'LIKE')
->range(0, 10)
->execute();
// Adding previous values along with last name.
$prefix = count($array) ? implode(', ', $array) . ', ' : '';
// Add matches to $matches.
foreach ($result as $row) {
if (!in_array($row->mail, $array)) {
$matches[$prefix . $row->mail] = check_plain($row->mail);
}
}
}
// Return for JS.
drupal_json_output($matches);
}