Merge remote-tracking branch 'origin/master'
commit
c4321fe7b1
|
|
@ -23,17 +23,10 @@ class PublicationsController extends Controller {
|
|||
}
|
||||
|
||||
public function index(Request $request): JsonResponse {
|
||||
$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);
|
||||
$user = Auth::user();
|
||||
if (!($user->isAdmin ?? null)) $query->where(['is_published' => true]);
|
||||
if ($page = Page::byUuid($request->get('page'))->first()) $query->where(['page_id' => $page->id]);
|
||||
$paginator = $query->paginate(config('app.pagination_limit'));
|
||||
return fractal($paginator, new PublicationTransformer())->respond();
|
||||
}
|
||||
|
|
@ -51,7 +44,7 @@ class PublicationsController extends Controller {
|
|||
public function update(Request $request, $uuid): void {
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $uuid) {
|
||||
public function destroy(Request $request, $uuid): JsonResponse {
|
||||
$model = $this->model->byUuid($uuid)->firstOrFail();
|
||||
$model->delete();
|
||||
return response()->json(null, 204);
|
||||
|
|
|
|||
|
|
@ -96,22 +96,9 @@ class Page extends Model {
|
|||
public static function byUrl($url) {
|
||||
if ($url = trim($url, '/ ')) {
|
||||
$query = self::query();
|
||||
$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]);
|
||||
});
|
||||
}
|
||||
collect(explode('/', $url))->reverse()->values()->each(function($slug, $index) use ($query) {
|
||||
if ($slug !== '') {
|
||||
$index ? $query->nthParentSlug($index, $slug) : $query->bySlug($slug);
|
||||
}
|
||||
});
|
||||
return $query->first();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use App\Models\Objects\NirObject;
|
|||
use App\Models\Objects\ObjectType;
|
||||
use App\Models\Pages\Page;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Publications\Publication;
|
||||
use App\Models\Role;
|
||||
use App\Models\SocialProvider;
|
||||
use App\Models\User;
|
||||
|
|
@ -55,7 +56,8 @@ class AppServiceProvider extends ServiceProvider
|
|||
'object' => NirObject::class,
|
||||
'object-type' => ObjectType::class,
|
||||
|
||||
'page' => Page::class
|
||||
'page' => Page::class,
|
||||
'publication' => Publication::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,6 @@ class PublicationForms extends FormsService {
|
|||
'required' => true,
|
||||
'value' => $model->excerpt ?? null
|
||||
],
|
||||
[
|
||||
'name' => 'description',
|
||||
'title' => 'Описание',
|
||||
'type' => FieldType::HTML,
|
||||
'value' => $model->description ?? null
|
||||
],
|
||||
[
|
||||
'name' => 'poster_id',
|
||||
'title' => 'Фотография профиля',
|
||||
|
|
@ -60,8 +54,8 @@ class PublicationForms extends FormsService {
|
|||
|
||||
|
||||
public function store(array $data): ?JsonResponse {
|
||||
if (!empty($data['attach']['page_slug'])) {
|
||||
$page = Page::query()->where(['slug' => $data['attach']['page_slug']])->first();
|
||||
if (!empty($data['attach']['page_id'])) {
|
||||
$page = Page::byUuid($data['attach']['page_id'])->first();
|
||||
$data['page_id'] = $page->id;
|
||||
}
|
||||
$data['user_id'] = Auth::user()->id;
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ class PagesTableSeeder extends Seeder
|
|||
'children' => [
|
||||
'Новости' => ['type' => PageType::PUBLICATIONS],
|
||||
'СМИ о нас' => ['type' => PageType::REGISTRY],
|
||||
'Фотогалерея' => [],
|
||||
'Видеоархив' => [],
|
||||
'Фотогалерея' => ['type' => PageType::PUBLICATIONS],
|
||||
'Видеоархив' => ['type' => PageType::PUBLICATIONS],
|
||||
'Контакты для СМИ' => [],
|
||||
]
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue