Файловый менеджер - Редактировать - /home/clickysoft/public_html/charliapp-v2.clickysoft.net/app/Traits/CollaboratorTrait.php
Назад
<?php namespace App\Traits; use App\Models\Book; use App\Models\Brainstorm; use App\Models\Outline; use App\Models\PlotPlanner; use App\Models\Timeline; use App\Models\Collaboration; use App\Models\Chapter; use App\Models\ChaptersCard; use App\Models\TimelineCharacter; use App\Models\TimelineEventType; use App\Models\TimelineEventBlock; use App\Models\BrainstormRound; use App\Models\User; use App\Http\Resources\Admin\BookResource; use App\Http\Resources\Admin\BrainstormResource; use App\Http\Resources\Admin\OutlineResource; use App\Http\Resources\Admin\PlotPlannerResource; use App\Http\Resources\Admin\TimelineResource; trait CollaboratorTrait { protected function getModelClass($type) { $modelClasses = [ 'books' => Book::class, 'seriess' => Series::class, 'brainstorms' => Brainstorm::class, 'outlines' => Outline::class, 'plot_planners' => PlotPlanner::class, 'timelines' => Timeline::class, 'chapters' => Chapter::class, 'chapters_cards' => ChaptersCard::class, 'timeline_characters' => TimelineCharacter::class, 'timeline_event_types' => TimelineEventType::class, 'timeline_event_blocks' => TimelineEventBlock::class, 'brainstorm_rounds' => BrainstormRound::class, ]; return $modelClasses[$type] ?? null; } protected function checkCollaboratorAccess($user, $type_record, $collaboratable_id, $collaboratable_type, $request, $next) { if ($user->id === $type_record?->user_id) { return $next($request); } $collaboration = Collaboration::where('collaboratable_id', $collaboratable_id) ->where('collaboratable_type', $collaboratable_type) ->where('user_id', $user->id) ->where('role', 'editor') ->first(); if ($collaboration) { return $next($request); } $book_collaboration = Collaboration::where('collaboratable_id', $type_record?->book_id) ->where('collaboratable_type', 'books') ->where('user_id', $user->id) ->where('role', 'editor') ->first(); if ($book_collaboration) { return $next($request); } return response(["success" => false, "message" => "Forbidden access."], 403); } protected function checkCollaboratorAccessShowAndGuest($user, $email, $type_record, $collaboratable_id, $collaboratable_type, $request, $next) { if ($user?->id === $type_record?->user_id) { return $next($request); } $collaboration = Collaboration::where('collaboratable_id', $collaboratable_id) ->where('collaboratable_type', $collaboratable_type) ->where('email', $email) ->first(); if ($collaboration) { return $next($request); } $book_collaboration = Collaboration::where('collaboratable_id', $type_record?->book_id) ->where('collaboratable_type', 'books') ->where('email', $email) ->first(); if ($book_collaboration) { return $next($request); } return response(["success" => false, "message" => "Forbidden access."], 403); } public function getCollaborators($type, $book) { $userId = auth()->id(); $specificModelIds = $this->getBookRelationalIds($type, $book); $bookCollaboratorsIds = Collaboration::where('collaboratable_type', 'books') ->where('collaboratable_id', $book->id) ->pluck('user_id') ->toArray(); $specificModelIdsCollaboration = Collaboration::whereIn('collaboratable_id', $specificModelIds) ->where('collaboratable_type', $type) ->where('user_id', '!=' , null) ->pluck('user_id') ->toArray(); $userIds = array_merge($bookCollaboratorsIds,$specificModelIdsCollaboration); $users = User::whereIn('id', $userIds)->latest()->get(); return $users; } public function getResourceClass($type) { $modelClasses = [ 'books' => BookResource::class, 'brainstorms' => BrainstormResource::class, 'outlines' => OutlineResource::class, 'plot_planners' => PlotPlannerResource::class, 'timelines' => TimelineResource::class, ]; return $modelClasses[$type] ?? null; } protected function getCollaboratorUrl($collaboration, $user) { $url = ''; if ($collaboration) { $types = [ 'books' => 'book-detail', 'brainstorms' => 'brainstorm', 'outlines' => 'outline', 'plot_planners' => 'plotline', 'timelines' => 'timeline', ]; if ($user && $collaboration->role == 'editor') { $type = $types[$collaboration->collaboratable_type] ?? null; $url = env("FRONT_APP_URL").'/'.$type.'/'.$collaboration->collaboratable_id; } else { $url = env("FRONT_APP_URL").'/guest-view/'.$collaboration->collaboratable_type.'/'.$collaboration->collaboratable_id.'?email='.$collaboration->email.'&key='.$collaboration->key; } } return $url; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка