Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 228 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MetaDataController | |
0.00% |
0 / 228 |
|
0.00% |
0 / 3 |
3660 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
checkQuota | |
0.00% |
0 / 215 |
|
0.00% |
0 / 1 |
3306 | |||
checkOnlyQuota | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace App\Http\Controllers\v2; |
4 | |
5 | use App\Helpers\Constants; |
6 | use Illuminate\Http\Request; |
7 | use App\Traits\SubscriptionTrait; |
8 | use Illuminate\Http\JsonResponse; |
9 | use App\Http\Controllers\Controller; |
10 | use App\Http\Models\FlyGrammarActions; |
11 | use App\Http\Models\FlyGrammarLanguage; |
12 | use App\Http\Models\FlyMsgAI\UserDictionary; |
13 | use App\Http\Models\Parameter; |
14 | use App\Http\Services\WPSService; |
15 | use App\Services\FlyMsgAI\FlyMsgAIService; |
16 | |
17 | class MetaDataController extends Controller |
18 | { |
19 | use SubscriptionTrait; |
20 | |
21 | public function __construct( |
22 | private readonly FlyMsgAIService $ai_service, |
23 | private readonly WPSService $wpsService |
24 | |
25 | ) {} |
26 | |
27 | public function checkQuota(Request $request): JsonResponse |
28 | { |
29 | $user = $request->user(); |
30 | |
31 | $currentSubscriptionPlan = $this->getCurrentPlan($user); |
32 | $quota = $this->getFlyAIQuota($user); |
33 | $flycuts_quota = $this->getFlyCutsQuota($user); |
34 | $promptsQuota = $this->getPromptQuota($user); |
35 | $grammarQuota = $this->getGrammarQuota($user); |
36 | $parameter = Parameter::where('name', 'webspellchecker_api_key')->first(); |
37 | $flyCutCoupons = Parameter::where('name', 'fly_cut_update_coupons')->first(); |
38 | $flyGrammarCoupons = Parameter::where('name', 'fly_grammar_update_coupons')->first(); |
39 | $flyGrammarMessages = Parameter::where('name', 'fly_grammar_update_messages')->first(); |
40 | $flyGrammarPopupMessage = Parameter::where('name', 'fly_grammar_popup_message')->first(); |
41 | $flyGrammarDisabledOnFlyMsg = Parameter::where('name', 'fly_grammar_disabled_on_flymsg')->first(); |
42 | |
43 | $flyGrammarLanguagesAvailable = FlyGrammarLanguage::select(['value', 'description'])->orderBy('index') |
44 | ->get()->map(function ($item) { |
45 | return [ |
46 | 'id' => $item->value, |
47 | 'value' => $item->description, |
48 | ]; |
49 | })->toArray(); |
50 | |
51 | $plan = $this->getCurrentPlan($user); |
52 | $show_upgrade_button = empty($user->company_id) && $plan->identifier !== 'sales-pro-monthly' && $plan->identifier !== 'sales-pro-yearly'; |
53 | |
54 | $meta = [ |
55 | 'is_enterprise' => !empty($user->company_id) && $user->status !== 'Invited', |
56 | 'show_upgrade_button' => $show_upgrade_button, |
57 | 'quota' => $quota, |
58 | 'prompts_quota' => $promptsQuota, |
59 | 'flycuts_quota' => $flycuts_quota, |
60 | 'fly_grammar' => $parameter->value, |
61 | 'grammar_quota' => $grammarQuota, |
62 | 'fly_grammar_update_prompt' => $flyGrammarMessages?->value ?? ['Work smarter, not harder.'], |
63 | 'plan' => $currentSubscriptionPlan, |
64 | 'fly_grammar_languages_available' => $flyGrammarLanguagesAvailable, |
65 | 'fly_grammar_popup_message' => $flyGrammarPopupMessage?->value, |
66 | 'fly_grammar_disabled_on_flymsg' => $flyGrammarDisabledOnFlyMsg?->value ?? false, |
67 | 'user_dictionary' => $this->wpsService->getUserDictionary($user), |
68 | 'fly_cut_update_coupons' => $flyCutCoupons?->value |
69 | ? collect($flyCutCoupons->value)->sortBy('order')->values()->all() |
70 | : [ |
71 | [ |
72 | 'title' => 'Never Hit a Limit Again!', |
73 | 'description' => "You've hit your {quota} daily text expansion limit. Your next refill is in {next_refill}. See how many times we've deployed a FlyCut:", |
74 | 'code' => '30OFF', |
75 | 'cta' => 'Get 30% Off on Year 1!', |
76 | 'cta_instruction' => "On Page 2 of Checkout, Use this Code (click code to copy):", |
77 | 'cta_url' => config('romeo.frontend-base-url') . '/new-plan/YearlyGrowth', |
78 | 'color' => '#2A1E36', |
79 | 'order' => 1, |
80 | ], |
81 | ], |
82 | 'fly_grammar_update_coupons' => $flyGrammarCoupons?->value |
83 | ? collect($flyGrammarCoupons->value)->sortBy('order')->values()->all() |
84 | : [ |
85 | [ |
86 | 'title' => 'Unlock Unlimited Grammar Perfection!', |
87 | 'description' => "You've hit your {quota} daily spelling and grammar fixes. Your next refill is in {next_refill}. See how many improvements we've helped you make:", |
88 | 'code' => '30OFF', |
89 | 'cta' => 'Get 30% Off on Year 1!', |
90 | 'cta_instruction' => "On Page 2 of Checkout, Use this Code (click code to copy):", |
91 | 'cta_url' => config('romeo.frontend-base-url') . '/new-plan/YearlyGrowth', |
92 | 'color' => '#F15A2A', |
93 | 'order' => 1, |
94 | ], |
95 | ], |
96 | ]; |
97 | |
98 | $wsc_serviceProtocol = Parameter::where('name', 'wsc_serviceProtocol')->first(); |
99 | if ($wsc_serviceProtocol) { |
100 | $meta['wsc_serviceProtocol'] = $wsc_serviceProtocol->value; |
101 | } |
102 | |
103 | $wsc_servicePort = Parameter::where('name', 'wsc_servicePort')->first(); |
104 | if ($wsc_servicePort) { |
105 | $meta['wsc_servicePort'] = $wsc_servicePort->value; |
106 | } |
107 | |
108 | $wsc_serviceHost = Parameter::where('name', 'wsc_serviceHost')->first(); |
109 | if ($wsc_serviceHost) { |
110 | $meta['wsc_serviceHost'] = $wsc_serviceHost->value; |
111 | } |
112 | |
113 | $wsc_servicePath = Parameter::where('name', 'wsc_servicePath')->first(); |
114 | if ($wsc_servicePath) { |
115 | $meta['wsc_servicePath'] = $wsc_servicePath->value; |
116 | } |
117 | |
118 | $wsc_suggestionsCount = Parameter::where('name', 'wsc_suggestionsCount')->first(); |
119 | if ($wsc_suggestionsCount) { |
120 | $meta['wsc_suggestionsCount'] = $wsc_suggestionsCount->value; |
121 | } |
122 | |
123 | $wsc_cache_settings = Parameter::where('name', 'wsc_cache_settings')->first(); |
124 | if ($wsc_cache_settings) { |
125 | $meta['wsc_cache_settings'] = $wsc_cache_settings->value; |
126 | } |
127 | |
128 | $wsc_enableGrammar = Parameter::where('name', 'wsc_enableGrammar')->first(); |
129 | if ($wsc_enableGrammar) { |
130 | $meta['wsc_enableGrammar'] = $wsc_enableGrammar->value; |
131 | } |
132 | |
133 | $wsc_disableStyleGuide = Parameter::where('name', 'wsc_disableStyleGuide')->first(); |
134 | if ($wsc_disableStyleGuide) { |
135 | $meta['wsc_disableStyleGuide'] = $wsc_disableStyleGuide->value; |
136 | } |
137 | |
138 | $wsc_actionItems = Parameter::where('name', 'wsc_actionItems')->first(); |
139 | if ($wsc_actionItems) { |
140 | $meta['wsc_actionItems'] = $wsc_actionItems->value; |
141 | } |
142 | |
143 | $wsc_customDictionaryIds = Parameter::where('name', 'wsc_customDictionaryIds')->first(); |
144 | if ($wsc_customDictionaryIds) { |
145 | $meta['wsc_customDictionaryIds'] = $wsc_customDictionaryIds->value; |
146 | } |
147 | |
148 | $wsc_userDictionaryName = Parameter::where('name', 'wsc_userDictionaryName')->first(); |
149 | if ($wsc_userDictionaryName) { |
150 | $meta['wsc_userDictionaryName'] = $wsc_userDictionaryName->value; |
151 | } |
152 | |
153 | $wsc_settingsSections = Parameter::where('name', 'wsc_settingsSections')->first(); |
154 | if ($wsc_settingsSections) { |
155 | $meta['wsc_settingsSections'] = $wsc_settingsSections->value; |
156 | } |
157 | |
158 | $wsc_ignoreElements = Parameter::where('name', 'wsc_ignoreElements')->first(); |
159 | if ($wsc_ignoreElements) { |
160 | $meta['wsc_ignoreElements'] = $wsc_ignoreElements->value; |
161 | } |
162 | |
163 | $wsc_ignoreClasses = Parameter::where('name', 'wsc_ignoreClasses')->first(); |
164 | if ($wsc_ignoreClasses) { |
165 | $meta['wsc_ignoreClasses'] = $wsc_ignoreClasses->value; |
166 | } |
167 | |
168 | $wsc_ignoreAttributes = Parameter::where('name', 'wsc_ignoreAttributes')->first(); |
169 | if ($wsc_ignoreAttributes) { |
170 | $meta['wsc_ignoreAttributes'] = $wsc_ignoreAttributes->value; |
171 | } |
172 | |
173 | $wsc_ignoreAllCapsWords = Parameter::where('name', 'wsc_ignoreAllCapsWords')->first(); |
174 | if ($wsc_ignoreAllCapsWords) { |
175 | $meta['wsc_ignoreAllCapsWords'] = $wsc_ignoreAllCapsWords->value; |
176 | } |
177 | |
178 | $wsc_ignoreDomainNames = Parameter::where('name', 'wsc_ignoreDomainNames')->first(); |
179 | if ($wsc_ignoreDomainNames) { |
180 | $meta['wsc_ignoreDomainNames'] = $wsc_ignoreDomainNames->value; |
181 | } |
182 | |
183 | $wsc_ignoreWordsWithMixedCases = Parameter::where('name', 'wsc_ignoreWordsWithMixedCases')->first(); |
184 | if ($wsc_ignoreWordsWithMixedCases) { |
185 | $meta['wsc_ignoreWordsWithMixedCases'] = $wsc_ignoreWordsWithMixedCases->value; |
186 | } |
187 | |
188 | $wsc_ignoreWordsWithNumbers = Parameter::where('name', 'wsc_ignoreWordsWithNumbers')->first(); |
189 | if ($wsc_ignoreWordsWithNumbers) { |
190 | $meta['wsc_ignoreWordsWithNumbers'] = $wsc_ignoreWordsWithNumbers->value; |
191 | } |
192 | |
193 | $wsc_enableBadgeButton = Parameter::where('name', 'wsc_enableBadgeButton')->first(); |
194 | if ($wsc_enableBadgeButton) { |
195 | $meta['wsc_enableBadgeButton'] = $wsc_enableBadgeButton->value; |
196 | } |
197 | |
198 | $wsc_enableLanguagesInBadgeButton = Parameter::where('name', 'wsc_enableLanguagesInBadgeButton')->first(); |
199 | if ($wsc_enableLanguagesInBadgeButton) { |
200 | $meta['wsc_enableLanguagesInBadgeButton'] = $wsc_enableLanguagesInBadgeButton->value; |
201 | } |
202 | |
203 | $wsc_fullSizeBadge = Parameter::where('name', 'wsc_fullSizeBadge')->first(); |
204 | if ($wsc_fullSizeBadge) { |
205 | $meta['wsc_fullSizeBadge'] = $wsc_fullSizeBadge->value; |
206 | } |
207 | |
208 | $wsc_globalBadge = Parameter::where('name', 'wsc_globalBadge')->first(); |
209 | if ($wsc_globalBadge) { |
210 | $meta['wsc_globalBadge'] = $wsc_globalBadge->value; |
211 | } |
212 | |
213 | $wsc_compactBadge = Parameter::where('name', 'wsc_compactBadge')->first(); |
214 | if ($wsc_compactBadge) { |
215 | $meta['wsc_compactBadge'] = $wsc_compactBadge->value; |
216 | } |
217 | |
218 | $wsc_badgeOffsetX = Parameter::where('name', 'wsc_badgeOffsetX')->first(); |
219 | if ($wsc_badgeOffsetX) { |
220 | $meta['wsc_badgeOffsetX'] = $wsc_badgeOffsetX->value; |
221 | } |
222 | |
223 | $wsc_badgeOffsetY = Parameter::where('name', 'wsc_badgeOffsetY')->first(); |
224 | if ($wsc_badgeOffsetY) { |
225 | $meta['wsc_badgeOffsetY'] = $wsc_badgeOffsetY->value; |
226 | } |
227 | |
228 | $wsc_badgeZIndex = Parameter::where('name', 'wsc_badgeZIndex')->first(); |
229 | if ($wsc_badgeZIndex) { |
230 | $meta['wsc_badgeZIndex'] = $wsc_badgeZIndex->value; |
231 | } |
232 | |
233 | $wsc_disableDictionariesPreferences = Parameter::where('name', 'wsc_disableDictionariesPreferences')->first(); |
234 | if ($wsc_disableDictionariesPreferences) { |
235 | $meta['wsc_disableDictionariesPreferences'] = $wsc_disableDictionariesPreferences->value; |
236 | } |
237 | |
238 | $wsc_removeBranding = Parameter::where('name', 'wsc_removeBranding')->first(); |
239 | if ($wsc_removeBranding) { |
240 | $meta['wsc_removeBranding'] = $wsc_removeBranding->value; |
241 | } |
242 | |
243 | $wsc_requestTokensCount = Parameter::where('name', 'wsc_requestTokensCount')->first(); |
244 | if ($wsc_requestTokensCount) { |
245 | $meta['wsc_requestTokensCount'] = $wsc_requestTokensCount->value; |
246 | } |
247 | |
248 | $wsc_disableDialog = Parameter::where('name', 'wsc_disableDialog')->first(); |
249 | if ($wsc_disableDialog) { |
250 | $meta['wsc_disableDialog'] = $wsc_disableDialog->value; |
251 | } |
252 | |
253 | $wsc_disabledRules = Parameter::where('name', 'wsc_disabledRules')->first(); |
254 | if ($wsc_disabledRules) { |
255 | $meta['wsc_disabledRules'] = $wsc_disabledRules->value; |
256 | } |
257 | |
258 | $wsc_restoreNativeSpellCheck = Parameter::where('name', 'wsc_restoreNativeSpellCheck')->first(); |
259 | if ($wsc_restoreNativeSpellCheck) { |
260 | $meta['wsc_restoreNativeSpellCheck'] = $wsc_restoreNativeSpellCheck->value; |
261 | } |
262 | |
263 | $wsc_syncOptions = Parameter::where('name', 'wsc_syncOptions')->first(); |
264 | if ($wsc_syncOptions) { |
265 | $meta['wsc_syncOptions'] = $wsc_syncOptions->value; |
266 | } |
267 | |
268 | $wsc_globalProofreadDialog = Parameter::where('name', 'wsc_globalProofreadDialog')->first(); |
269 | if ($wsc_globalProofreadDialog) { |
270 | $meta['wsc_globalProofreadDialog'] = $wsc_globalProofreadDialog->value; |
271 | } |
272 | |
273 | $wsc_allSuggestionsMode = Parameter::where('name', 'wsc_allSuggestionsMode')->first(); |
274 | if ($wsc_allSuggestionsMode) { |
275 | $meta['wsc_allSuggestionsMode'] = $wsc_allSuggestionsMode->value; |
276 | } |
277 | |
278 | $wsc_proofreadDialogContainer = Parameter::where('name', 'wsc_proofreadDialogContainer')->first(); |
279 | if ($wsc_proofreadDialogContainer) { |
280 | $meta['wsc_proofreadDialogContainer'] = $wsc_proofreadDialogContainer->value; |
281 | } |
282 | |
283 | $wsc_spellingSuggestions = Parameter::where('name', 'wsc_spellingSuggestions')->first(); |
284 | if ($wsc_spellingSuggestions) { |
285 | $meta['wsc_spellingSuggestions'] = $wsc_spellingSuggestions->value; |
286 | } |
287 | |
288 | $wsc_grammarSuggestions = Parameter::where('name', 'wsc_grammarSuggestions')->first(); |
289 | if ($wsc_grammarSuggestions) { |
290 | $meta['wsc_grammarSuggestions'] = $wsc_grammarSuggestions->value; |
291 | } |
292 | |
293 | $wsc_styleGuideSuggestions = Parameter::where('name', 'wsc_styleGuideSuggestions')->first(); |
294 | if ($wsc_styleGuideSuggestions) { |
295 | $meta['wsc_styleGuideSuggestions'] = $wsc_styleGuideSuggestions->value; |
296 | } |
297 | |
298 | $wsc_cache = Parameter::where('name', 'wsc_cache')->first(); |
299 | if ($wsc_cache) { |
300 | $meta['wsc_cache'] = $wsc_cache->value; |
301 | } |
302 | |
303 | $wsc_autocorrect = Parameter::where('name', 'wsc_autocorrect')->first(); |
304 | if ($wsc_autocorrect) { |
305 | $meta['wsc_autocorrect'] = $wsc_autocorrect->value; |
306 | } |
307 | |
308 | $wsc_autocomplete = Parameter::where('name', 'wsc_autocomplete')->first(); |
309 | if ($wsc_autocomplete) { |
310 | $meta['wsc_autocomplete'] = $wsc_autocomplete->value; |
311 | } |
312 | |
313 | $wsc_checkOnSpace = Parameter::where('name', 'wsc_checkOnSpace')->first(); |
314 | if ($wsc_checkOnSpace) { |
315 | $meta['wsc_checkOnSpace'] = $wsc_checkOnSpace->value; |
316 | } |
317 | |
318 | $wsc_disableProblemDescription = Parameter::where('name', 'wsc_disableProblemDescription')->first(); |
319 | if ($wsc_disableProblemDescription) { |
320 | $meta['wsc_disableProblemDescription'] = $wsc_disableProblemDescription->value; |
321 | } |
322 | |
323 | $wsc_globalBadgeForceList = Parameter::where('name', 'wsc_globalBadgeForceList')->first(); |
324 | if ($wsc_globalBadgeForceList) { |
325 | $meta['wsc_globalBadgeForceList'] = $wsc_globalBadgeForceList->value; |
326 | } |
327 | |
328 | $wsc_forceFullBadgeList = Parameter::where('name', 'wsc_forceFullBadgeList')->first(); |
329 | if ($wsc_forceFullBadgeList) { |
330 | $meta['wsc_forceFullBadgeList'] = $wsc_forceFullBadgeList->value; |
331 | } |
332 | |
333 | $wsc_showLanguageBlackList = Parameter::where('name', 'wsc_showLanguageBlackList')->first(); |
334 | if ($wsc_showLanguageBlackList) { |
335 | $meta['wsc_showLanguageBlackList'] = $wsc_showLanguageBlackList->value; |
336 | } |
337 | |
338 | $wsc_aiWritingAssistant = Parameter::where('name', 'wsc_aiWritingAssistant')->first(); |
339 | if ($wsc_aiWritingAssistant) { |
340 | $meta['wsc_aiWritingAssistant'] = $wsc_aiWritingAssistant->value; |
341 | } |
342 | |
343 | if ($grammarQuota['remaining'] >= 0 && $grammarQuota['total'] !== -1) { |
344 | $meta['wsc_autocorrect'] = false; |
345 | $meta['wsc_autocomplete'] = false; |
346 | } |
347 | |
348 | return response()->json($meta); |
349 | } |
350 | |
351 | public function checkOnlyQuota(Request $request): JsonResponse |
352 | { |
353 | $user = $request->user(); |
354 | |
355 | $currentSubscriptionPlan = $this->getCurrentPlan($user); |
356 | $quota = $this->getFlyAIQuota($user); |
357 | $promptsQuota = $this->getPromptQuota($user); |
358 | $grammarQuota = $this->getGrammarQuota($user); |
359 | |
360 | return response()->json([ |
361 | 'is_enterprise' => !empty($user->company_id) && $user->status !== 'Invited', |
362 | 'quota' => $quota, |
363 | 'prompts_quota' => $promptsQuota, |
364 | 'grammar_quota' => $grammarQuota, |
365 | 'plan' => $currentSubscriptionPlan |
366 | ]); |
367 | } |
368 | } |