html field and other stuff
parent
f9d12c07cc
commit
73af945046
|
|
@ -7,6 +7,7 @@ use App\Models\Objects\Values\DatetimeValue;
|
|||
use App\Models\Objects\Values\DateValue;
|
||||
use App\Models\Objects\Values\DocumentValue;
|
||||
use App\Models\Objects\Values\FloatValue;
|
||||
use App\Models\Objects\Values\HtmlValue;
|
||||
use App\Models\Objects\Values\ImageValue;
|
||||
use App\Models\Objects\Values\IntegerValue;
|
||||
use App\Models\Objects\Values\RelationValue;
|
||||
|
|
@ -17,6 +18,7 @@ use App\Models\Objects\Values\TimeValue;
|
|||
class FieldType {
|
||||
public const STRING = 'string';
|
||||
public const TEXT = 'text';
|
||||
public const HTML = 'html';
|
||||
public const INTEGER = 'integer';
|
||||
public const FLOAT = 'float';
|
||||
public const BOOLEAN = 'boolean';
|
||||
|
|
@ -30,6 +32,7 @@ class FieldType {
|
|||
public const TITLES = [
|
||||
self::STRING => 'Строка',
|
||||
self::TEXT => 'Текст',
|
||||
self::HTML => 'Текст с разметкой',
|
||||
self::INTEGER => 'Целое число',
|
||||
self::FLOAT => 'Число с точкой',
|
||||
self::BOOLEAN => 'Двоичное',
|
||||
|
|
@ -44,6 +47,7 @@ class FieldType {
|
|||
public const TABLES = [
|
||||
self::STRING => 'field_string_values',
|
||||
self::TEXT => 'field_text_values',
|
||||
self::HTML => 'field_html_values',
|
||||
self::INTEGER => 'field_integer_values',
|
||||
self::FLOAT => 'field_float_values',
|
||||
self::BOOLEAN => 'field_boolean_values',
|
||||
|
|
@ -58,6 +62,7 @@ class FieldType {
|
|||
public const CLASSES = [
|
||||
self::STRING => StringValue::class,
|
||||
self::TEXT => TextValue::class,
|
||||
self::HTML => HtmlValue::class,
|
||||
self::INTEGER => IntegerValue::class,
|
||||
self::FLOAT => FloatValue::class,
|
||||
self::BOOLEAN => BooleanValue::class,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Objects\Values;
|
||||
|
||||
class HtmlValue extends Value {
|
||||
protected $table = 'field_html_values';
|
||||
|
||||
public function get() {
|
||||
return $this->value ? trim($this->value) : null;
|
||||
}
|
||||
public function set($value): bool {
|
||||
return parent::set(trim($value));
|
||||
}
|
||||
|
||||
public static function applyFilter($query, $value) {
|
||||
collect(explode(' ', trim($value)))->each(function($term) use($query) {
|
||||
$query->where('value', 'like', "%{$term}%");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ class TextValue extends Value {
|
|||
return $this->value ? trim($this->value) : null;
|
||||
}
|
||||
public function set($value): bool {
|
||||
return parent::set(trim($value));
|
||||
return parent::set(trim(strip_tags($value)));
|
||||
}
|
||||
|
||||
public static function applyFilter($query, $value) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ namespace App\Models\Pages;
|
|||
|
||||
class PageType {
|
||||
public const CONTENT = 'content';
|
||||
public const REGISTRY = 'registry';
|
||||
|
||||
public const TITLES = [
|
||||
self::CONTENT => 'Контентная страница'
|
||||
self::CONTENT => 'Контентная страница',
|
||||
self::REGISTRY => 'Страница реестра'
|
||||
];
|
||||
}
|
||||
|
|
@ -36,16 +36,10 @@ trait HasObjectsTrait {
|
|||
|
||||
public function attachObject(NirObject $object, $ord = null, $group = null) {
|
||||
$ord = ($ord === null) ? $this->getMaxOrd($group) : $ord;
|
||||
$this->moveFollowingObjects($ord, $group);
|
||||
$this->moveObjectsSet('forward', $ord, null, $group);
|
||||
$this->objects()->attach($object->id, ['ord' => $ord ?? 0, 'group' => $group ?? 'default']);
|
||||
}
|
||||
|
||||
public function moveFollowingObjects($ord, $group = null) {
|
||||
$this->objectsByGroup($group)->wherePivot('ord', '>=', $ord)->get()->each(function($object) {
|
||||
$this->objects()->updateExistingPivot($object, ['ord' => $object->pivot->ord + 1]);
|
||||
});
|
||||
}
|
||||
|
||||
public function getMaxOrd($group = null): int {
|
||||
$res = $this->objectsByGroup($group)->max('ord');
|
||||
return ($res !== null) ? ($res + 1) : 0;
|
||||
|
|
@ -56,15 +50,22 @@ trait HasObjectsTrait {
|
|||
$currentGroup = $object->currentGroup($this);
|
||||
$group = $group ?? $currentGroup;
|
||||
$currentOrd = $object->currentOrd($this);
|
||||
if (($group === $currentGroup) && ($ord > $currentOrd)) {
|
||||
$this->objectsByGroup($group)->wherePivot('ord', '>', $currentOrd)->wherePivot('ord', '<=', $ord)->each(function($object) {
|
||||
$this->objects()->updateExistingPivot($object, ['ord' => $object->pivot->ord - 1]);
|
||||
});
|
||||
} else $this->moveFollowingObjects($ord, $group);
|
||||
if ($group === $currentGroup) {
|
||||
($ord > $currentOrd) ? $this->moveObjectsSet('backward', $currentOrd, $ord, $group) : $this->moveObjectsSet('forward', $ord, $currentOrd, $group);
|
||||
} else $this->moveObjectsSet('forward', $ord, null, $group);
|
||||
$this->objects()->updateExistingPivot($object, ['ord' => $ord, 'group' => $group ?? 'default']);
|
||||
$this->trimIndexes([$group, $currentGroup]);
|
||||
}
|
||||
|
||||
public function moveObjectsSet($dir = 'forward', $ordFrom = null, $ordTo = null, $group = null) {
|
||||
$query = $this->objectsByGroup($group);
|
||||
if ($ordFrom !== null) $query->wherePivot('ord', '>=', $ordFrom);
|
||||
if ($ordTo !== null) $query->wherePivot('ord', '<=', $ordTo);
|
||||
$query->get()->each(function($object) use($dir) {
|
||||
$this->objects()->updateExistingPivot($object, ['ord' => ($dir === 'forward') ? ($object->pivot->ord + 1) : ($object->pivot->ord - 1)]);
|
||||
});
|
||||
}
|
||||
|
||||
public function trimIndexes($groups) {
|
||||
collect(is_array($groups) ? $groups : [$groups])->unique()->each(function($group) {
|
||||
$this->objectsByGroup($group)->each(function($object, $index) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFieldHtmlValuesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('field_html_values', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('object_id')->index()->nullable();
|
||||
$table->integer('field_id')->index()->nullable();
|
||||
$table->text('value')->nullable();
|
||||
$table->integer('ord')->index()->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('field_html_values');
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,16 @@ class FieldsTableSeeder extends Seeder {
|
|||
'required' => true
|
||||
],
|
||||
|
||||
'html' => [
|
||||
'title' => 'Содержимое текстового блока',
|
||||
'type' => FieldType::HTML
|
||||
],
|
||||
'html-required' => [
|
||||
'title' => 'Содержимое текстового блока',
|
||||
'type' => FieldType::HTML,
|
||||
'required' => true
|
||||
],
|
||||
|
||||
'list-type' => [
|
||||
'title' => 'Вид списка',
|
||||
'type' => FieldType::RELATION,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ class ObjectTypeFieldsTableSeeder extends Seeder {
|
|||
'fields' => ['text-required']
|
||||
]
|
||||
],
|
||||
'page-section-html' => [
|
||||
'common' => [
|
||||
'fields' => ['html-required']
|
||||
]
|
||||
],
|
||||
'page-section-list' => [
|
||||
'common' => [
|
||||
'fields' => ['list-type', 'list-items']
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ class ObjectTypesTableSeeder extends Seeder {
|
|||
'page-section-text' => [
|
||||
'title' => 'Текстовый блок'
|
||||
],
|
||||
'page-section-html' => [
|
||||
'title' => 'Текстовый блок с разметкой'
|
||||
],
|
||||
'page-section-list' => [
|
||||
'title' => 'Список'
|
||||
],
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ class PagesTableSeeder extends Seeder
|
|||
'О центре' => [
|
||||
'children' => [
|
||||
'Руководство' => [
|
||||
'children' => [
|
||||
|
||||
]
|
||||
],
|
||||
'Документы' => [
|
||||
'children' => [
|
||||
|
|
|
|||
Loading…
Reference in New Issue