-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprivatemsg.controller.inc
85 lines (75 loc) · 2.21 KB
/
privatemsg.controller.inc
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @file
* Private message controller.
* Loads private messages.
*/
class PrivatemsgMessageController extends EntityDatabaseStorageController {
/**
* @var User|null
*/
protected $account = NULL;
/**
* {@inheritdoc}
*/
public function load($ids = array(), $conditions = array()) {
// Remove account from conditions.
if (isset($conditions['account'])) {
$this->account = $conditions['account'];
unset($conditions['account']);
}
$messages = parent::load($ids, $conditions);
return $messages;
}
/**
* {@inheritdoc}
*/
protected function attachLoad(&$messages, $revision_id = FALSE) {
global $user;
foreach ($messages as $message) {
$message->user = $this->account ? $this->account : $user;
// Load author of message.
if (!($message->author = user_load($message->author))) {
// If user does not exist, load anonymous user.
$message->author = user_load(0);
}
}
parent::attachLoad($messages, $revision_id);
}
/**
* {@inheritdoc}
*/
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
// Remove account from conditions.
if (isset($conditions['account'])) {
$this->account = $conditions['account'];
unset($conditions['account']);
}
$query = parent::buildQuery($ids, $conditions, $revision_id);
$query->fields('pmi', array('is_new', 'thread_id'));
if ($this->account) {
$query
->condition('pmi.recipient', $this->account->uid)
->condition('pmi.type', array('hidden', 'user'));
}
else {
// If no account is given, at least limit the result to a single row per
// message.
$query->distinct();
}
$query->join('pm_index', 'pmi', "base.mid = pmi.mid");
return $query;
}
/**
* {@inheritdoc}
*/
protected function cacheGet($ids, $conditions = array()) {
// Passing the account condition, which does not exist as a property to
// parent::cacheGet() causes notices, remove it.
// @todo Investigate if this causes any undesired side effects.
if (isset($conditions['account'])) {
unset($conditions['account']);
}
return parent::cacheGet($ids, $conditions);
}
}