1: <?php
2: /**
3: * PHP version 5
4: * @package generalDriver
5: * @author Christian Schiffler <c.schiffler@cyberspectrum.de>
6: * @author Stefan Heimes <stefan_heimes@hotmail.com>
7: * @author Tristan Lins <tristan.lins@bit3.de>
8: * @copyright The MetaModels team.
9: * @license LGPL.
10: * @filesource
11: */
12:
13: namespace DcGeneral\DataDefinition\Definition\View\Panel;
14:
15: /**
16: * Class DefaultSortElementInformation.
17: *
18: * Default implementation of a sort definition on properties.
19: *
20: * @package DcGeneral\DataDefinition\Definition\View\Panel
21: */
22: class DefaultSortElementInformation implements SortElementInformationInterface
23: {
24: /**
25: * The names of the properties to be sortable.
26: *
27: * @var array
28: */
29: protected $properties = array();
30:
31: /**
32: * The sorting flag to use by default.
33: *
34: * @var string
35: */
36: protected $defaultFlag = SortElementInformationInterface::SORTING_FLAG_NONE;
37:
38: /**
39: * {@inheritDoc}
40: */
41: public function getName()
42: {
43: return 'sort';
44: }
45:
46: /**
47: * {@inheritDoc}
48: */
49: public function setDefaultFlag($flag)
50: {
51: $this->defaultFlag = $flag;
52:
53: return $this;
54: }
55:
56: /**
57: * {@inheritDoc}
58: */
59: public function getDefaultFlag()
60: {
61: return $this->defaultFlag;
62: }
63:
64: /**
65: * {@inheritDoc}
66: */
67: public function addProperty($propertyName, $flag = 0)
68: {
69: $this->properties[$propertyName] = $flag;
70:
71: return $this;
72: }
73:
74: /**
75: * {@inheritDoc}
76: */
77: public function hasProperty($propertyName)
78: {
79: return isset($this->properties[$propertyName]);
80: }
81:
82: /**
83: * {@inheritDoc}
84: */
85: public function removeProperty($propertyName)
86: {
87: unset($this->properties[$propertyName]);
88:
89: return $this;
90: }
91:
92: /**
93: * {@inheritDoc}
94: */
95: public function getPropertyNames()
96: {
97: return array_keys($this->properties);
98: }
99:
100: /**
101: * {@inheritDoc}
102: */
103: public function getPropertyFlag($propertyName)
104: {
105: $flag = $this->getDefaultFlag();
106:
107: if ($this->hasProperty($propertyName) && $this->properties[$propertyName])
108: {
109: $flag = $this->properties[$propertyName];
110: }
111:
112: return $flag;
113: }
114: }
115: