Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
membrubackend
/
app
/
Http
/
Controllers
/
Api
/
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 :
KeyResultCommentController.php
| Size :
3.78
KB
Copy
<?php namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use App\Models\KeyResult; use App\Models\KeyResultComment; use App\Models\User; use App\Models\NotificationLog; use App\Http\Requests\KeyResultCommentFormRequest; use App\Http\Resources\KeyResultCommentCollection; use Illuminate\Database\Eloquent\ModelNotFoundException; use Auth; class KeyResultCommentController extends Controller { public function index(KeyResult $keyResult) { return new KeyResultCommentCollection( $keyResult->key_result_comments()->whereNull('parent_id')->latest()->get() ); } public function publicComments($keyResultUuid) { $authUser = Auth::user(); $keyResult = KeyResult::where('uuid', $keyResultUuid)->first(); // check if the entity is available for public if($keyResult){ if(($authUser && !$authUser->isAdmin() && isPrivateObjective($keyResult->objective_id, $authUser)) || (!$authUser && $keyResult->masterGoalShareStatus() == 'off')){ throw (new ModelNotFoundException); } return new KeyResultCommentCollection( $keyResult->key_result_comments()->whereNull('parent_id')->latest()->get() ); }else{ throw (new ModelNotFoundException); } } public function store(KeyResultCommentFormRequest $request) { $data = $request->validated(); $authUser = Auth::user(); $data['parent_id'] = $request->parent_id; $keyResultComment = KeyResultComment::create($data); $keyResult = $keyResultComment->key_result; if($keyResult->user_id != $authUser->id && $keyResult->user){ newKeyResultCommentMail($authUser, $keyResultComment); } NotificationLog::create([ 'username' => $keyResultComment->user->getFullName(), 'avatar' => $keyResultComment->user->avatar, 'entity_name' => $keyResult->name, 'objective_slug' => $keyResult->objective->slug, 'key_result_id' => $keyResultComment->key_result_id, 'type' => NotificationLog::KEY_RESULT_NEW_COMMENT, 'frontend_type' => NotificationLog::FE_COMMENTS, 'need_link' => 1, 'responsible_id' => $keyResult->user_id, 'for_all' => $keyResult->objective->is_private ? 0 : 1, 'for_auth_user' => $keyResult->user_id != $authUser->id ? 1 : 0, ]); if ($request->parent_id) { NotificationLog::create([ 'username' => $keyResultComment->user->getFullName(), 'avatar' => $keyResultComment->user->avatar, 'entity_name' => $keyResult->name, 'objective_slug' => $keyResult->objective->slug, 'key_result_id' => $keyResultComment->key_result_id, 'type' => NotificationLog::KEY_RESULT_REPLY_COMMENT, 'frontend_type' => NotificationLog::FE_COMMENTS, 'need_link' => 1, 'responsible_id' => $keyResult->user_id, 'for_all' => $keyResult->objective->is_private ? 0 : 1, 'for_auth_user' => 1, ]); } return response()->json([ 'status' => 'success', ], 200); } public function statusList() { return response()->json([ 'status' => 'success', 'data' => KeyResultComment::getStatusList(), ], 200); } public function update(KeyResultCommentFormRequest $request, KeyResultComment $keyResultComment) { $data = $request->validated(); $keyResultComment->update($data); return response()->json([ 'status' => 'success', 'data' => [], ], 200); } }
Back