1 | <?php |
||
2 | |||
3 | namespace Apps\Model\Front\Profile; |
||
4 | |||
5 | use Apps\ActiveRecord\UserNotification; |
||
6 | use Ffcms\Core\Arch\Model; |
||
7 | |||
8 | /** |
||
9 | * Class EntityAddNotification. Add user notification in database table |
||
10 | * @package Apps\Model\Front\Profile |
||
11 | */ |
||
12 | class EntityAddNotification extends Model |
||
13 | { |
||
14 | const MSG_DEFAULT = 'New notification event: «%snippet%»'; |
||
15 | const MSG_ADD_WALLPOST = 'New post on the wall: «%snippet%»'; |
||
16 | const MSG_ADD_WALLANSWER = 'New answer «%snippet%» for wall post «%post%»'; |
||
17 | const MSG_ADD_COMMENTANSWER = 'New answer «%snippet%» to your comment «%post%»'; |
||
18 | const MSG_ADD_FEEDBACKANSWER = 'New answer «%snippet%» to your feedback request «%post%»'; |
||
19 | |||
20 | private $_targetId; |
||
21 | |||
22 | /** |
||
23 | * EntityAddNotification constructor. Pass target user_id inside the model |
||
24 | * @param bool $targetId |
||
25 | */ |
||
26 | public function __construct($targetId) |
||
27 | { |
||
28 | $this->_targetId = $targetId; |
||
29 | parent::__construct(); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Add notification for user |
||
34 | * @param string $uri |
||
35 | * @param string $msg |
||
36 | * @param array|null $vars |
||
37 | */ |
||
38 | public function add($uri, $msg = self::MSG_DEFAULT, array $vars = null) |
||
39 | { |
||
40 | // save data into database |
||
41 | $record = new UserNotification(); |
||
42 | $record->user_id = $this->_targetId; |
||
0 ignored issues
–
show
|
|||
43 | $record->uri = $uri; |
||
44 | $record->msg = $msg; |
||
45 | if ($vars !== null) { |
||
46 | $record->vars = $vars; |
||
47 | } |
||
48 | |||
49 | $record->save(); |
||
50 | } |
||
51 | } |
||
52 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.