Merge remote-tracking branch 'origin/master'
commit
d7ab59d826
|
|
@ -8,6 +8,7 @@ use App\Models\Publications\Publication;
|
|||
use App\Transformers\Publications\PublicationTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PublicationsController extends Controller {
|
||||
protected Publication $model;
|
||||
|
|
@ -22,14 +23,23 @@ class PublicationsController extends Controller {
|
|||
}
|
||||
|
||||
public function index(Request $request): JsonResponse {
|
||||
$query = $this->model->query();
|
||||
if ($page = Page::byUuid($request->get('page'))->first()) $query->where(['page_id' => $page->id]);
|
||||
$where = ['is_published' => true];
|
||||
if (Auth::check()) {
|
||||
if ($request->has('edit_mode')) {
|
||||
if ($request->get('edit_mode')==='yes') {
|
||||
unset($where['is_published']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$query = $this->model->query()->orderBy('id', 'desc');
|
||||
if ($page = Page::byUuid($request->get('page'))->first()) $where[] = ['page_id' => $page->id];
|
||||
$query->where($where);
|
||||
$paginator = $query->paginate(config('app.pagination_limit'));
|
||||
return fractal($paginator, new PublicationTransformer())->respond();
|
||||
}
|
||||
|
||||
public function show(Request $request, $id): JsonResponse {
|
||||
$model = $this->model->byUuid($id)->firstOrFail();
|
||||
$model = $this->model->bySlug($id)->firstOrFail();
|
||||
return fractal($model, new PublicationTransformer())->respond();
|
||||
}
|
||||
|
||||
|
|
@ -41,10 +51,18 @@ class PublicationsController extends Controller {
|
|||
public function update(Request $request, $uuid): void {
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $uuid): JsonResponse {
|
||||
public function destroy(Request $request, $uuid) {
|
||||
$model = $this->model->byUuid($uuid)->firstOrFail();
|
||||
$model->delete();
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
public function published(Request $request, $uuid): JsonResponse {
|
||||
$model = $this->model->byUuid($uuid)->firstOrFail();
|
||||
$data = [
|
||||
'is_published' => $request->get('publish')
|
||||
];
|
||||
$model->update($data);
|
||||
return fractal($model, new PublicationTransformer())->respond();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,9 +96,22 @@ class Page extends Model {
|
|||
public static function byUrl($url) {
|
||||
if ($url = trim($url, '/ ')) {
|
||||
$query = self::query();
|
||||
collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query) {
|
||||
if ($slug !== '') {
|
||||
$index ? $query->nthParentSlug($index, $slug) : $query->bySlug($slug);
|
||||
$reduceIndex = 0;
|
||||
collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query, &$reduceIndex) {
|
||||
$exist = self::query()->where(['slug' => $slug])->exists();
|
||||
if ($exist) {
|
||||
if ($slug !== '') {
|
||||
$currentIndex = $index - $reduceIndex;
|
||||
$currentIndex ? $query->nthParentSlug($currentIndex, $slug) : $query->bySlug($slug);
|
||||
}
|
||||
} else {
|
||||
$reduceIndex++;
|
||||
$exist = Publication::query()->where(['slug' => $slug])->exists();
|
||||
if ($exist) {
|
||||
$query->whereHas('publications', function($query) use($slug) {
|
||||
$query->where(['slug' => $slug]);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return $query->first();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class Publication extends Model {
|
|||
'type',
|
||||
'name',
|
||||
'excerpt',
|
||||
'description',
|
||||
'is_published'
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Services\Forms;
|
||||
|
||||
use App\Services\Forms\Pages\PageFormsServices;
|
||||
use App\Services\Forms\Publications\PublicationFormsServices;
|
||||
use App\Services\Forms\Users\UserFormsServices;
|
||||
|
||||
class FormsService {
|
||||
|
|
@ -10,6 +11,7 @@ class FormsService {
|
|||
|
||||
public static array $services = [
|
||||
PageFormsServices::class,
|
||||
PublicationFormsServices::class,
|
||||
UserFormsServices::class
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ namespace App\Services\Forms\Pages;
|
|||
|
||||
class PageFormsServices {
|
||||
public static array $services = [
|
||||
|
||||
'published' => PublicationForms::class
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Forms\Publications;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\Objects\FieldType;
|
||||
use App\Models\Pages\Page;
|
||||
use App\Models\Publications\Publication;
|
||||
use App\Models\Publications\PublicationType;
|
||||
use App\Services\Forms\FormsService;
|
||||
use App\Transformers\Assets\AssetTransformer;
|
||||
use App\Transformers\Publications\PublicationTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PublicationForms extends FormsService {
|
||||
public array $formTitles = ['create' => 'Создание новой новости', 'update' => 'Редактирование новости'];
|
||||
|
||||
public function form(?string $id = null, array $data = []): array {
|
||||
$model = Publication::byUuid($id)->first();
|
||||
$groups = [
|
||||
['name' => 'common', 'fields' => $this->commonGroupFields($model)]
|
||||
];
|
||||
return ['title' => $this->formTitle($model), 'data' => $groups];
|
||||
}
|
||||
|
||||
public function commonGroupFields(?Publication $model): array {
|
||||
$fields = [
|
||||
[
|
||||
'name' => 'name',
|
||||
'title' => 'Название',
|
||||
'type' => FieldType::STRING,
|
||||
'required' => true,
|
||||
'value' => $model->name ?? null
|
||||
],
|
||||
[
|
||||
'name' => 'excerpt',
|
||||
'title' => 'Краткое описание',
|
||||
'type' => FieldType::TEXT,
|
||||
'required' => true,
|
||||
'value' => $model->excerpt ?? null
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'title' => 'Описание',
|
||||
'type' => FieldType::HTML,
|
||||
'value' => $model->description ?? null
|
||||
],
|
||||
[
|
||||
'name' => 'poster_id',
|
||||
'title' => 'Фотография профиля',
|
||||
'type' => FieldType::IMAGE,
|
||||
'value' => ($model->poster ?? null) ? fractal($model->poster, new AssetTransformer()) : null
|
||||
]
|
||||
];
|
||||
return ['data' => $fields];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function store(array $data): ?JsonResponse {
|
||||
if (!empty($data['attach']['page_slug'])) {
|
||||
$page = Page::query()->where(['slug' => $data['attach']['page_slug']])->first();
|
||||
$data['page_id'] = $page->id;
|
||||
}
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
$data['slug'] = Str::slug(Str::transliterate($data['name']));
|
||||
$data['type'] = PublicationType::NEWS;
|
||||
if (!empty($data['poster_id'])) {
|
||||
$asset = Asset::query()->where(['uuid' => $data['poster_id']])->first();
|
||||
$data['poster_id'] = $asset->id;
|
||||
}
|
||||
unset($data['attach']);
|
||||
$model = Publication::create($data, true);
|
||||
return fractal($model, new PublicationTransformer())->respond();
|
||||
}
|
||||
|
||||
public function update(string $id, array $data): ?JsonResponse {
|
||||
$model = Publication::byUuid($id)->firstOrFail();
|
||||
if (!empty($data['poster_id'])) {
|
||||
$asset = Asset::query()->where(['uuid' => $data['poster_id']])->first();
|
||||
$data['poster_id'] = $asset->id;
|
||||
}
|
||||
$model->update($data);
|
||||
return fractal($model->fresh(), new PublicationTransformer())->respond();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Forms\Publications;
|
||||
|
||||
class PublicationFormsServices {
|
||||
public static array $services = [
|
||||
'publications' => PublicationForms::class
|
||||
];
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ use League\Fractal\TransformerAbstract;
|
|||
|
||||
class FieldsGroupTransformer extends TransformerAbstract {
|
||||
protected array $defaultIncludes = [
|
||||
|
||||
];
|
||||
|
||||
protected array $availableIncludes = [
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use League\Fractal\TransformerAbstract;
|
|||
|
||||
class PublicationTransformer extends TransformerAbstract {
|
||||
protected array $defaultIncludes = [
|
||||
|
||||
'poster'
|
||||
];
|
||||
|
||||
protected array $availableIncludes = [
|
||||
|
|
@ -32,6 +32,7 @@ class PublicationTransformer extends TransformerAbstract {
|
|||
'subtype' => $model->parsedType,
|
||||
'name' => $model->name,
|
||||
'excerpt' => $model->excerpt,
|
||||
'description' => $model->description,
|
||||
'is_published' => boolval($model->is_published),
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : null,
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : null
|
||||
|
|
@ -47,7 +48,7 @@ class PublicationTransformer extends TransformerAbstract {
|
|||
}
|
||||
|
||||
public function includePoster(Publication $model): ?Item {
|
||||
return $model->poster ? $this->item($model->poster, new AssetTransformer()) : null;
|
||||
return $model->poster ? $this->item($model->poster, new AssetTransformer()) : null;
|
||||
}
|
||||
|
||||
public function includeAuthor(Publication $model): ?Item {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDescriptionToPublicationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('publications', function (Blueprint $table) {
|
||||
$table->addColumn('text', 'description')->after('excerpt')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('publications', function (Blueprint $table) {
|
||||
$table->dropColumn('description');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -32,16 +32,6 @@ class FieldsTableSeeder extends Seeder {
|
|||
'required' => true
|
||||
],
|
||||
|
||||
'text' => [
|
||||
'title' => 'Содержимое текстового блока',
|
||||
'type' => FieldType::TEXT
|
||||
],
|
||||
'text-required' => [
|
||||
'title' => 'Содержимое текстового блока',
|
||||
'type' => FieldType::TEXT,
|
||||
'required' => true
|
||||
],
|
||||
|
||||
'html' => [
|
||||
'title' => 'Содержимое текстового блока',
|
||||
'type' => FieldType::HTML
|
||||
|
|
@ -52,21 +42,21 @@ class FieldsTableSeeder extends Seeder {
|
|||
'required' => true
|
||||
],
|
||||
|
||||
'list-type' => [
|
||||
'title' => 'Вид списка',
|
||||
'type' => FieldType::RELATION,
|
||||
'required' => true,
|
||||
'params' => [
|
||||
'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
|
||||
'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'list-types']]]
|
||||
]
|
||||
],
|
||||
'list-items' => [
|
||||
'title' => 'Элементы списка',
|
||||
'type' => FieldType::TEXT,
|
||||
'multiple' => true,
|
||||
'required' => true
|
||||
],
|
||||
// 'list-type' => [
|
||||
// 'title' => 'Вид списка',
|
||||
// 'type' => FieldType::RELATION,
|
||||
// 'required' => true,
|
||||
// 'params' => [
|
||||
// 'related' => DictionaryItem::class, 'transformer' => DictionaryItemTransformer::class,
|
||||
// 'options' => ['show' => true, 'whereHas' => ['dictionary' => ['name' => 'list-types']]]
|
||||
// ]
|
||||
// ],
|
||||
// 'list-items' => [
|
||||
// 'title' => 'Элементы списка',
|
||||
// 'type' => FieldType::TEXT,
|
||||
// 'multiple' => true,
|
||||
// 'required' => true
|
||||
// ],
|
||||
|
||||
'images' => [
|
||||
'title' => 'Изображения',
|
||||
|
|
@ -78,6 +68,12 @@ class FieldsTableSeeder extends Seeder {
|
|||
'type' => FieldType::IMAGE,
|
||||
'multiple' => true,
|
||||
'required' => true
|
||||
],
|
||||
|
||||
'video-url' => [
|
||||
'title' => 'Ссылка на видео',
|
||||
'type' => FieldType::STRING,
|
||||
'required' => true
|
||||
]
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -20,21 +20,16 @@ class ObjectTypeFieldsTableSeeder extends Seeder {
|
|||
'fields' => ['header-required']
|
||||
]
|
||||
],
|
||||
'page-section-text' => [
|
||||
'common' => [
|
||||
'fields' => ['text-required']
|
||||
]
|
||||
],
|
||||
'page-section-html' => [
|
||||
'common' => [
|
||||
'fields' => ['html-required']
|
||||
]
|
||||
],
|
||||
'page-section-list' => [
|
||||
'common' => [
|
||||
'fields' => ['list-type', 'list-items']
|
||||
]
|
||||
],
|
||||
// 'page-section-list' => [
|
||||
// 'common' => [
|
||||
// 'fields' => ['list-type', 'list-items']
|
||||
// ]
|
||||
// ],
|
||||
'page-section-images' => [
|
||||
'common' => [
|
||||
'fields' => ['images-required']
|
||||
|
|
@ -45,9 +40,9 @@ class ObjectTypeFieldsTableSeeder extends Seeder {
|
|||
'fields' => ['documents-required']
|
||||
]
|
||||
],
|
||||
'page-section-videos' => [
|
||||
'page-section-video' => [
|
||||
'common' => [
|
||||
'fields' => []
|
||||
'fields' => ['video-url']
|
||||
]
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,22 +17,19 @@ class ObjectTypesTableSeeder extends Seeder {
|
|||
'page-section-header' => [
|
||||
'title' => 'Заголовок'
|
||||
],
|
||||
'page-section-text' => [
|
||||
'page-section-html' => [
|
||||
'title' => 'Текстовый блок'
|
||||
],
|
||||
'page-section-html' => [
|
||||
'title' => 'Текстовый блок с разметкой'
|
||||
],
|
||||
'page-section-list' => [
|
||||
'title' => 'Список'
|
||||
],
|
||||
// 'page-section-list' => [
|
||||
// 'title' => 'Список'
|
||||
// ],
|
||||
'page-section-images' => [
|
||||
'title' => 'Изображения'
|
||||
],
|
||||
'page-section-documents' => [
|
||||
'title' => 'Документы'
|
||||
],
|
||||
'page-section-videos' => [
|
||||
'page-section-video' => [
|
||||
'title' => 'Видео'
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -12,11 +12,7 @@ class PagesTableSeeder extends Seeder
|
|||
public array $pages = [
|
||||
'О центре' => [
|
||||
'children' => [
|
||||
'Руководство' => [
|
||||
'children' => [
|
||||
|
||||
]
|
||||
],
|
||||
'Руководство' => [],
|
||||
'Документы' => [
|
||||
'children' => [
|
||||
'Документы об учреждении' => [],
|
||||
|
|
@ -28,9 +24,7 @@ class PagesTableSeeder extends Seeder
|
|||
'Специальная оценка условий труда' => []
|
||||
]
|
||||
],
|
||||
'Структура' => [
|
||||
|
||||
],
|
||||
'Структура' => [],
|
||||
'Наблюдательный совет' => [
|
||||
'children' => [
|
||||
'Структура' => [],
|
||||
|
|
@ -38,9 +32,7 @@ class PagesTableSeeder extends Seeder
|
|||
'Решения' => []
|
||||
]
|
||||
],
|
||||
'Закупки' => [
|
||||
|
||||
],
|
||||
'Закупки' => [],
|
||||
'Противодействие коррупции' => [
|
||||
'children' => [
|
||||
'ФЗ, указы, постановления' => [],
|
||||
|
|
@ -136,8 +128,7 @@ class PagesTableSeeder extends Seeder
|
|||
'Контакты для СМИ' => [],
|
||||
]
|
||||
],
|
||||
'Контакты' => [
|
||||
]
|
||||
'Контакты' => []
|
||||
];
|
||||
|
||||
public function run()
|
||||
|
|
|
|||
|
|
@ -56,4 +56,7 @@ Route::group(['middleware' => ['auth:api']], function() {
|
|||
Route::get('filters/{type}', 'Api\Forms\FormsController@filters');
|
||||
|
||||
Route::get('dadata/{inn}', 'Api\Companies\CompaniesController@getDataByInn');
|
||||
|
||||
Route::put('publications/published/{id}', 'Api\Publications\PublicationsController@published');
|
||||
Route::delete('publications/{id}', 'Api\Publications\PublicationsController@destroy');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue