Issues (3936)

Classes/Session/SearchSessionData.php (1 issue)

1
<?php
2
namespace EWW\Dpf\Session;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
18
19
class SearchSessionData
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $excludeFilters = [];
25
26
    /**
27
     * @var array
28
     */
29
    protected $filters = [];
30
31
    /**
32
     * @var string
33
     */
34
    protected $sortField = '';
35
36
    /**
37
     * @var string
38
     */
39
    protected $sortOrder = '';
40
41
    /**
42
     * @var string
43
     */
44
    protected $simpleQuery = null;
45
46
    /**
47
     * @var int
48
     */
49
    protected $itemsPerPage;
50
51
52
    /**
53
     * Returns the exclude filters.
54
     *
55
     * @return array
56
     */
57
    public function getExcludeFilters()
58
    {
59
        return $this->excludeFilters;
60
    }
61
62
63
    /**
64
     * Toggles the discarded documents filter.
65
     *
66
     */
67
    public function toggleExcludeDiscardedFilter()
68
    {
69
        if (array_key_exists('aliasState', $this->excludeFilters)) {
70
            unset($this->excludeFilters['aliasState']);
71
        } else {
72
            $this->excludeFilters['aliasState'] = [DocumentWorkflow::ALIAS_STATE_DISCARDED];
73
        }
74
    }
75
76
77
    /**
78
     * Toggles the hide bookmarks filter.
79
     *
80
     */
81
    public function toggleBookmarksOnlyFilter()
82
    {
83
        if (array_key_exists('bookmarks', $this->excludeFilters)) {
84
            unset($this->excludeFilters['bookmarks']);
85
        } else {
86
            $this->excludeFilters['bookmarks'] = true;
87
        }
88
    }
89
90
    /**
91
     * Sets a filter
92
     *
93
     * @param $name
94
     * @param array $values
95
     */
96
    public function setFilter($name, $values = [])
97
    {
98
        if ($name && $values && is_array($values)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $values of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
99
            $this->filters[$name] = $values;
100
        } elseif ($name) {
101
            unset($this->filters[$name]);
102
        }
103
    }
104
105
106
    /**
107
     * Removes all filters
108
     *
109
     * @return array
110
     */
111
    public function clearFilters()
112
    {
113
        $this->filters = [];
114
    }
115
116
117
    /**
118
     * Gets the filters
119
     *
120
     * @return array
121
     */
122
    public function getFilters()
123
    {
124
        return $this->filters;
125
    }
126
127
128
    /**
129
     * Removes the sort information
130
     *
131
     */
132
    public function clearSort()
133
    {
134
        $this->sortField = '';
135
        $this->sortOrder = '';
136
    }
137
138
    /**
139
     * Gets the sort field
140
     *
141
     * @return string
142
     */
143
    public function getSortField()
144
    {
145
        return $this->sortField;
146
    }
147
148
    /**
149
     * Sets the sort field
150
     *
151
     * @param string $fieldName
152
     */
153
    public function setSortField($fieldName)
154
    {
155
        $this->sortField = $fieldName;
156
    }
157
158
    /**
159
     * Gets the sort order
160
     *
161
     * @return string
162
     */
163
    public function getSortOrder()
164
    {
165
        return $this->sortOrder;
166
    }
167
168
    /**
169
     * Sets the sort order
170
     *
171
     * @param string $order
172
     */
173
    public function setSortOrder($order)
174
    {
175
        $this->sortOrder = $order;
176
    }
177
178
    /**
179
     * Gets the simple query string
180
     *
181
     * @return string
182
     */
183
    public function getSimpleQuery()
184
    {
185
        return $this->simpleQuery;
186
    }
187
188
    /**
189
     * Sets the simple query string
190
     *
191
     * @param string $query
192
     */
193
    public function setSimpleQuery($query)
194
    {
195
        $this->simpleQuery = $query;
196
    }
197
198
    /**
199
     * Gets the items per page for the list.
200
     *
201
     * @return int
202
     */
203
    public function getItemsPerPage()
204
    {
205
        return $this->itemsPerPage;
206
    }
207
208
    /**
209
     * Sets the items per page for the list.
210
     *
211
     * @param int $itemsPerPage
212
     */
213
    public function setItemsPerPage($itemsPerPage)
214
    {
215
        $this->itemsPerPage = $itemsPerPage;
216
    }
217
218
219
}