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

PreferencesRepository   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 61.11%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 74
rs 10
c 0
b 0
f 0
ccs 22
cts 36
cp 0.6111

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentLocale() 0 6 1
A saveCurrentLocale() 0 6 1
A setSortableOrderState() 0 6 1
A resetAll() 0 4 1
A saveSearchFilterParams() 0 6 1
A getOrderFilterParam() 0 6 1
A saveOrderFilterParam() 0 8 1
A getPerPageParam() 0 6 1
A setPerPageParam() 0 6 1
A isSortableByWeightActive() 0 6 1
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