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\Condition\Palette;
14:
15: use DcGeneral\Data\ModelInterface;
16: use DcGeneral\Data\PropertyValueBag;
17:
18: /**
19: * Condition checking that the value of a property is false.
20: */
21: class PropertyFalseCondition extends AbstractWeightAwarePaletteCondition
22: {
23: /**
24: * The property name.
25: *
26: * @var string
27: */
28: protected $propertyName;
29:
30: /**
31: * Use strict compare mode.
32: *
33: * @var bool
34: */
35: protected $strict;
36:
37: /**
38: * Create a new instance.
39: *
40: * @param string $propertyName The name of the property.
41: *
42: * @param bool $strict Flag if the comparison shall be strict (type safe).
43: *
44: * @param int $weight The weight of this condition to apply.
45: */
46: public function __construct($propertyName = '', $strict = false, $weight = 1)
47: {
48: $this->propertyName = (string)$propertyName;
49: $this->strict = (bool)$strict;
50: $this->setWeight($weight);
51: }
52:
53: /**
54: * Set the property name.
55: *
56: * @param string $propertyName The property name.
57: *
58: * @return PropertyFalseCondition
59: */
60: public function setPropertyName($propertyName)
61: {
62: $this->propertyName = (string)$propertyName;
63:
64: return $this;
65: }
66:
67: /**
68: * Retrieve the property name.
69: *
70: * @return string
71: */
72: public function getPropertyName()
73: {
74: return $this->propertyName;
75: }
76:
77: /**
78: * Set the flag if the comparison shall be strict (type safe).
79: *
80: * @param boolean $strict The flag.
81: *
82: * @return PropertyFalseCondition
83: */
84: public function setStrict($strict)
85: {
86: $this->strict = (bool)$strict;
87: return $this;
88: }
89:
90: /**
91: * Retrieve the flag if the comparison shall be strict (type safe).
92: *
93: * @return boolean
94: */
95: public function getStrict()
96: {
97: return $this->strict;
98: }
99:
100: /**
101: * {@inheritdoc}
102: */
103: public function getMatchCount(ModelInterface $model = null, PropertyValueBag $input = null)
104: {
105: if (!$this->propertyName)
106: {
107: return false;
108: }
109:
110: if ($input && $input->hasPropertyValue($this->propertyName))
111: {
112: $value = $input->getPropertyValue($this->propertyName);
113: }
114: elseif ($model)
115: {
116: $value = $model->getProperty($this->propertyName);
117: }
118: else
119: {
120: return false;
121: }
122:
123: return ($this->strict ? ($value === false) : !$value) ? $this->getWeight() : false;
124: }
125:
126: /**
127: * {@inheritdoc}
128: */
129: public function __clone()
130: {
131: }
132: }
133: