v0.1.10
This commit is contained in:
71
kernel/modules/notification/models/Notification.php
Normal file
71
kernel/modules/notification/models/Notification.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\notification\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\modules\user\models\User;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property bool $is_read
|
||||
* @property array|string $data
|
||||
* @property string $type
|
||||
* @property string $message
|
||||
* @property string $subject
|
||||
* @property int $status
|
||||
*/
|
||||
|
||||
class Notification extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const TO_SEND_STATUS = 1;
|
||||
const SENT_STATUS = 2;
|
||||
|
||||
protected $table = 'notification';
|
||||
|
||||
protected $fillable = ['user_id', 'message', 'is_read', 'data', 'type', 'subject', 'status'];
|
||||
|
||||
protected $casts = [
|
||||
'is_read' => 'boolean',
|
||||
'data' => 'array'
|
||||
];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'Пользователь',
|
||||
'message' => 'Сообщение',
|
||||
'subject' => 'Тема',
|
||||
'is_read' => 'Прочитано',
|
||||
'data' => 'Данные',
|
||||
'type' => 'Тип',
|
||||
'status' => 'Статус'
|
||||
];
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function markAsRead(): static
|
||||
{
|
||||
$this->update(['is_read' => true]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::TO_SEND_STATUS => "На отправку",
|
||||
self::SENT_STATUS => "Отправлено",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
13
kernel/modules/notification/models/User.php
Normal file
13
kernel/modules/notification/models/User.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\notification\models;
|
||||
|
||||
class User extends \kernel\modules\user\models\User
|
||||
{
|
||||
|
||||
public function notifications(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Notification::class);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\modules\notification\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
/**
|
||||
* @property string $key
|
||||
* @property string $value
|
||||
* @property string $label
|
||||
* @property integer $status
|
||||
*/
|
||||
class CreateNotificationForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'required|integer',
|
||||
'message' => 'required',
|
||||
'is_read' => '',
|
||||
'data' => '',
|
||||
'type' => 'required',
|
||||
'subject' => '',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user