PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.16
Yatra – Travel Booking & Tour Operator Software v3.0.16
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
← All changes | app/Services/ReviewService.php +89 -4 3.0.2.6 → 3.0.16 View file →
@@ -154,10 +154,83 @@
154 154 ];
155 155 }
156 156
157 157 /**
158 + * Create a review on behalf of a customer (admin path).
159 + *
160 + * Differs from {@see submitReview()} in three deliberate ways:
161 + *
162 + * 1. Skips the "already reviewed this trip" guard. An admin entering
163 + * a customer's quote from email isn't a duplicate the user can fix.
164 + * 2. Skips the `reviews.auto_approve` setting lookup. The status
165 + * arrives from the operator (already enum-clamped by the
166 + * controller) and is the source of truth.
167 + * 3. Doesn't fall back to the current user's display_name/email as
168 + * reviewer — admins enter the customer's identity by hand.
169 + *
170 + * Field aliasing (customer_name → author_name etc.) is handled at the
171 + * controller layer; this method receives canonical column names only.
172 + *
173 + * @param array $data Canonical review payload: trip_id, rating, title,
174 + * content, author_name, author_email, status,
175 + * optional created_by.
176 + * @return array {success: bool, review_id?: int, message: string}
177 + */
178 + public function createReviewAsAdmin(array $data): array
179 + {
180 + if (empty($data['trip_id']) || empty($data['rating'])) {
181 + return ['success' => false, 'message' => __('Trip and rating are required.', 'yatra')];
182 + }
183 +
184 + $trip = $this->tripRepository->find((int) $data['trip_id']);
185 + if (!$trip) {
186 + return ['success' => false, 'message' => __('Trip not found.', 'yatra')];
187 + }
188 +
189 + $rating = (int) $data['rating'];
190 + if ($rating < 1 || $rating > 5) {
191 + return ['success' => false, 'message' => __('Rating must be between 1 and 5.', 'yatra')];
192 + }
193 +
194 + if (empty($data['author_name'])) {
195 + return ['success' => false, 'message' => __('Customer name is required.', 'yatra')];
196 + }
197 + if (empty($data['content'])) {
198 + return ['success' => false, 'message' => __('Review content is required.', 'yatra')];
199 + }
200 +
201 + // Default status only when the controller didn't supply one. The
202 + // controller already clamps the value against the ENUM so we
203 + // trust it as-is when present.
204 + if (!isset($data['status']) || $data['status'] === '') {
205 + $data['status'] = 'pending';
206 + }
207 +
208 + try {
209 + $reviewId = $this->reviewRepository->create($data);
210 + } catch (\Throwable $e) {
211 + return [
212 + 'success' => false,
213 + 'message' => __('Failed to create review.', 'yatra') . ' ' . $e->getMessage(),
214 + ];
215 + }
216 +
217 + if (!$reviewId) {
218 + return ['success' => false, 'message' => __('Failed to create review.', 'yatra')];
219 + }
220 +
221 + $this->updateTripRatingCache((int) $data['trip_id']);
222 +
223 + return [
224 + 'success' => true,
225 + 'review_id' => $reviewId,
226 + 'message' => __('Review created successfully.', 'yatra'),
227 + ];
228 + }
229 +
230 + /**
158 231 * Update a review
159 - *
232 + *
160 233 * @param int $id Review ID
161 234 * @param array $data Review data
162 235 * @return array {success: bool, message: string}
163 236 */
@@ -231,9 +304,13 @@
231 304 $this->updateTripRatingCache((int) $review->trip_id);
232 305
233 306 return [
234 307 'success' => true,
235 - 'message' => sprintf(__('Review status updated to %s.', 'yatra'), $status),
308 + 'message' => sprintf(
309 + /* translators: %s: new review status. */
310 + __('Review status updated to %s.', 'yatra'),
311 + $status
312 + ),
236 313 ];
237 314 }
238 315
239 316 /**
@@ -255,9 +332,13 @@
255 332
256 333 return [
257 334 'success' => true,
258 335 'affected' => $affected,
259 - 'message' => sprintf(__('%d reviews updated.', 'yatra'), $affected),
336 + 'message' => sprintf(
337 + /* translators: %d: number of reviews updated. */
338 + __('%d reviews updated.', 'yatra'),
339 + $affected
340 + ),
260 341 ];
261 342 }
262 343
263 344 /**
@@ -272,9 +353,13 @@
272 353
273 354 return [
274 355 'success' => true,
275 356 'affected' => $affected,
276 - 'message' => sprintf(__('%d reviews deleted.', 'yatra'), $affected),
357 + 'message' => sprintf(
358 + /* translators: %d: number of reviews deleted. */
359 + __('%d reviews deleted.', 'yatra'),
360 + $affected
361 + ),
277 362 ];
278 363 }
279 364
280 365 /**