1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Model; |
13
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\GenericEvent; |
15
|
|
|
use Jitamin\Foundation\Database\Model; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* User Mention. |
19
|
|
|
*/ |
20
|
|
|
class UserMentionModel extends Model |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Get list of mentioned users. |
24
|
|
|
* |
25
|
|
|
* @param string $content |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getMentionedUsers($content) |
30
|
|
|
{ |
31
|
|
|
$users = []; |
32
|
|
|
|
33
|
|
|
if (preg_match_all('/@([^\s]+)/', $content, $matches)) { |
34
|
|
|
$users = $this->db->table(UserModel::TABLE) |
|
|
|
|
35
|
|
|
->columns('id', 'username', 'name', 'email', 'language') |
36
|
|
|
->eq('notifications_enabled', 1) |
37
|
|
|
->neq('id', $this->userSession->getId()) |
|
|
|
|
38
|
|
|
->in('username', array_unique($matches[1])) |
39
|
|
|
->findAll(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $users; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Fire events for user mentions. |
47
|
|
|
* |
48
|
|
|
* @param string $content |
49
|
|
|
* @param string $eventName |
50
|
|
|
* @param GenericEvent $event |
51
|
|
|
*/ |
52
|
|
|
public function fireEvents($content, $eventName, GenericEvent $event) |
53
|
|
|
{ |
54
|
|
|
if (empty($event['project_id'])) { |
55
|
|
|
$event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$users = $this->getMentionedUsers($content); |
59
|
|
|
|
60
|
|
|
foreach ($users as $user) { |
61
|
|
|
if ($this->projectPermissionModel->isMember($event['project_id'], $user['id'])) { |
|
|
|
|
62
|
|
|
$event['mention'] = $user; |
63
|
|
|
$this->dispatcher->dispatch($eventName, $event); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.