/** * Fields factory * @param string $fieldName * @param array $fieldInfo * * @return Field * @throws Main\ArgumentException */ public function initializeField($fieldName, $fieldInfo) { if ($fieldInfo instanceof Field) { $field = $fieldInfo; } elseif (!empty($fieldInfo['reference'])) { if (is_string($fieldInfo['data_type']) && strpos($fieldInfo['data_type'], '\\') === false) { // if reference has no namespace, then it'is in the same namespace $fieldInfo['data_type'] = $this->getNamespace() . $fieldInfo['data_type']; } //$refEntity = Base::getInstance($fieldInfo['data_type']."Table"); $field = new ReferenceField($fieldName, $fieldInfo['data_type'], $fieldInfo['reference'], $fieldInfo); } elseif (!empty($fieldInfo['expression'])) { $expression = array_shift($fieldInfo['expression']); $buildFrom = $fieldInfo['expression']; $field = new ExpressionField($fieldName, $expression, $buildFrom, $fieldInfo); } elseif (!empty($fieldInfo['USER_TYPE_ID'])) { $field = new UField($fieldInfo); } else { $fieldClass = Base::snake2camel($fieldInfo['data_type']) . 'Field'; $fieldClass = __NAMESPACE__ . '\\' . $fieldClass; if (strlen($fieldInfo['data_type']) && class_exists($fieldClass)) { $field = new $fieldClass($fieldName, $fieldInfo); } elseif (strlen($fieldInfo['data_type']) && class_exists($fieldInfo['data_type'])) { $fieldClass = $fieldInfo['data_type']; $field = new $fieldClass($fieldName, $fieldInfo); } else { throw new Main\ArgumentException(sprintf('Unknown data type "%s" found for `%s` field in %s Entity.', $fieldInfo['data_type'], $fieldName, $this->getName())); } } $field->setEntity($this); return $field; }
/** * @param $iblockId * @return Entity\Base * @throws ArgumentException */ public static function compileEntity($iblockId) { $iblock = IblockStructure::iblock($iblockId); if (!$iblock) { throw new ArgumentException('Указан несуществующий идентификатор инфоблока'); } $entityName = "Iblock" . Entity\Base::snake2camel($iblockId) . "SectionTable"; $fullEntityName = '\\' . __NAMESPACE__ . '\\' . $entityName; $code = "\n namespace " . __NAMESPACE__ . ";\n class {$entityName} extends SectionTable {\n public static function getIblockId(){\n return {$iblock['ID']};\n }\n public static function getUfId(){\n return 'IBLOCK_{$iblock['ID']}_SECTION';\n }\n }\n "; if (!class_exists($fullEntityName)) { eval($code); } return Entity\Base::getInstance($fullEntityName); }
} if ($columnInfo["length"] > 0 && $columnInfo["orm_type"] == "string") { $validateFunctionName = "validate" . \Bitrix\Main\Entity\Base::snake2camel($columnName); echo "\t\t\t\t'validation' => array(_" . "_CLASS_" . "_, '" . $validateFunctionName . "'),\n"; $arValidators[$validateFunctionName] = array("length" => $columnInfo["length"], "field" => $columnName); } $messageId = strtoupper(implode("_", $tableParts) . "_ENTITY_" . $columnName . "_FIELD"); $arMessages[$messageId] = ""; echo "\t\t\t\t'title' => Loc::getMessage('" . $messageId . "'),\n"; echo "\t\t\t),\n"; } foreach ($arParents as $columnName => $parentInfo) { $parentTableParts = explode("_", $parentInfo["PARENT_TABLE"]); array_shift($parentTableParts); $parentModuleNamespace = ucfirst($parentTableParts[0]); $parentClassName = \Bitrix\Main\Entity\Base::snake2camel(implode("_", $parentTableParts)); $columnNameEx = preg_replace("/_ID\$/", "", $columnName); echo "\t\t\t'" . $columnNameEx . "' => array(\n"; echo "\t\t\t\t'data_type' => 'Bitrix\\" . $parentModuleNamespace . "\\" . $parentClassName . "',\n"; echo "\t\t\t\t'reference' => array('=this." . $columnName . "' => 'ref." . $parentInfo["PARENT_COLUMN"] . "'),\n"; echo "\t\t\t),\n"; } echo "\t\t);\n"; echo "\t}\n"; foreach ($arValidators as $validateFunctionName => $validator) { echo "\t/**\n"; echo "\t * Returns validators for " . $validator["field"] . " field.\n"; echo "\t *\n"; echo "\t * @return array\n"; echo "\t */\n"; echo "\tpublic static function " . $validateFunctionName . "()\n";
public static function getUtmEntityClassName(Entity\Base $hlentity, $userfield) { return $hlentity->getName() . 'Utm' . Entity\Base::snake2camel($userfield['FIELD_NAME']); }