Completed
Push — master ( 194cbe...2ee496 )
by Yaro
05:39 queued 19s
created

PreferencesRepository::setSortableOrderState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Yaro\Jarboe\Table\Repositories;
4
5
class PreferencesRepository
6
{
7
    const PREFIX = 'jarboe';
8
9 1
    public function saveSearchFilterParams($tableIdentifier, $params)
10
    {
11 1
        $key = sprintf('%s.%s.search', self::PREFIX, $tableIdentifier);
12
13 1
        session()->put($key, $params);
14 1
    }
15
16 1
    public function getOrderFilterParam($tableIdentifier, $column)
17
    {
18 1
        $key = sprintf('%s.%s.order.%s', self::PREFIX, $tableIdentifier, $column);
19
20 1
        return session($key);
21
    }
22
23 1
    public function saveOrderFilterParam($tableIdentifier, $column, $direction)
24
    {
25 1
        $key = sprintf('%s.%s.order', self::PREFIX, $tableIdentifier);
26
27 1
        session()->put($key, [
28 1
            $column => $direction,
29
        ]);
30 1
    }
31
32 1
    public function getPerPageParam($tableIdentifier)
33
    {
34 1
        $key = sprintf('%s.%s.per_page', self::PREFIX, $tableIdentifier);
35
36 1
        return session($key);
37
    }
38
39 1
    public function setPerPageParam($tableIdentifier, $perPage)
40
    {
41 1
        $key = sprintf('%s.%s.per_page', self::PREFIX, $tableIdentifier);
42
43 1
        session()->put($key, $perPage);
44 1
    }
45
46
    public function getCurrentLocale($tableIdentifier)
47
    {
48
        $key = sprintf('%s.%s.locale',self::PREFIX, $tableIdentifier);
49
50
        return session($key);
51
    }
52
53
    public function saveCurrentLocale($tableIdentifier, $locale)
54
    {
55
        $key = sprintf('%s.%s.locale', self::PREFIX, $tableIdentifier);
56
57
        session()->put($key, $locale);
58
    }
59
60 1
    public function isSortableByWeightActive($tableIdentifier)
61
    {
62 1
        $key = sprintf('%s.%s.reorder', self::PREFIX, $tableIdentifier);
63
64 1
        return session($key, false);
65
    }
66
67
    public function setSortableOrderState($tableIdentifier, bool $active)
68
    {
69
        $key = sprintf('%s.%s.reorder', self::PREFIX, $tableIdentifier);
70
71
        session()->put($key, $active);
72
    }
73
74
    public function resetAll()
75
    {
76
        session()->forget(self::PREFIX);
77
    }
78
}
79