Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShortcutCategoryPositionService
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 getCategoryPosition
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 updateCategorySequence
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 updateCategoryPosition
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 removeCategoryPosition
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Services;
4
5use App\Http\Models\ShortcutCategory;
6use App\Http\Models\ShortcutCategoryPosition;
7
8class ShortcutCategoryPositionService
9{
10    public function getCategoryPosition($userId)
11    {
12        $searchArray = ['user_id' => $userId];
13
14        return ShortcutCategoryPosition::where($searchArray)->first();
15    }
16
17    public function updateCategorySequence($positions)
18    {
19        if (! empty($positions)) {
20            foreach ($positions as $key => $position) {
21                $data = ['seq_id' => $key + 1];
22                $searchArray = ['_id' => $position];
23                ShortcutCategory::where($searchArray)->update($data);
24            }
25
26            return true;
27        }
28
29        return false;
30    }
31
32    public function updateCategoryPosition($userId, $documentId)
33    {
34        $searchArray = ['user_id' => $userId];
35        $updateArray = ['positions' => $documentId];
36        ShortcutCategoryPosition::where($searchArray)->push($updateArray);
37        $positions = $this->getCategoryPosition($userId);
38        $this->updateCategorySequence($positions['positions'] ?? 0);
39    }
40
41    public function removeCategoryPosition($userId, $documentId)
42    {
43        $searchArray = ['user_id' => $userId];
44        $updateArray = ['positions' => $documentId];
45        ShortcutCategoryPosition::where($searchArray)->pull($updateArray);
46        $positions = $this->getCategoryPosition($userId);
47        $this->updateCategorySequence($positions['positions'] ?? 0);
48    }
49}