This commit is contained in:
2025-08-01 14:29:50 +03:00
parent 2ab819ff30
commit b86b8ff923
54 changed files with 1512 additions and 672 deletions

View 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 => "Отправлено",
];
}
}

View 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);
}
}

View File

@@ -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' => '',
];
}
}