3 namespace wcf\system\condition
;
5 use wcf\data\condition\Condition
;
6 use wcf\data\DatabaseObject
;
7 use wcf\data\DatabaseObjectList
;
8 use wcf\system\exception\InvalidObjectArgument
;
11 * Abstract condition implementation for check a text-typed property of a database
14 * @author Matthias Schmidt
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\Condition
20 abstract class AbstractObjectTextPropertyCondition
extends AbstractTextCondition
implements
25 * name of the relevant database object class
28 protected $className = '';
31 * is true if the entered value should be split by commas to search for
35 protected $supportsMultipleValues = false;
38 * name of the relevant object property
41 protected $propertyName = '';
46 public function addObjectListCondition(DatabaseObjectList
$objectList, array $conditionData)
48 $className = $this->getListClassName();
49 if (!($objectList instanceof $className)) {
50 throw new InvalidObjectArgument($objectList, $className, 'Object list');
53 if ($this->supportsMultipleValues
) {
54 $objectList->getConditionBuilder()->add(
55 $objectList->getDatabaseTableAlias() . '.' . $this->getPropertyName() . ' IN (?)',
56 [$conditionData[$this->fieldName
]]
59 $objectList->getConditionBuilder()->add(
60 $objectList->getDatabaseTableAlias() . '.' . $this->getPropertyName() . ' = ?',
61 [$conditionData[$this->fieldName
]]
69 public function checkObject(DatabaseObject
$object, array $conditionData)
71 $className = $this->getClassName();
72 if (!($object instanceof $className)) {
73 throw new InvalidObjectArgument($object, $className);
76 return \
in_array($object->{$this->getPropertyName()}, $conditionData[$this->fieldName
]);
80 * Returns the name of the relevant database object class.
84 protected function getClassName()
86 return $this->className
;
92 public function getData()
94 $value = parent
::getData();
95 if ($value === null ||
!$this->supportsMultipleValues
) {
100 $this->fieldName
=> \
preg_split('/\s*,\s*/', $value[$this->fieldName
], -1, \PREG_SPLIT_NO_EMPTY
),
105 * Returns the name of the relevant database object list class.
109 protected function getListClassName()
111 return $this->className
. 'List';
115 * Returns the name of the relevant object property.
119 protected function getPropertyName()
121 return $this->propertyName
;
127 public function setData(Condition
$condition)
129 parent
::setData($condition);
131 if ($this->supportsMultipleValues
) {
132 /** @noinspection PhpParamsInspection */
133 $this->fieldValue
= \
implode(',', $this->fieldValue
);