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