/** * @param $value * @param \Bitrix\Main\Entity\Field $field * @param null|string $errorPhrase * @param null|array $additionalTemplates * * @return string */ protected function getErrorMessage($value, Entity\Field $field, $errorPhrase = null, $additionalTemplates = null) { if ($errorPhrase === null) { $errorPhrase = $this->errorPhrase !== null ? $this->errorPhrase : Loc::getMessage($this->errorPhraseCode); } $langValues = array('#VALUE#' => $value, '#FIELD_NAME#' => $field->getName(), '#FIELD_TITLE#' => $field->getTitle()); if (is_array($additionalTemplates)) { $langValues += $additionalTemplates; } return str_replace(array_keys($langValues), array_values($langValues), $errorPhrase); }
/** * @param $value * @param \Bitrix\Main\Entity\Field $field * @param null $errorPhrase * * @return mixed */ protected function getErrorMessage($value, Entity\Field $field, $errorPhrase = null) { if ($errorPhrase === null) { $errorPhrase = $this->errorPhrase; } $langValues = array('#VALUE#' => $value, '#FIELD_NAME#' => $field->getName(), '#FIELD_TITLE#' => $field->getTitle()); if (HasMessage($errorPhrase)) { return GetMessage($errorPhrase, $langValues); } else { return str_replace(array_keys($langValues), array_values($langValues), $errorPhrase); } }
public function validate($value, $primary, array $row, Entity\Field $field) { $entity = $field->getEntity(); $primaryNames = $entity->getPrimaryArray(); $query = new Entity\Query($entity); $query->setSelect($primaryNames); $query->setFilter(array('=' . $field->getName() => $value)); $query->setLimit(2); $result = $query->exec(); while ($existing = $result->fetch()) { // check primary foreach ($existing as $k => $v) { if (!isset($primary[$k]) || $primary[$k] != $existing[$k]) { return $this->getErrorMessage($value, $field); } } } return true; }
/** * Adds a runtime field (being created dinamycally, opposite to being described statically in the entity map) * * @param string|null $name * @param array|Field $fieldInfo * * @return Query */ public function registerRuntimeField($name, $fieldInfo) { if ((empty($name) || is_numeric($name)) && $fieldInfo instanceof Field) { $name = $fieldInfo->getName(); } $this->init_entity->addField($fieldInfo, $name); // force chain creation for further needs $chain = $this->getRegisteredChain($name, true); $this->registerChain('runtime', $chain); if ($chain->getLastElement()->getValue() instanceof ExpressionField) { $this->collectExprChains($chain, array('hidden')); } return $this; }
/** * @param Field $field * * @return bool */ protected function appendField(Field $field) { if (isset($this->fields[$field->getName()]) && !$this->isClone) { trigger_error(sprintf('Entity `%s` already has Field with name `%s`.', $this->getFullName(), $field->getName()), E_USER_WARNING); return false; } if ($field instanceof ReferenceField) { // references cache $this->references[$field->getRefEntityName()][] = $field; } $this->fields[$field->getName()] = $field; if ($field instanceof ScalarField && $field->isPrimary()) { $this->primary[] = $field->getName(); if ($field->isAutocomplete()) { $this->autoIncrement = $field->getName(); } } // add reference field for UField iblock_section if ($field instanceof UField && $field->getTypeId() == 'iblock_section') { $refFieldName = $field->getName() . '_BY'; if ($field->isMultiple()) { $localFieldName = $field->getValueFieldName(); } else { $localFieldName = $field->getName(); } $newFieldInfo = array('data_type' => 'Bitrix\\Iblock\\Section', 'reference' => array($localFieldName, 'ID')); $newRefField = new ReferenceField($refFieldName, $newFieldInfo['data_type'], $newFieldInfo['reference'][0], $newFieldInfo['reference'][1]); $newRefField->setEntity($this); $this->fields[$refFieldName] = $newRefField; } return true; }
/** * @param array $prop * @param Entity\Field $tableField * @return Entity\ExpressionField */ private static function linkPropertyValue(array $prop, Entity\Field &$tableField) { $propValueShortcut = "PROPERTY_{$prop['CODE']}_VALUE"; $isMultiple = $prop['MULTIPLE'] == 'Y'; $isOldProps = $prop['VERSION'] == 2; $concatSubquery = "GROUP_CONCAT(%s SEPARATOR '" . static::$concatSeparator . "')"; $propValueColumn = $isMultiple || $isOldProps ? 'VALUE' : "PROPERTY_{$prop['ID']}"; $mapEntity = new Entity\ExpressionField($propValueShortcut, $isMultiple ? $concatSubquery : '%s', "{$tableField->getName()}.{$propValueColumn}"); return $mapEntity; }