Skip to content

Commit 445054f

Browse files
committed
Move some functions to the parent class
1 parent 7c2ab95 commit 445054f

File tree

2 files changed

+92
-92
lines changed

2 files changed

+92
-92
lines changed

src/PhpTableGenerator/HeadCell.php

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ class HeadCell extends Cell
5353
*/
5454
private $selectAllSelector;
5555

56-
/**
57-
* @var
58-
*/
59-
private $sortByKey;
60-
61-
/**
62-
* @var
63-
*/
64-
private $sortBy;
65-
66-
/**
67-
* @var
68-
*/
69-
private $sortDirKey;
70-
71-
/**
72-
* @var
73-
*/
74-
private $sortDir;
75-
7656
public function __construct($title = null, $alias = null, $content = null, $htmlspecialchars = false)
7757
{
7858
if ($title !== null) {
@@ -190,83 +170,19 @@ public function setSelectable($selectable, $selectAllSelector = '')
190170
$this->selectAllSelector = $selectAllSelector;
191171
}
192172

193-
/**
194-
* @return string
195-
*/
196-
public function getSortByKey()
197-
{
198-
return $this->sortByKey;
199-
}
200-
201-
/**
202-
* @param string $sortByKey
203-
*/
204-
public function setSortByKey($sortByKey)
205-
{
206-
$this->sortByKey = $sortByKey;
207-
}
208-
209-
/**
210-
* @return string
211-
*/
212-
public function getSortDir()
213-
{
214-
return $this->sortDir;
215-
}
216-
217-
/**
218-
* @param $sortDir
219-
*/
220-
public function setSortDir($sortDir)
221-
{
222-
$this->sortDir = (strtolower($sortDir) === 'asc') ? 'asc' : 'desc';
223-
}
224-
225-
/**
226-
* @return string
227-
*/
228-
public function getSortBy()
229-
{
230-
return $this->sortBy;
231-
}
232-
233-
/**
234-
* @param string $sortBy
235-
*/
236-
public function setSortBy($sortBy)
237-
{
238-
$this->sortBy = $sortBy;
239-
}
240-
241173
/**
242174
* According the current sorting direction, alias, and etc return
243175
* the next sorting direction
244176
*
245177
* @return string
246178
*/
247-
public function getNewSortDir()
179+
public function getSortDir()
248180
{
249181
$alias = $this->getAlias();
250-
//$sortBy = $this->getSortBy();
251-
$sortDir = $this->getSortDir();
252-
253-
return ($alias === $sortBy && $sortDir === 'asc') ? 'desc' : 'asc';
254-
}
255-
256-
/**
257-
* @return string
258-
*/
259-
public function getSortDirKey()
260-
{
261-
return $this->sortDirKey;
262-
}
182+
$listSortBy = $this->getListSortBy();
183+
$listSortDir = $this->getListSortDir();
263184

264-
/**
265-
* @param string $sortDirKey
266-
*/
267-
public function setSortDirKey($sortDirKey)
268-
{
269-
$this->sortDirKey = $sortDirKey;
185+
return ($alias === $listSortBy && $listSortDir === 'asc') ? 'desc' : 'asc';
270186
}
271187

272188
/**
@@ -294,13 +210,13 @@ public function getContent()
294210
}
295211

296212
$alias = $this->getAlias();
297-
$sortByKey = $this->getSortByKey();
213+
$listSortByKey = $this->getListSortByKey();
298214

299-
$newSortDir = $this->getNewSortDir();
215+
$sortDir = $this->getSortDir();
300216

301217
$sortFunction = $config->getConfig('sorterJSFunction');
302-
$sortDirKey = $this->getSortDirKey();
218+
$listSortDirKey = $this->getListSortDirKey();
303219

304-
return "{$checkboxHtml} <a style='cursor: pointer;' onclick='{$sortFunction}(\"{$sortByKey}\", \"{$alias}\", \"{$sortDirKey}\", \"{$newSortDir}\");'>{$title}</a>";
220+
return "{$checkboxHtml} <a style='cursor: pointer;' onclick='{$sortFunction}(\"{$listSortByKey}\", \"{$alias}\", \"{$listSortDirKey}\", \"{$sortDir}\");'>{$title}</a>";
305221
}
306222
}

src/PhpTableGenerator/TableGenerator.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ abstract class TableGenerator
4343
*/
4444
private $data;
4545

46+
/**
47+
* @var
48+
*/
49+
private $listSortByKey;
50+
51+
/**
52+
* @var
53+
*/
54+
private $listSortBy;
55+
56+
/**
57+
* @var
58+
*/
59+
private $listSortDirKey;
60+
61+
/**
62+
* @var
63+
*/
64+
private $listSortDir;
65+
4666
/**
4767
* initialize a TableGenerator object
4868
*
@@ -130,4 +150,68 @@ public function getAllAttributesHtml()
130150
* @return string
131151
*/
132152
abstract public function getHtml();
153+
154+
/**
155+
* @return string
156+
*/
157+
public function getListSortByKey()
158+
{
159+
return $this->listSortByKey;
160+
}
161+
162+
/**
163+
* @param string $listSortByKey
164+
*/
165+
public function setListSortByKey($listSortByKey)
166+
{
167+
$this->listSortByKey = $listSortByKey;
168+
}
169+
170+
/**
171+
* @return string
172+
*/
173+
public function getListSortBy()
174+
{
175+
return $this->listSortBy;
176+
}
177+
178+
/**
179+
* @param string $listSortBy
180+
*/
181+
public function setListSortBy($listSortBy)
182+
{
183+
$this->listSortBy = $listSortBy;
184+
}
185+
186+
/**
187+
* @return string
188+
*/
189+
public function getListSortDirKey()
190+
{
191+
return $this->listSortDirKey;
192+
}
193+
194+
/**
195+
* @param string $listSortDirKey
196+
*/
197+
public function setSortDirKey($listSortDirKey)
198+
{
199+
$this->listSortDirKey = $listSortDirKey;
200+
}
201+
202+
/**
203+
* @return string
204+
*/
205+
public function getListSortDir()
206+
{
207+
return $this->listSortDir;
208+
}
209+
210+
/**
211+
* @param $listSortDir
212+
*/
213+
public function setListSortDir($listSortDir)
214+
{
215+
$this->listSortDir = (strtolower($listSortDir) === 'asc') ? 'asc' : 'desc';
216+
}
133217
}

0 commit comments

Comments
 (0)