PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.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 3 weeks ago CollaborationCommentController.php 3 weeks ago CollectionController.php 3 weeks ago CollectionItemController.php 3 weeks ago EditorController.php 3 weeks ago GlobalDataController.php 4 days ago MediaController.php 3 weeks ago PageController.php 4 days ago PageSettingsController.php 3 weeks ago UserController.php 3 weeks ago
CollaborationCommentController.php
162 lines
1 <?php
2
3 namespace Kirki\App\Http\Controllers\Api;
4
5 use Kirki\App\DTO\CollaborationComment\CreateCollaborationCommentDTO;
6 use Kirki\App\DTO\CollaborationComment\DeleteCollaborationCommentDTO;
7 use Kirki\App\DTO\CollaborationComment\ResolveCollaborationCommentDTO;
8 use Kirki\App\DTO\CollaborationCommentListFilterDTO;
9 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentDestroyRequest;
10 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentResolveRequest;
11 use Kirki\App\Http\Requests\CollaborationComment\CollaborationCommentStoreRequest;
12 use Kirki\App\Resources\CollaborationComment\CollaborationCommentResource;
13 use Kirki\App\Resources\CollaborationComment\CollaborationCommentUserResource;
14 use Kirki\App\Services\CollaborationCommentService;
15 use Kirki\Framework\Http\Request;
16 use Kirki\Framework\Http\Response;
17
18 use function Kirki\Framework\response;
19 use function Kirki\Framework\user;
20
21 class CollaborationCommentController
22 {
23 /**
24 * @var CollaborationCommentService
25 */
26 protected $service;
27
28 public function __construct(CollaborationCommentService $service)
29 {
30 $this->service = $service;
31 }
32
33 /**
34 * Paginated listing of a post's top-level comments.
35 */
36 public function index(Request $request)
37 {
38 $filters = CollaborationCommentListFilterDTO::from_array([
39 'post_id' => $request->int('post_id'),
40 'page' => $request->int('page', 1),
41 'limit' => $request->int('limit', 20),
42 'user_id' => user()->get_id()
43 ]);
44
45 $paginator = $this->service->paginated($filters);
46
47 return response()->json([
48 'data' => CollaborationCommentResource::paginated($paginator),
49 'message' => __('Comments retrieved successfully.', 'kirki'),
50 ]);
51 }
52
53 /**
54 * Create a comment or reply.
55 */
56 public function store(CollaborationCommentStoreRequest $request)
57 {
58 $dto = CreateCollaborationCommentDTO::from_array($request->validated());
59 $dto->user_id = user()->get_id();
60
61 $comment = $this->service->create($dto);
62
63 return response()->json([
64 'data' => CollaborationCommentResource::make($comment),
65 'message' => __('Comment created successfully.', 'kirki'),
66 ], Response::CREATED);
67 }
68
69 /**
70 * Update a comment's status (e.g. mark resolved).
71 */
72 public function resolve(CollaborationCommentResolveRequest $request)
73 {
74 $dto = ResolveCollaborationCommentDTO::from_array($request->validated());
75 $dto->user_id = user()->get_id();
76
77 $comment = $this->service->resolve($dto);
78
79 return response()->json([
80 'data' => CollaborationCommentResource::make($comment),
81 'message' => __('Comment status updated successfully.', 'kirki'),
82 ]);
83 }
84
85 /**
86 * Search users for the @mention picker.
87 */
88 public function users(Request $request)
89 {
90 $users = $this->service->search_users(
91 $request->string('query', ''),
92 $request->int('limit', 20)
93 );
94
95 return response()->json([
96 'data' => CollaborationCommentUserResource::collection($users),
97 'message' => __('Users retrieved successfully.', 'kirki'),
98 ]);
99 }
100
101 /**
102 * Mark a comment as read.
103 */
104 public function read(Request $request)
105 {
106 $comment = $this->service->mark_read($request->int('id'), user()->get_id());
107
108 return response()->json([
109 'data' => CollaborationCommentResource::make($comment),
110 'message' => __('Comment marked as read.', 'kirki'),
111 ]);
112 }
113
114 /**
115 * Mark a comment as unread.
116 */
117 public function unread(Request $request)
118 {
119 $comment = $this->service->mark_unread($request->int('id'), user()->get_id());
120
121 return response()->json([
122 'data' => CollaborationCommentResource::make($comment),
123 'message' => __('Comment marked as unread.', 'kirki'),
124 ]);
125 }
126
127 /**
128 * Delete a comment and its replies (author or editor/administrator only).
129 */
130 public function destroy(CollaborationCommentDestroyRequest $request)
131 {
132 $dto = DeleteCollaborationCommentDTO::from_array($request->validated());
133
134 return response()->json([
135 'data' => $this->service->delete($dto),
136 'message' => __('Comment deleted successfully.', 'kirki'),
137 ]);
138 }
139
140 /**
141 * Mark every top-level comment of a post as read.
142 */
143 public function read_all(Request $request)
144 {
145 return response()->json([
146 'data' => $this->service->mark_all_read($request->int('post_id'), user()->get_id()),
147 'message' => __('All comments marked as read.', 'kirki'),
148 ]);
149 }
150
151 /**
152 * Resolve every top-level comment of a post.
153 */
154 public function resolve_all(Request $request)
155 {
156 return response()->json([
157 'data' => $this->service->resolve_all($request->int('post_id'), $request->string('session_id', '')),
158 'message' => __('All comments marked as resolved.', 'kirki'),
159 ]);
160 }
161 }
162