PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / trunk
Kirki – Freeform Page Builder, Website Builder & Customizer vtrunk
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / Http / Controllers / Api / CollaborationCommentController.php
kirki / app / Http / Controllers / Api Last commit date
AppsController.php 2 months ago CollaborationCommentController.php 1 day ago CollaborationController.php 1 month ago CollectionController.php 1 month ago CollectionItemController.php 1 day ago EditorController.php 1 month ago FormController.php 3 weeks ago GlobalDataController.php 1 month ago MediaController.php 2 months ago PageController.php 1 month ago PageSettingsController.php 1 month ago PostController.php 1 month ago UserController.php 1 month ago
CollaborationCommentController.php
169 lines
1 <?php
2
3 namespace Kirki\App\Http\Controllers\Api;
4
5 use Kirki\App\Constants\AccessLevels;
6 use Kirki\App\DTO\CollaborationComment\CreateCollaborationCommentDTO;
7 use Kirki\App\DTO\CollaborationComment\DeleteCollaborationCommentDTO;
8 use Kirki\App\DTO\CollaborationComment\ResolveCollaborationCommentDTO;
9 use Kirki\App\DTO\CollaborationCommentListFilterDTO;
10 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentDestroyRequest;
11 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentResolveRequest;
12 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentStoreRequest;
13 use Kirki\App\Resources\CollaborationComment\CollaborationCommentResource;
14 use Kirki\App\Resources\CollaborationComment\CollaborationCommentUserResource;
15 use Kirki\App\Services\CollaborationCommentService;
16 use Kirki\Framework\Exceptions\AuthorizationException;
17 use Kirki\Framework\Http\Request;
18 use Kirki\Framework\Http\Response;
19
20 use function Kirki\Framework\message;
21 use function Kirki\Framework\response;
22 use function Kirki\Framework\user;
23
24 class CollaborationCommentController
25 {
26 /**
27 * @var CollaborationCommentService
28 */
29 protected $service;
30
31 public function __construct(CollaborationCommentService $service)
32 {
33 $this->service = $service;
34 }
35
36 /**
37 * Paginated listing of a post's top-level comments.
38 */
39 public function index(Request $request)
40 {
41 $filters = CollaborationCommentListFilterDTO::from_array([
42 'post_id' => $request->int('post_id'),
43 'page' => $request->int('page', 1),
44 'limit' => $request->int('limit', 20),
45 'user_id' => user()->get_id()
46 ]);
47
48 $paginator = $this->service->paginated($filters);
49
50 return response()->json([
51 'data' => CollaborationCommentResource::paginated($paginator),
52 'message' => __('Comments retrieved successfully.', 'kirki'),
53 ]);
54 }
55
56 /**
57 * Create a comment or reply.
58 */
59 public function store(CollaborationCommentStoreRequest $request)
60 {
61 $dto = CreateCollaborationCommentDTO::from_array($request->validated());
62 $dto->user_id = user()->get_id();
63
64 $comment = $this->service->create($dto);
65
66 return response()->json([
67 'data' => CollaborationCommentResource::make($comment),
68 'message' => __('Comment created successfully.', 'kirki'),
69 ], Response::CREATED);
70 }
71
72 /**
73 * Update a comment's status (e.g. mark resolved).
74 */
75 public function resolve(CollaborationCommentResolveRequest $request)
76 {
77 $dto = ResolveCollaborationCommentDTO::from_array($request->validated());
78 $dto->user_id = user()->get_id();
79
80 $comment = $this->service->resolve($dto);
81
82 return response()->json([
83 'data' => CollaborationCommentResource::make($comment),
84 'message' => __('Comment status updated successfully.', 'kirki'),
85 ]);
86 }
87
88 /**
89 * Search users for the @mention picker.
90 */
91 public function users(Request $request)
92 {
93 $users = $this->service->search_users(
94 $request->string('query', ''),
95 $request->int('limit', 20)
96 );
97
98 return response()->json([
99 'data' => CollaborationCommentUserResource::collection($users),
100 'message' => __('Users retrieved successfully.', 'kirki'),
101 ]);
102 }
103
104 /**
105 * Mark a comment as read.
106 */
107 public function read(Request $request)
108 {
109 $comment = $this->service->mark_read($request->int('id'), user()->get_id());
110
111 return response()->json([
112 'data' => CollaborationCommentResource::make($comment),
113 'message' => __('Comment marked as read.', 'kirki'),
114 ]);
115 }
116
117 /**
118 * Mark a comment as unread.
119 */
120 public function unread(Request $request)
121 {
122 $comment = $this->service->mark_unread($request->int('id'), user()->get_id());
123
124 return response()->json([
125 'data' => CollaborationCommentResource::make($comment),
126 'message' => __('Comment marked as unread.', 'kirki'),
127 ]);
128 }
129
130 /**
131 * Delete a comment and its replies (author or editor/administrator only).
132 */
133 public function destroy(CollaborationCommentDestroyRequest $request)
134 {
135 $dto = DeleteCollaborationCommentDTO::from_array($request->validated());
136
137 return response()->json([
138 'data' => $this->service->delete($dto),
139 'message' => __('Comment deleted successfully.', 'kirki'),
140 ]);
141 }
142
143 /**
144 * Mark every top-level comment of a post as read.
145 */
146 public function read_all(Request $request)
147 {
148 return response()->json([
149 'data' => $this->service->mark_all_read($request->int('post_id'), user()->get_id()),
150 'message' => __('All comments marked as read.', 'kirki'),
151 ]);
152 }
153
154 /**
155 * Resolve every top-level comment of a post.
156 */
157 public function resolve_all(Request $request)
158 {
159 if (!user()->has_access(AccessLevels::FULL_ACCESS)) {
160 throw new AuthorizationException(message('auth.unauthorized_request'));
161 }
162
163 return response()->json([
164 'data' => $this->service->resolve_all($request->int('post_id'), $request->string('session_id', '')),
165 'message' => __('All comments marked as resolved.', 'kirki'),
166 ]);
167 }
168 }
169