Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
membrubackend
/
app
/
Http
/
Resources
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
UserResource.php
| Size :
3.13
KB
Copy
<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; use App\Models\User; use Auth; use Carbon\Carbon; class UserResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $authUser = Auth::user(); $today = Carbon::today()->toDateString(); $todayPromise = $this->todayPromise(); if($todayPromise){ $keyResultsNames = $todayPromise->key_results->map(function ($keyResult) use ($authUser) { // check if this auth user can see a private objective if(!$authUser->isAdmin() && isPrivateObjective($keyResult->objective_id, $authUser)){ return false; } return $keyResult->name; })->filter()->toArray(); } $promise = $todayPromise ? [ 'name' => $todayPromise->name, 'key_results_names' => $keyResultsNames ? implode(', ', $keyResultsNames) : null, ] : null; // check if the user is the first one who register and block delete $canDeleteUser = $this->registration_email ? false : true; return [ 'id' => $this->id, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'email' => $this->email, 'slug' => $this->slug, 'language' => $this->language, 'instance_id' => $this->instance_id, 'role_id' => $this->role_id, 'role_name' => $this->role ? $this->role->name : null, 'avatar' => $this->avatar, 'working_days' => $this->working_days ? explode(',', $this->working_days) : [], 'promise_time' => $this->promise_time, 'objectives_count' => $this->objectives()->where([['start_date', '<=', $today], ['end_date', '>=', $today]])->count(), 'key_results_count' => $this->key_results()->where([['start_date', '<=', $today], ['end_date', '>=', $today]])->count(), 'has_daily_promise' => $this->isWorkDay() ? ($todayPromise ? 'has_promise' : 'promise_not_set') : 'person_not_working_today', 'promise' => $promise, 'created_at' => $this->created_at, 'tags' => $this->tags->map(function ($tag) { return [ 'id' => $tag->id, 'name' => $tag->name, 'color_name' => $tag->color ? $tag->color->name : null, 'color_code' => $tag->color ? $tag->color->code : null, ]; }), 'rights' => [ 'edit' => $authUser->can('adminAndEntityInstance', [User::class, $this->resource]), 'delete' => $authUser->can('adminAndEntityInstance', [User::class, $this->resource]) && $authUser->id != $this->id && $canDeleteUser, ], ]; } }
Back