diff --git a/app/Models/Objects/FieldType.php b/app/Models/Objects/FieldType.php index 9cb9b54..86c7de4 100644 --- a/app/Models/Objects/FieldType.php +++ b/app/Models/Objects/FieldType.php @@ -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, diff --git a/app/Models/Objects/Values/HtmlValue.php b/app/Models/Objects/Values/HtmlValue.php new file mode 100644 index 0000000..5b831a7 --- /dev/null +++ b/app/Models/Objects/Values/HtmlValue.php @@ -0,0 +1,20 @@ +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}%"); + }); + } +} \ No newline at end of file diff --git a/app/Models/Objects/Values/TextValue.php b/app/Models/Objects/Values/TextValue.php index e24f0f1..da0bb56 100644 --- a/app/Models/Objects/Values/TextValue.php +++ b/app/Models/Objects/Values/TextValue.php @@ -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) { diff --git a/app/Models/Pages/PageType.php b/app/Models/Pages/PageType.php index d9dd9bb..840770b 100644 --- a/app/Models/Pages/PageType.php +++ b/app/Models/Pages/PageType.php @@ -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 => 'Страница реестра' ]; } \ No newline at end of file diff --git a/app/Support/HasObjectsTrait.php b/app/Support/HasObjectsTrait.php index cfd8f27..8e0ea3a 100644 --- a/app/Support/HasObjectsTrait.php +++ b/app/Support/HasObjectsTrait.php @@ -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) { diff --git a/database/migrations/2023_06_06_162647_create_field_html_values_table.php b/database/migrations/2023_06_06_162647_create_field_html_values_table.php new file mode 100644 index 0000000..9456a7d --- /dev/null +++ b/database/migrations/2023_06_06_162647_create_field_html_values_table.php @@ -0,0 +1,35 @@ +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'); + } +} diff --git a/database/seeders/Objects/FieldsTableSeeder.php b/database/seeders/Objects/FieldsTableSeeder.php index cad7043..de5308c 100644 --- a/database/seeders/Objects/FieldsTableSeeder.php +++ b/database/seeders/Objects/FieldsTableSeeder.php @@ -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, diff --git a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php index 3e672d9..70afb8d 100644 --- a/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php +++ b/database/seeders/Objects/ObjectTypeFieldsTableSeeder.php @@ -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'] diff --git a/database/seeders/Objects/ObjectTypesTableSeeder.php b/database/seeders/Objects/ObjectTypesTableSeeder.php index 744f782..4b6e7de 100644 --- a/database/seeders/Objects/ObjectTypesTableSeeder.php +++ b/database/seeders/Objects/ObjectTypesTableSeeder.php @@ -19,6 +19,9 @@ class ObjectTypesTableSeeder extends Seeder { 'page-section-text' => [ 'title' => 'Текстовый блок' ], + 'page-section-html' => [ + 'title' => 'Текстовый блок с разметкой' + ], 'page-section-list' => [ 'title' => 'Список' ], diff --git a/database/seeders/Pages/PagesTableSeeder.php b/database/seeders/Pages/PagesTableSeeder.php index 104d8a7..0c987ae 100644 --- a/database/seeders/Pages/PagesTableSeeder.php +++ b/database/seeders/Pages/PagesTableSeeder.php @@ -12,7 +12,9 @@ class PagesTableSeeder extends Seeder 'О центре' => [ 'children' => [ 'Руководство' => [ + 'children' => [ + ] ], 'Документы' => [ 'children' => [