1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This is a notification task, by default a container that may act like |
5
|
|
|
* an array (through ArrayAccess), with some ad-hoc methods. |
6
|
|
|
* |
7
|
|
|
* @name ElkArte Forum |
8
|
|
|
* @copyright ElkArte Forum contributors |
9
|
|
|
* @license BSD http://opensource.org/licenses/BSD-3-Clause |
10
|
|
|
* |
11
|
|
|
* @version 1.0.3 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
if (!defined('ELK')) |
16
|
|
|
die('No access...'); |
17
|
|
|
|
18
|
|
|
class Notifications_Task extends \ElkArte\ValuesContainer |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Data of the members to notify. |
22
|
|
|
* Populated only if the getMembersData method is called. |
23
|
|
|
* |
24
|
|
|
* @var mixed[] |
25
|
|
|
*/ |
26
|
|
|
protected $_members_data = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Data of the member generating the notification. |
30
|
|
|
* Populated only if the getNotifierData method is called. |
31
|
|
|
* |
32
|
|
|
* @var mixed[] |
33
|
|
|
*/ |
34
|
|
|
protected $_notifier_data = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The constructor prepared the data array and fills some default values |
38
|
|
|
* if needed. |
39
|
|
|
* |
40
|
|
|
* @param string $type The notification type we are dealing with |
41
|
|
|
* @param int $id The id of the target (can be a message, a topic, a member, whatever) |
42
|
|
|
* @param int $id_member The id of the member generating the notification |
43
|
|
|
* @param mixed[] $data An array of data that can be necessary in the process |
44
|
|
|
* @param string $namespace A namespace for the class if different from the |
45
|
|
|
* default \ElkArte\sources\subs\MentionType\ |
46
|
|
|
*/ |
47
|
|
|
public function __construct($type, $id, $id_member, $data, $namespace = '') |
48
|
|
|
{ |
49
|
|
|
$this->data = array( |
|
|
|
|
50
|
|
|
'notification_type' => $type, |
51
|
|
|
'namespace' => empty($namespace) ? '\\ElkArte\\sources\\subs\\MentionType\\' : rtrim($namespace, '\\') . '\\', |
52
|
|
|
'id_target' => $id, |
53
|
|
|
'id_member_from' => $id_member, |
54
|
|
|
'source_data' => $data, |
55
|
|
|
'log_time' => time() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
if (!isset($this->data['source_data']['status'])) |
59
|
|
|
$this->data['source_data']['status'] = 'new'; |
60
|
|
|
|
61
|
|
|
if (isset($this->data['source_data']['id_members'])) |
62
|
|
|
$this->setMembers($this->data['source_data']['id_members']); |
63
|
|
|
else |
64
|
|
|
$this->setMembers(array()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the array of member that have to receive the notification. |
69
|
|
|
* |
70
|
|
|
* @return int[] An array of member id |
71
|
|
|
*/ |
72
|
|
|
public function getMembers() |
73
|
|
|
{ |
74
|
|
|
return $this->data['source_data']['id_members']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sets the members that have to receive the notification. |
79
|
|
|
* |
80
|
|
|
* @param int|int[] An array of member id |
81
|
|
|
*/ |
82
|
|
|
public function setMembers($members) |
83
|
|
|
{ |
84
|
|
|
$this->data['source_data']['id_members'] = (array) $members; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the data from getBasicMemberData about the members to be notified. |
89
|
|
|
* |
90
|
|
|
* @return mixed[] |
91
|
|
|
*/ |
92
|
|
|
public function getMembersData() |
93
|
|
|
{ |
94
|
|
|
if ($this->_members_data === null) |
95
|
|
|
{ |
96
|
|
|
require_once(SUBSDIR . '/Members.subs.php'); |
97
|
|
|
$this->_members_data = getBasicMemberData($this->getMembers(), array('preferences' => true)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->_members_data; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns the data from getBasicMemberData about the member that |
105
|
|
|
* generated the notification |
106
|
|
|
* |
107
|
|
|
* @return mixed[] |
108
|
|
|
*/ |
109
|
|
|
public function getNotifierData() |
110
|
|
|
{ |
111
|
|
|
if ($this->_notifier_data === null) |
112
|
|
|
{ |
113
|
|
|
require_once(SUBSDIR . '/Members.subs.php'); |
114
|
|
|
$this->_notifier_data = getBasicMemberData($this->id_member_from); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->_notifier_data; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the class name of the MentionType. |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getClass() |
126
|
|
|
{ |
127
|
|
|
return $this->data['namespace'] . ucfirst($this->data['notification_type']) . '_Mention'; |
128
|
|
|
} |
129
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..