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\Palette;
14:
15: use DcGeneral\Data\ModelInterface;
16: use DcGeneral\Data\PropertyValueBag;
17: use DcGeneral\DataDefinition\Palette\Condition\Property\PropertyConditionInterface;
18:
19: /**
20: * A property contained within a palette.
21: *
22: * @package DcGeneral\DataDefinition\Palette
23: */
24: class Property implements PropertyInterface
25: {
26: /**
27: * The name of the property.
28: *
29: * @var string
30: */
31: protected $name;
32:
33: /**
34: * The condition to be examined to determine if this property is visible.
35: *
36: * @var PropertyConditionInterface
37: */
38: protected $visibleCondition;
39:
40: /**
41: * The condition to be examined to determine if this property is editable.
42: *
43: * @var PropertyConditionInterface
44: */
45: protected $editableCondition;
46:
47: /**
48: * Create a new instance.
49: *
50: * @param string $name The name of the property.
51: */
52: public function __construct($name)
53: {
54: $this->setName($name);
55: }
56:
57: /**
58: * {@inheritdoc}
59: */
60: public function setName($name)
61: {
62: $this->name = (string)$name;
63: }
64:
65: /**
66: * {@inheritdoc}
67: */
68: public function getName()
69: {
70: return $this->name;
71: }
72:
73: /**
74: * {@inheritdoc}
75: */
76: public function isVisible(ModelInterface $model = null, PropertyValueBag $input = null)
77: {
78: if ($this->visibleCondition)
79: {
80: return $this->visibleCondition->match($model, $input);
81: }
82:
83: return true;
84: }
85:
86: /**
87: * {@inheritdoc}
88: */
89: public function isEditable(ModelInterface $model = null, PropertyValueBag $input = null)
90: {
91: if ($this->editableCondition)
92: {
93: return $this->editableCondition->match($model, $input);
94: }
95:
96: return true;
97: }
98:
99: /**
100: * {@inheritdoc}
101: */
102: public function setVisibleCondition(PropertyConditionInterface $condition = null)
103: {
104: $this->visibleCondition = $condition;
105:
106: return $this;
107: }
108:
109: /**
110: * {@inheritdoc}
111: */
112: public function getVisibleCondition()
113: {
114: return $this->visibleCondition;
115: }
116:
117: /**
118: * {@inheritdoc}
119: */
120: public function setEditableCondition(PropertyConditionInterface $condition = null)
121: {
122: $this->editableCondition = $condition;
123:
124: return $this;
125: }
126:
127: /**
128: * {@inheritdoc}
129: */
130: public function getEditableCondition()
131: {
132: return $this->editableCondition;
133: }
134:
135: /**
136: * {@inheritdoc}
137: */
138: public function __clone()
139: {
140: if ($this->visibleCondition !== null)
141: {
142: $this->visibleCondition = clone $this->visibleCondition;
143: }
144: if ($this->editableCondition !== null)
145: {
146: $this->editableCondition = clone $this->editableCondition;
147: }
148: }
149: }
150: