14 abstract public function getDocumentType();
16 public function getOrmFilter(
ConditionGroup $conditionGroup, ?array $targetDocumentType =
null): array
18 $filter = [
'LOGIC' =>
'OR'];
20 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
21 if (is_null($targetDocumentType))
23 $targetDocumentType = $this->getDocumentType();
26 $fieldsMap = $documentService->getDocumentFields($targetDocumentType);
31 foreach ($conditionGroup->
getItems() as [$condition, $joiner])
33 $fieldId = $condition->getField();
34 if (!isset($fieldsMap[$fieldId]))
41 $betweenFilterResult = $this->getBetweenFilter($fieldsMap[$fieldId] ?? [], $condition);
42 if (!$betweenFilterResult->isSuccess())
47 $filter[$i][] = $betweenFilterResult->getData()[
'filter1'];
48 $filter[$i][] = $betweenFilterResult->getData()[
'filter2'];
52 $value = $condition->getValue();
56 $extractionResult = $this->
extractValue($fieldsMap[$fieldId], (
string)$condition->getValue());
57 if ($extractionResult->isSuccess())
59 $value = $extractionResult->getData()[
'extractedValue'];
69 $value = \CBPHelper::extractUsers($value, $targetDocumentType);
71 elseif ($fieldsMap[$fieldId][
'Type'] ===
FieldType::BOOL && isset($value))
73 $value = \CBPHelper::getBool($value);
76 switch ($condition->getOperator())
110 $operator = $condition->getOperator();
123 $filter[$i][] = $this->createRowFilter($operator, $condition->getField(), $value);
134 private function getBetweenFilter(array $property,
Condition $condition):
Result
137 $value_greater_then = (is_array($value) && isset($value[0]) ? $value[0] : $value);
138 $value_less_then = (is_array($value) && isset($value[1]) ? $value[1] :
'');
140 $extractionResult1 = $this->
extractValue($property, (
string)$value_greater_then);
141 if (!$extractionResult1->isSuccess())
146 $extractionResult2 = $this->
extractValue($property, (
string)$value_less_then);
147 if (!$extractionResult2->isSuccess())
152 $filter1 = $this->createRowFilter(
'>=', $condition->
getField(), $extractionResult1->getData()[
'extractedValue']);
153 $filter2 = $this->createRowFilter(
'<=', $condition->
getField(), $extractionResult2->getData()[
'extractedValue']);
158 private function createRowFilter(
string $operator,
string $field, $value): array
160 return [$operator . $field => $value];
165 $documentService = \CBPRuntime::getRuntime()->getDocumentService();
167 $field = $documentService->getFieldTypeObject($this->getDocumentType(), $fieldProperties);
170 $extractionErrors = [];
173 $errors[] =
new Error(
'Can\'t create field type object');
177 if (!isset($fieldProperties[
'FieldName']))
179 $fieldProperties[
'FieldName'] =
'field_name';
182 $value = $field->extractValue(
183 [
'Field' => $fieldProperties[
'FieldName']],
184 [$fieldProperties[
'FieldName'] => $value],
189 foreach ($extractionErrors as $singleError)
191 if (is_array($singleError))
193 $errors[] =
new Error(
194 $singleError[
'message'] ??
'',
195 $singleError[
'code'] ??
'',
196 $singleError[
'parameter'] ??
''
207 $prefix = $fieldsMap[
'DynamicFilterFields'][
'FieldName'] .
'_';
209 $conditionGroup = [
'items' => []];
211 foreach ($currentValues[$prefix .
'field'] ?? [] as $index => $fieldName)
213 $operator = $currentValues[$prefix .
'operator'][$index];
216 && isset($currentValues[$prefix .
'value'][$index], $currentValues[$prefix .
'value'][$index + 1])
219 $currentValues[$prefix .
'value'][$index] = [
220 $currentValues[$prefix .
'value'][$index],
221 $currentValues[$prefix .
'value'][$index + 1],
224 array_splice($currentValues[$prefix .
'value'], $index + 1, 1);
227 $conditionGroup[
'items'][] = [
230 'object' => $currentValues[$prefix .
'object'][$index],
231 'field' => $currentValues[$prefix .
'field'][$index],
232 'operator' => $operator,
233 'value' => $currentValues[$prefix .
'value'][$index],
236 $currentValues[$prefix .
'joiner'][$index],
240 $result =
new Result();
241 $result->setData($conditionGroup);
getCurrentValues($compatible=false)
static createOk(?array $data=null)
extractValue(array $fieldProperties, $value)