1: <?php
2:
3: /**
4: * This file is part of the Nextras community extensions of Nette Framework
5: *
6: * @license MIT
7: * @link https://github.com/nextras
8: * @author Jan Skrasek
9: */
10:
11: namespace Nextras\Datagrid;
12:
13: use Nette;
14:
15:
16:
17: class Column extends Nette\Object
18: {
19:
20: /** @var string */
21: public $name;
22:
23: /** @var string */
24: public $label;
25:
26: /** @var string */
27: protected $sort = FALSE;
28:
29: /** @var Datagrid */
30: protected $grid;
31:
32:
33:
34: public function __construct($name, $label, Datagrid $grid)
35: {
36: $this->name = $name;
37: $this->label = $label;
38: $this->grid = $grid;
39: }
40:
41:
42:
43: public function enableSort()
44: {
45: $this->sort = TRUE;
46: return $this;
47: }
48:
49:
50:
51: public function canSort()
52: {
53: return $this->sort;
54: }
55:
56:
57:
58: public function getNewState()
59: {
60: if ($this->isAsc()) {
61: return Datagrid::ORDER_DESC;
62: } elseif ($this->isDesc()) {
63: return NULL;
64: } else {
65: return Datagrid::ORDER_ASC;
66: }
67: }
68:
69:
70:
71: public function isAsc()
72: {
73: return $this->grid->orderColumn === $this->name && $this->grid->orderType === Datagrid::ORDER_ASC;
74: }
75:
76:
77:
78: public function isDesc()
79: {
80: return $this->grid->orderColumn === $this->name && $this->grid->orderType === Datagrid::ORDER_DESC;
81: }
82:
83: }
84: