first
This commit is contained in:
72
kernel/app_modules/user_custom_fields/models/CustomField.php
Normal file
72
kernel/app_modules/user_custom_fields/models/CustomField.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\user_custom_fields\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
// Добавить @property
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $status
|
||||
* @property string $slug
|
||||
* @property string $label
|
||||
* @property string $type
|
||||
* @property string $entity
|
||||
* @property string $field_options
|
||||
*/
|
||||
class CustomField extends Model
|
||||
{
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
const TYPE_STRING = 'string';
|
||||
|
||||
const TYPE_SELECT = 'select';
|
||||
|
||||
protected $table = 'custom_field';
|
||||
|
||||
protected $fillable = ['slug', 'label', 'type', 'entity', 'field_options', 'status']; // Заполнить массив. Пример: ['label', 'slug', 'status']
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
// Заполнить массив
|
||||
// Пример: [
|
||||
// 'label' => 'Заголовок',
|
||||
// 'entity' => 'Сущность',
|
||||
// 'slug' => 'Slug',
|
||||
// 'status' => 'Статус',
|
||||
// ]
|
||||
|
||||
return [
|
||||
'slug' => 'Slug',
|
||||
'label' => 'Название',
|
||||
'type' => 'Тип',
|
||||
'entity' => 'Сущность',
|
||||
'field_options' => 'Опции поля',
|
||||
'status' => 'Статус',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getTypes(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_STRING => 'Текст',
|
||||
self::TYPE_SELECT => 'Список',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\user_custom_fields\models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use kernel\modules\user\models\User;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $custom_field_id
|
||||
* @property string $value
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class UserCustomValues extends Model
|
||||
{
|
||||
|
||||
const DISABLE_STATUS = 0;
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'user_custom_values';
|
||||
|
||||
protected $fillable = ['user_id', 'custom_field_id', 'value'];
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'ID пользователя',
|
||||
'custom_field_id' => 'ID кастомного поля',
|
||||
'value' => 'Значение',
|
||||
'created_at' => 'Дата создания',
|
||||
'updated_at' => 'Дата обновления',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public static function getStatus(): array
|
||||
{
|
||||
return [
|
||||
self::DISABLE_STATUS => "Не активный",
|
||||
self::ACTIVE_STATUS => "Активный",
|
||||
];
|
||||
}
|
||||
|
||||
public function customField(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CustomField::class);
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\user_custom_fields\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateCustomFieldForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'slug' => 'required|min-str-len:3|max-str-len:30',
|
||||
'label' => 'required|min-str-len:3|max-str-len:50',
|
||||
'type' => 'required|min-str-len:3|max-str-len:30',
|
||||
'entity' => 'required|min-str-len:3|max-str-len:30',
|
||||
'field_options' => '',
|
||||
'status' => '',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\app_modules\user_custom_fields\models\forms;
|
||||
|
||||
use kernel\FormModel;
|
||||
|
||||
class CreateUserCustomValueForm extends FormModel
|
||||
{
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
// Заполнить массив правил
|
||||
// Пример:
|
||||
// return [
|
||||
// 'label' => 'required|min-str-len:5|max-str-len:30',
|
||||
// 'entity' => 'required',
|
||||
// 'slug' => '',
|
||||
// 'status' => ''
|
||||
// ];
|
||||
return [
|
||||
'user_id' => 'required|integer|min:1',
|
||||
'custom_field_id' => 'required|integer|min:1',
|
||||
'value' => '',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user