This repository has been archived by the owner on Aug 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Column.php
150 lines (121 loc) · 3.73 KB
/
Column.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
declare(strict_types=1);
/*
* This file is part of the Zikula package.
*
* Copyright Zikula - https://ziku.la/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zikula\Component\SortableColumns;
/**
* Class Column
*
* A column defines a column of a data table that is used in conjunction with SortableColumns to
* assist in the display of column headers and links to facilitate resorting based on column and direction.
*/
class Column
{
public const DIRECTION_ASCENDING = 'ASC';
public const DIRECTION_DESCENDING = 'DESC';
public const CSS_CLASS_UNSORTED = 'unsorted';
public const CSS_CLASS_ASCENDING = 'sorted-asc';
public const CSS_CLASS_DESCENDING = 'sorted-desc';
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $defaultSortDirection;
/**
* @var string
*/
private $currentSortDirection;
/**
* @var string
*/
private $reverseSortDirection;
/**
* @var string
*/
private $cssClassString;
/**
* @var bool
*/
private $isSortColumn = false;
public function __construct(string $name, string $currentSortDirection = null, string $defaultSortDirection = null)
{
$this->name = $name;
$this->currentSortDirection = !empty($currentSortDirection) ? $currentSortDirection : self::DIRECTION_ASCENDING;
$this->reverseSortDirection = $this->reverse($this->currentSortDirection);
$this->defaultSortDirection = !empty($defaultSortDirection) ? $defaultSortDirection : self::DIRECTION_ASCENDING;
$this->cssClassString = self::CSS_CLASS_UNSORTED;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getDefaultSortDirection(): string
{
return $this->defaultSortDirection;
}
public function setDefaultSortDirection(string $defaultSortDirection): void
{
$this->defaultSortDirection = $defaultSortDirection;
}
public function getCurrentSortDirection(): string
{
return $this->currentSortDirection;
}
public function setCurrentSortDirection(string $currentSortDirection): void
{
$this->currentSortDirection = $currentSortDirection;
$this->setCssClassString($this->cssFromDirection($currentSortDirection));
$this->reverseSortDirection = $this->reverse($currentSortDirection);
}
public function getReverseSortDirection(): string
{
return $this->reverseSortDirection;
}
public function setReverseSortDirection(string $reverseSortDirection): void
{
$this->reverseSortDirection = $reverseSortDirection;
}
public function getCssClassString(): string
{
return $this->cssClassString;
}
public function setCssClassString(string $cssClassString): void
{
$this->cssClassString = $cssClassString;
}
public function isSortColumn(): bool
{
return $this->isSortColumn;
}
public function setSortColumn(bool $isSortColumn): void
{
$this->isSortColumn = $isSortColumn;
}
/**
* Reverse the direction constants.
*/
private function reverse(string $direction): string
{
return (self::DIRECTION_ASCENDING === $direction) ? self::DIRECTION_DESCENDING : self::DIRECTION_ASCENDING;
}
/**
* Determine a css class based on the direction.
*/
private function cssFromDirection(string $direction): string
{
return (self::DIRECTION_ASCENDING === $direction) ? self::CSS_CLASS_ASCENDING : self::CSS_CLASS_DESCENDING;
}
}