-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNotification.php
132 lines (116 loc) · 3.26 KB
/
Notification.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace common\models;
use Yii;
use cbtech\notification_system\models\NotificationBase;
use yii\helpers\Url;
/**
* This is the model class for table "notification".
*
* @property integer $id
* @property integer $user_id
* @property string $key
* @property integer $key_id
* @property string $type
* @property integer $read
* @property integer $flashed
* @property string $created_at
* @property string $updated_at
*
* @property User $user
*/
class Notification extends NotificationBase
{
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(parent::rules(),[
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
]);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* A new comment notification
*/
const KEY_NEW_COMMENT = 'new_comment';
/**
* A new connection notification
*/
const KEY_NEW_CONNECTION_REQUEST = 'new_connection_request';
/**
* @var array Holds all usable notifications
*/
public static $keys = [
self::KEY_NEW_COMMENT,
self::KEY_NEW_CONNECTION_REQUEST
];
/**
* @inheritdoc
*/
public function getTitle()
{
switch ($this->key) {
case self::KEY_NEW_COMMENT:
return Yii::t('app', '');
case self::KEY_NEW_CONNECTION_REQUEST:
return Yii::t('app', 'test');
}
}
/**
* @inheritdoc
*/
public function getBody()
{
switch ($this->key) {
case self::KEY_NEW_COMMENT:
$comment = Comment::findOne($this->key_id);
return Yii::t('app', 'You have a new comment from {user}', [
'user' => $comment->user->username
]);
case self::KEY_NEW_CONNECTION_REQUEST:
$user = User::findOne($this->user_id);
$connection = User::findOne($this->key_id);
$msg = Yii::t('app', '<b>{connection}</b> would like to connect with you.', [
'connection' => $connection->userProfile->name
]);
$html = "<div class='' style=''>
{$msg}
</div>";
return $html;
}
}
/**
* @inheritdoc
*/
public function getFooter(){
switch ($this->key) {
case self::KEY_NEW_COMMENT:
return "";
case self::KEY_NEW_CONNECTION_REQUEST:
$html = "<div class='' style='text-align:right;'>
<button class='btn btn-default btn-xs rejectConnection' data-keepOpenOnClick>Reject</button>
<button class='btn btn-primary btn-xs acceptConnection' data-keepOpenOnClick>Accept</button>
</div>";
return $html;
}
}
/**
* @inheritdoc
*/
public function getRoute()
{
switch ($this->key) {
case self::KEY_NEW_COMMENT:
return Url::to(['comment/index', 'id' => $this->key_id]);
case self::KEY_NEW_CONNECTION_REQUEST:
return Url::to(['user/user-connection-request', 'id' => $this->key_id]);
};
}
}