Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 297
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserDashboardController
0.00% covered (danger)
0.00%
0 / 297
0.00% covered (danger)
0.00%
0 / 4
8190
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 statistics
0.00% covered (danger)
0.00%
0 / 127
0.00% covered (danger)
0.00%
0 / 1
1482
 extension
0.00% covered (danger)
0.00%
0 / 54
0.00% covered (danger)
0.00%
0 / 1
2
 restrictions
0.00% covered (danger)
0.00%
0 / 115
0.00% covered (danger)
0.00%
0 / 1
2550
1<?php
2
3namespace App\Http\Controllers\v1;
4
5use DOMDocument;
6use App\Http\Models\Plans;
7use Illuminate\Http\Request;
8use App\Http\Models\Shortcut;
9use App\Http\Models\Template;
10use App\Http\Models\Auth\User;
11use App\Http\Models\FlyCutUsage;
12use App\Traits\SubscriptionTrait;
13use Illuminate\Http\JsonResponse;
14use Illuminate\Support\Facades\DB;
15use Illuminate\Support\Facades\Log;
16use App\Http\Controllers\Controller;
17use App\Http\Models\FlyMsgUserDailyUsage;
18use App\Http\Models\TemplateCategory;
19use App\Http\Models\HubspotProperties;
20use App\Http\Models\UserInfo;
21use App\Http\Services\StatisticsService;
22
23class UserDashboardController extends Controller
24{
25    use SubscriptionTrait;
26
27    /**
28     * The statistics service implementation.
29     *
30     * @var StatisticsService
31     */
32    protected $statisticsService;
33
34    /**
35     * Create a new controller instance.
36     *
37     *
38     * @return void
39     */
40    public function __construct(StatisticsService $statisticsService)
41    {
42        $this->statisticsService = $statisticsService;
43    }
44
45    /**
46     * Get the statistics record for the user
47     */
48    public function statistics(Request $request): JsonResponse
49    {
50        $user = $request->user();
51
52        $allParameters = $request->all();
53
54        $current_subscription = $this->getCurrentPlan($user)->toArray();
55        $features = $current_subscription["features"];
56
57        $shortcutCount = Shortcut::count();
58        $searchArray = ['user_defined' => false];
59        $templateAddedCount = Shortcut::where($searchArray)->count();
60
61        $total_allowed_shortcuts = $features['Number of FlyCuts that can be created'];
62        $total_allowed_categories = $features['Categories'];
63
64        // Check for general category Flyplates counts in DB
65        $categoryWhere = ['slug' => 'general'];
66        $category_id = TemplateCategory::where($categoryWhere)->pluck('_id')->first();
67
68        $templatesWhere = ['category_id' => $category_id];
69        $templateCounts = Template::where($templatesWhere)->count();
70
71        if ($current_subscription['identifier'] == Plans::FREEMIUM_IDENTIFIER) {
72            $features["FlyPlates"] = $templateCounts;
73        } else if (
74            $current_subscription['identifier'] == Plans::STARTER_MONTHLY_IDENTIFIER ||
75            $current_subscription['identifier'] == Plans::STARTER_YEARLY_IDENTIFIER
76        ) {
77            $features["FlyPlates"] = $templateCounts + intval(50);
78        }
79
80        // for flyrewards restrictions
81
82        $is_rewardable = (isset($user->rewardable)) ? $user->rewardable : '';
83        $rewards_level = (isset($user->rewards_level)) ? $user->rewards_level : '';
84
85        if ($is_rewardable) {
86            switch ($rewards_level) {
87                case 1:
88                    $total_allowed_shortcuts = -1;
89                    $features['Number of FlyCuts that can be created'] = $total_allowed_shortcuts;
90                    break;
91
92                case 2:
93                    $total_allowed_shortcuts = -1;
94                    $features['Number of FlyCuts that can be created'] = $total_allowed_shortcuts;
95
96                    $total_allowed_characters = -1;
97                    $features['Number of Characters that can be used per flycut'] = $total_allowed_characters;
98                    break;
99
100                case 3:
101                    $total_allowed_shortcuts = -1;
102                    $features['Number of FlyCuts that can be created'] = $total_allowed_shortcuts;
103
104                    $total_allowed_characters = -1;
105                    $features['Number of Characters that can be used per flycut'] = $total_allowed_characters;
106
107                    // check the plan and accordingly allowed user for the extra category
108                    if (
109                        $current_subscription['identifier'] == Plans::FREEMIUM_IDENTIFIER ||
110                        $current_subscription['identifier'] == Plans::STARTER_MONTHLY_IDENTIFIER ||
111                        $current_subscription['identifier'] == Plans::STARTER_YEARLY_IDENTIFIER
112                    ) {
113                        $total_allowed_categories = $total_allowed_categories + 1;
114                        $features['Categories'] = $total_allowed_categories;
115                    }
116                    break;
117
118                case $rewards_level >= 4:
119                    $total_allowed_shortcuts = -1;
120                    $features['Number of FlyCuts that can be created'] = $total_allowed_shortcuts;
121
122                    $total_allowed_characters = -1;
123                    $features['Number of Characters that can be used per flycut'] = $total_allowed_characters;
124
125                    $total_flyplates_allowed = -1;
126                    $features['FlyPlates'] = $total_flyplates_allowed;
127
128                    // check the plan and accordingly allowed user for the extra category
129                    if (
130                        $current_subscription['identifier'] == Plans::FREEMIUM_IDENTIFIER ||
131                        $current_subscription['identifier'] == Plans::STARTER_MONTHLY_IDENTIFIER ||
132                        $current_subscription['identifier'] == Plans::STARTER_YEARLY_IDENTIFIER
133                    ) {
134                        $total_allowed_categories = $total_allowed_categories + 1;
135                        $features['Categories'] = $total_allowed_categories;
136                    }
137                    break;
138            }
139        }
140
141        $fromDate = $this->statisticsService->getDateFromNow($request->query('differenceFromNow'), $request->query('dateType'));
142        $from = $this->statisticsService->getDateFromNowInMonthYear($request->query('differenceFromNow'), $request->query('dateType'));
143
144        $hubspotRecord = HubspotProperties::firstWhere('flymsg_id', $user->getKey());
145
146        // Check if we have monthly data.
147        $stats = $hubspotRecord['total___of_characters_typed_monthly_by_flymsg_by_user'] ?? [];
148        $monthsWithValues = 0;
149
150        if (isset($hubspotRecord['total___of_characters_typed_monthly_by_flymsg_by_user'])) {
151            $stats = array_map('trim', explode('.', $stats));
152            foreach ($stats as $key => $value) {
153                $stats1 = array_map('trim', explode(' - ', $value));
154                if (isset($stats1[0]) && $stats1[0] != 0 && !empty($stats1[0])) {
155                    $monthsWithValues = $key;
156                }
157            }
158            $monthsWithValues++;
159        }
160
161        $eligible_months = 0;
162        if ($monthsWithValues == 1) {
163            $eligible_months = 1;
164        }
165        if ($monthsWithValues > 1 && $monthsWithValues <= 3) {
166            $eligible_months = 3;
167        }
168        if ($monthsWithValues > 3 && $monthsWithValues <= 6) {
169            $eligible_months = 6;
170        }
171        if ($monthsWithValues > 6 && $monthsWithValues <= 9) {
172            $eligible_months = 9;
173        }
174        if ($monthsWithValues > 6) {
175            $eligible_months = 12;
176        }
177
178        $eligible_months = 36;
179
180        $fromOldRecord = !$user->charts()->exists();
181        $fromNewRecord = $user->charts()->exists();
182        $eligible_7_days = true;
183
184        if ($fromNewRecord && $user->created_at) {
185            $stats = array_map('trim', explode('-', $user->created_at));
186            if ($stats[0] == 2023 && $stats[1] == 01) {
187                $stats = array_map('trim', explode('T', $stats[2]));
188                if ($stats[0] >= 25) {
189                    $eligible_7_days = true;
190                }
191            }
192        }
193
194        // test $timeSaved = $fromOldRecord ? $this->statisticsService->getOldTimeSaved($from, $hubspotRecord) : $user->timeSaved($from);
195        // $charactersTyped = $fromOldRecord ? $this->statisticsService->getOldCharactersTyped($from, $hubspotRecord) : $user->charactersTyped($from);
196
197        $dailyUsage = FlyMsgUserDailyUsage::where('user_id', $user->getKey())
198            ->where('created_at', '>=', new \MongoDB\BSON\UTCDateTime(strtotime($fromDate->startOfDay()->toDateTimeString()) * 1000));
199        $charactersTyped = (clone $dailyUsage)->sum('characters_typed');
200        $timeSaved = (clone $dailyUsage)->sum('time_saved');
201        $costSaved = (clone $dailyUsage)->sum('cost_savings');
202        $flyGrammar = (clone $dailyUsage)->sum('fly_grammar_actions');
203        $flyGrammarActions = (clone $dailyUsage)->sum('fly_grammar_accepted');
204        $autoCorrectActions = (clone $dailyUsage)->sum('fly_grammar_autocorrect');
205        $autoCompleteActions = (clone $dailyUsage)->sum('fly_grammar_autocomplete');
206        $paragraphRewriteCount = (clone $dailyUsage)->sum('paragraph_rewrite_count');
207
208        // test $timeSaved = $this->statisticsService->getTimeSaved($user, $charactersTyped);
209        // $costSaved = $this->statisticsService->getCostSaved($user, $timeSaved, now());
210
211        $flycuts_used = $user->flycutsUsed($from);
212
213        if ($fromOldRecord) {
214            $chart_data = $this->statisticsService->getOldChart($from, $hubspotRecord);
215
216            if (!$eligible_7_days) {
217                $chartFlyCutsUsed = $chart_data['totalflycuts_used'] ?? 0;
218                $flycuts_used = $flycuts_used + $chartFlyCutsUsed;
219            }
220
221            unset($chart_data['totalflycuts_used']);
222        } else {
223            $chart_data = $user->getChartData($from);
224        }
225
226        $result = [
227            'shortcuts' => $shortcutCount,
228            'templates' => $templateAddedCount,
229            'total_templates_available' => $features['FlyPlates'],
230            'total_shortcuts_available' => $total_allowed_shortcuts,
231            'characters_typed' => $charactersTyped,
232            'flycuts_used' => $flycuts_used,
233            'time_saved' => $timeSaved,
234            'cost_saved' => $costSaved,
235            'chart_data' => $chart_data,
236            // From New Data
237            'chart_data_New' => $fromNewRecord ? $user->getChartData($from) : [],
238            'eligible_months' => $eligible_months,
239            'eligible_7_days' => $eligible_7_days,
240            'created_at' => $user->created_at,
241            'issues_fixed' => $flyGrammarActions,
242            'issues_autocorrect' => $autoCorrectActions,
243            'issues_autocomplete' => $autoCompleteActions,
244            'paragraph_rewrite_count' => $paragraphRewriteCount,
245            'grammar' => $flyGrammar
246        ];
247
248        return response()->json($result);
249    }
250
251    public function extension(Request $request): JsonResponse
252    {
253        $user = $request->user();
254        $userInfo = UserInfo::where('user_id', $user->id)->first();
255        $plan = $this->getCurrentPlan($user);
256        $today = FlyMsgUserDailyUsage::where('user_id', $user->id)
257            ->where('created_at', '>=', new \MongoDB\BSON\UTCDateTime(strtotime(now()->startOfDay()->toDateTimeString()) * 1000))
258            ->first();
259
260        $thisMonth = FlyMsgUserDailyUsage::where('user_id', $user->id)
261            ->where('created_at', '>=', new \MongoDB\BSON\UTCDateTime(strtotime(now()->startOfMonth()->toDateTimeString()) * 1000));
262
263        $thisYear = FlyMsgUserDailyUsage::where('user_id', $user->id)
264            ->where('created_at', '>=', new \MongoDB\BSON\UTCDateTime(strtotime(now()->startOfYear()->toDateTimeString()) * 1000));
265
266        $result = [
267            'all' => [
268                'flycuts' => $userInfo->total___of_times_flycut_used__count_ ?? 0,
269                'grammar' => $userInfo->total___of_times_flygrammar_is_used_count ?? 0,
270                'engage' => $userInfo->total___of_times_flyengage_used__count_ ?? 0,
271                'post' => $userInfo->total___of_times_flyposts_used__count_ ?? 0,
272                'time_saved' => round($userInfo->total_time_saved_by_flymsg_by_user ?? 0, 2),
273                'cost_saved' => round($userInfo->total_cost_savings_by_flymsg_by_user ?? 0, 2),
274                'characters_typed' => $userInfo->total___of_characters_typed_by_flymsg_by_user ?? 0,
275            ],
276            'today' => [
277                'flycuts' => $today->flycut_count ?? 0,
278                'grammar' => $today->fly_grammar_actions ?? 0,
279                'engage' => $today->flyengage_count ?? 0,
280                'post' => $today->flypost_count ?? 0,
281                'time_saved' => round($today->time_saved ?? 0, 2),
282                'cost_saved' => round($today->cost_savings ?? 0, 2),
283                'characters_typed' => $today->characters_typed ?? 0,
284            ],
285            'this_month' => [
286                'flycuts' => $thisMonth->sum('flycut_count') ?? 0,
287                'grammar' => $thisMonth->sum('fly_grammar_actions') ?? 0,
288                'engage' => $thisMonth->sum('flyengage_count') ?? 0,
289                'post' => $thisMonth->sum('flypost_count') ?? 0,
290                'time_saved' => round($thisMonth->sum('time_saved') ?? 0, 2),
291                'cost_saved' => round($thisMonth->sum('cost_savings') ?? 0, 2),
292                'characters_typed' => $thisMonth->sum('characters_typed') ?? 0,
293            ],
294            'this_year' => [
295                'flycuts' => $thisYear->sum('flycut_count') ?? 0,
296                'grammar' => $thisYear->sum('fly_grammar_actions') ?? 0,
297                'engage' => $thisYear->sum('flyengage_count') ?? 0,
298                'post' => $thisYear->sum('flypost_count') ?? 0,
299                'time_saved' => round($thisYear->sum('time_saved') ?? 0, 2),
300                'cost_saved' => round($thisYear->sum('cost_savings') ?? 0, 2),
301                'characters_typed' => $thisYear->sum('characters_typed') ?? 0,
302            ],
303            'quota' => [
304                'flycuts' => $plan->flycut_deployment ?? -1,
305                'grammar' => $plan->flygrammar_actions ?? -1,
306                'ai' => $plan->prompts_per_day ?? -1,
307            ]
308        ];
309
310        return response()->json($result);
311    }
312
313    public function restrictions()
314    {
315        $userRestrictions = [];
316        $users = DB::table('users')->get();
317
318        foreach ($users as $user) {
319            $user_id = (string) $user->_id;
320
321            $user = User::where(['_id' => $user_id])->first();
322            $current_subscription = $user->subscription('main');
323
324            if ($current_subscription) {
325                $plan = $current_subscription->plan;
326
327                // Available features for the user
328                $features = $plan->features;
329                $userRestrictions[$user_id]['is_valid'] = true;
330                $userRestrictions[$user_id]['email'] = $user->email;
331
332                $shortcutSql = DB::table('shortcuts')
333                    ->where('user_id', '=', $user_id);
334
335                $shortcuts = $shortcutSql->get();
336                if (! empty($shortcuts)) {
337                    foreach ($shortcuts as $shortcutHtmlArray) {
338                        $shortcutId = (string) $shortcutHtmlArray->_id;
339                        $userRestrictions[$user_id][$shortcutId]['is_valid'] = true;
340
341                        $shortcuttext = $shortcutHtmlArray->text;
342                        $shortcuttext = str_replace("\n", '', str_replace(PHP_EOL, '', $shortcuttext));
343
344                        /** Check for Bold Text */
345                        $bold = $features['Bold'] ?? false;
346                        $has_bold_text_in_html = $this->hasTag('/<strong>(.+?)<\/strong>/m', $shortcuttext);
347
348                        //$userRestrictions[$user_id][$shortcutId]["Bold"] = false;
349                        if (!$bold && ($has_bold_text_in_html)) {
350                            //$userRestrictions[$user_id][$shortcutId]["Bold"] = true;
351                            $userRestrictions[$user_id]['is_valid'] = false;
352                        }
353
354                        /** Check for Italic Text */
355                        $italic = $features['Italic'] ?? false;
356                        $has_italic_text_in_html = $this->hasTag('/<em>(.+?)<\/em>/m', $shortcuttext);
357
358                        //$userRestrictions[$user_id][$shortcutId]["Italic"] = false;
359                        if (!$italic && ($has_italic_text_in_html)) {
360                            //$userRestrictions[$user_id][$shortcutId]["Italic"] = true;
361                            $userRestrictions[$user_id]['is_valid'] = false;
362                        }
363
364                        $shortcutHtml = $shortcutHtmlArray->html;
365                        $shortcutHtml_styles = $this->extractStylesFromHtml($shortcutHtml);
366
367                        /** Check for underline */
368                        $under_line = $features['Underline'] ?? false;
369                        $under_line_exists = $this->checkIfStyleExists('text-decoration', 'underline', $shortcutHtml_styles);
370
371                        //$userRestrictions[$user_id][$shortcutId]["Underline"] = false;
372                        if ($under_line_exists && !$under_line) {
373                            //$userRestrictions[$user_id][$shortcutId]["Underline"] = true;
374                            $userRestrictions[$user_id]['is_valid'] = false;
375                        }
376
377                        /** Strikethrough */
378                        $strike_through = $features['Strikethrough'] ?? false;
379                        $strike_through_exists = $this->checkIfStyleExists('text-decoration', 'line-through', $shortcutHtml_styles);
380
381                        //$userRestrictions[$user_id][$shortcutId]["Strikethrough"] = false;
382                        if ($strike_through_exists && !$strike_through) {
383                            //$userRestrictions[$user_id][$shortcutId]["Strikethrough"] = true;
384                            $userRestrictions[$user_id]['is_valid'] = false;
385                        }
386
387                        /** Hyperlink */
388                        $hyperlink = $features['Hyperlink'] ?? false;
389                        $has_hyperlink_html = $this->hasTag('/<a(.+?)<\/a>/m', $shortcutHtml);
390
391                        //$userRestrictions[$user_id][$shortcutId]["Hyperlink"] = false;
392                        if ($has_hyperlink_html && !$hyperlink) {
393                            //$userRestrictions[$user_id][$shortcutId]["Hyperlink"] = true;
394                            $userRestrictions[$user_id]['is_valid'] = false;
395                        }
396
397                        /** Alignment - Left */
398                        $alignment_left = $features['Alignment - Left'] ?? false;
399                        $alignment_left_exists = $this->checkIfStyleExists('text-align', 'left', $shortcutHtml_styles);
400
401                        //$userRestrictions[$user_id][$shortcutId]["Alignment - Left"] = false;
402                        if ($alignment_left_exists && !$alignment_left) {
403                            //$userRestrictions[$user_id][$shortcutId]["Alignment - Left"] = true;
404                            $userRestrictions[$user_id]['is_valid'] = false;
405                        }
406
407                        /** Alignment - Centered */
408                        $alignment_center = $features['Alignment - Centered'] ?? false;
409                        $alignment_center_exists = $this->checkIfStyleExists('text-align', 'center', $shortcutHtml_styles);
410
411                        //$userRestrictions[$user_id][$shortcutId]["Alignment - Centered"] = false;
412                        if ($alignment_center_exists && !$alignment_center) {
413                            //$userRestrictions[$user_id][$shortcutId]["Alignment - Centered"] = true;
414                            $userRestrictions[$user_id]['is_valid'] = false;
415                        }
416
417                        /** Alignment - Right */
418                        $alignment_right = $features['Alignment - Right'] ?? false;
419                        $alignment_right_exists = $this->checkIfStyleExists('text-align', 'right', $shortcutHtml_styles);
420
421                        //$userRestrictions[$user_id][$shortcutId]["Alignment - Right"] = false;
422                        if ($alignment_right_exists && !$alignment_right) {
423                            //$userRestrictions[$user_id][$shortcutId]["Alignment - Right"] = true;
424                            $userRestrictions[$user_id]['is_valid'] = false;
425                        }
426
427                        /** Font Size */
428                        $font_size = $features['Font Size'] ?? false;
429                        $font_size_match = $this->checkIfStyleExists('font-size', $font_size . 'px', $shortcutHtml_styles);
430
431                        //$userRestrictions[$user_id][$shortcutId]["Font Size"] = false;
432                        if ($font_size != -1 && !$font_size_match && array_key_exists('font-size', $shortcutHtml_styles)) {
433                            //$userRestrictions[$user_id][$shortcutId]["Font Size"] = true;
434                            $userRestrictions[$user_id]['is_valid'] = false;
435                        }
436
437                        /** Font Family */
438                        $font = $features['Fonts'] ?? false;
439                        if ($font == 'Arial') {
440                            $font_family_match_1 = $this->checkIfStyleExists('font-family', 'arial, helvetica, sans-serif', $shortcutHtml_styles);
441                            $font_family_match_2 = $this->checkIfStyleExists('font-family', 'Arial', $shortcutHtml_styles);
442
443                            //$userRestrictions[$user_id][$shortcutId]['Fonts'] = false;
444                            if (!$font_family_match_1 && ! $font_family_match_2 && array_key_exists('font-family', $shortcutHtml_styles)) {
445                                //$userRestrictions[$user_id][$shortcutId]['Fonts'] = true;
446                                $userRestrictions[$user_id]['is_valid'] = false;
447                            }
448                        } else {
449                            if ($font != -1 && $font) {
450                                $count_unique_fonts = $this->countStyles('font-family', $shortcutHtml_styles);
451
452                                //$userRestrictions[$user_id][$shortcutId]['Fonts'] = false;
453                                if ($count_unique_fonts > $font) {
454                                    //$userRestrictions[$user_id][$shortcutId]['Fonts'] = true;
455                                    $userRestrictions[$user_id]['is_valid'] = false;
456                                }
457                            }
458                        }
459
460                        /** Bullet Points */
461                        $bullet_points = $features['Bullet Points'] ?? false;
462                        $has_bullet_points_html = $this->hasTag('/<ul(.+?)<\/ul>/m', $shortcutHtml);
463
464                        //$userRestrictions[$user_id][$shortcutId]['Bullet Points'] = false;
465                        if ($has_bullet_points_html && !$bullet_points) {
466                            //$userRestrictions[$user_id][$shortcutId]['Bullet Points'] = true;
467                            $userRestrictions[$user_id]['is_valid'] = false;
468                        }
469
470                        /** Numbered List */
471                        $numbered_list = $features['Numbered List'] ?? false;
472                        $has_numbered_list = $this->hasTag('/<ol(.+?)<\/ol>/m', $shortcutHtml);
473
474                        //$userRestrictions[$user_id][$shortcutId]['Numbered List'] = false;
475                        if ($has_numbered_list && !$numbered_list) {
476                            //$userRestrictions[$user_id][$shortcutId]['Numbered List'] = true;
477                            $userRestrictions[$user_id]['is_valid'] = false;
478                        }
479
480                        /** Increase Indent */
481                        $increase_indent = $features['Increase Indent'] ?? false;
482                        $has_increase_indent = array_key_exists('padding-left', $shortcutHtml_styles);
483
484                        //$userRestrictions[$user_id][$shortcutId]['Increase Indent'] = false;
485                        if ($has_increase_indent && !$increase_indent) {
486                            //$userRestrictions[$user_id][$shortcutId]['Increase Indent'] = true;
487                            $userRestrictions[$user_id]['is_valid'] = false;
488                        }
489
490                        /** Giphy checkIfGiphyExists */
491                        $allow_giphy = $features['Giphy'] ?? false;
492                        $doc = new DOMDocument();
493                        @$doc->loadHTML($shortcutHtml);
494                        $imageTags = $doc->getElementsByTagName('img');
495
496                        $gifs = collect($imageTags)->filter(function ($tag) {
497                            return (pathinfo(parse_url($tag->getAttribute('src'), PHP_URL_PATH), PATHINFO_EXTENSION) == 'gif')
498                                && ($this->getDomainName($tag->getAttribute('src')) == 'media2.giphy.com');
499                        });
500
501                        //$userRestrictions[$user_id][$shortcutId]['Giphy'] = false;
502                        if (!$allow_giphy && $gifs->isNotEmpty()) {
503                            //$userRestrictions[$user_id][$shortcutId]['Giphy'] = true;
504                            $userRestrictions[$user_id]['is_valid'] = false;
505                        }
506
507                        /** flycut charactor count checkCharacterCount */
508                        $flycut_char_limit = $features['Number of Characters that can be used per flycut'];
509                        $char_count = strlen($shortcutHtml);
510
511                        //$userRestrictions[$user_id][$shortcutId]['Number of Characters that can be used per flycut'] = false;
512                        if ($char_count > $flycut_char_limit && $flycut_char_limit > -1) {
513                            //$userRestrictions[$user_id][$shortcutId]['Number of Characters that can be used per flycut'] = true;
514                            $userRestrictions[$user_id]['is_valid'] = false;
515                        }
516                    }
517
518                    /** flycut counts checkFlyCutsCount */
519                    $number_of_flyCuts_that_can_be_created = $features['Number of FlyCuts that can be created'];
520                    $current_flycuts_created = $shortcutSql->count();
521
522                    //$userRestrictions[$user_id]["Number of FlyCuts that can be created"] = false;
523                    if ($current_flycuts_created >= $number_of_flyCuts_that_can_be_created && $number_of_flyCuts_that_can_be_created > -1) {
524                        //$userRestrictions[$user_id]["Number of FlyCuts that can be created"] = true;
525                        $userRestrictions[$user_id]['is_valid'] = false;
526                    }
527
528                    /** flycut counts checkFlyCutsCount */
529                    $number_of_flyCuts_that_can_be_created = $features['Number of FlyCuts that can be created'];
530                    $current_flycuts_created = $shortcutSql->count();
531
532                    //$userRestrictions[$user_id]["Number of FlyCuts that can be created"] = false;
533                    if ($current_flycuts_created >= $number_of_flyCuts_that_can_be_created && $number_of_flyCuts_that_can_be_created > -1) {
534                        //$userRestrictions[$user_id]["Number of FlyCuts that can be created"] = true;
535                        $userRestrictions[$user_id]['is_valid'] = false;
536                    }
537
538                    /** categories counts checkCategoriesCount */
539                    $categories_limit = $features['Categories'] ?? 0;
540
541                    $categorySql = DB::table('shortcut_categories')
542                        ->where('user_id', '=', $user_id);
543                    $categories_count = $categorySql->count();
544
545                    //$userRestrictions[$user_id]["Categories"] = false;
546                    if ($categories_count >= $categories_limit && $categories_limit != -1) {
547                        //$userRestrictions[$user_id]["Categories"] = true;
548                        $userRestrictions[$user_id]['is_valid'] = false;
549                    }
550
551                    /** sub categories counts checkSubCategoriesCount */
552                    $sub_categories_limit = $features['Subcategory'] ?? 0;
553                    $subcategorySql = DB::table('shortcut_sub_categories_lv1')
554                        ->where('user_id', '=', $user_id);
555                    $sub_categories_count = $subcategorySql->count();
556
557                    //$userRestrictions[$user_id]["Subcategory"] = false;
558                    if ($sub_categories_count > $sub_categories_limit && $sub_categories_limit != -1) {
559                        //$userRestrictions[$user_id]["Subcategory"] = true;
560                        $userRestrictions[$user_id]['is_valid'] = false;
561                    }
562                }
563            }
564        }
565
566        return response()->json($userRestrictions);
567    }
568}