static function getDocumentFields($documentType)
{
$iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
if ($iblockId <= 0)
throw new CBPArgumentOutOfRangeException("documentType", $documentType);
$documentFieldTypes = self::getDocumentFieldTypes($documentType);
$result = self::getSystemIblockFields();
$dbProperties = CIBlockProperty::getList(
array("sort" => "asc", "name" => "asc"),
array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y')
);
$ignoreProperty = array();
while ($property = $dbProperties->fetch())
{
if (trim($property["CODE"]) <> '')
{
$key = "PROPERTY_".$property["CODE"];
$ignoreProperty["PROPERTY_".$property["ID"]] = "PROPERTY_".$property["CODE"];
}
else
{
$key = "PROPERTY_".$property["ID"];
$ignoreProperty["PROPERTY_".$property["ID"]] = 0;
}
$result[$key] = array(
"Name" => $property["NAME"],
"Filterable" => ($property["FILTRABLE"] == "Y"),
"Editable" => true,
"Required" => ($property["IS_REQUIRED"] == "Y"),
"Multiple" => ($property["MULTIPLE"] == "Y"),
"TypeReal" => $property["PROPERTY_TYPE"],
"UserTypeSettings" => $property["USER_TYPE_SETTINGS"]
);
if(trim($property["CODE"]) <> '')
$result[$key]["Alias"] = "PROPERTY_".$property["ID"];
if ($property["USER_TYPE"] <> '')
{
$result[$key]["TypeReal"] = $property["PROPERTY_TYPE"].":".$property["USER_TYPE"];
if ($property["USER_TYPE"] == "UserID"
|| $property["USER_TYPE"] == "employee" && (COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
{
$result[$key]["Type"] = "user";
$result[$key."_PRINTABLE"] = array(
"Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
"Filterable" => false,
"Editable" => false,
"Required" => false,
"Multiple" => ($property["MULTIPLE"] == "Y"),
"Type" => "string",
);
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
elseif ($property["USER_TYPE"] == "DateTime")
{
$result[$key]["Type"] = "datetime";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
elseif ($property["USER_TYPE"] == "Date")
{
$result[$key]["Type"] = "date";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
elseif ($property["USER_TYPE"] == "EList")
{
$result[$key]["Type"] = "E:EList";
$result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
}
elseif ($property["USER_TYPE"] == "ECrm")
{
$result[$key]["Type"] = "E:ECrm";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
$result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
}
elseif ($property["USER_TYPE"] == "Money")
{
$result[$key]["Type"] = "S:Money";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
$result[$key."_PRINTABLE"] = array(
"Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
"Filterable" => false,
"Editable" => false,
"Required" => false,
"Multiple" => ($property["MULTIPLE"] == "Y"),
"Type" => "string",
);
}
elseif ($property["USER_TYPE"] == "Sequence")
{
$result[$key]["Type"] = "N:Sequence";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
$result[$key]["Options"] = $property["USER_TYPE_SETTINGS"];
}
elseif ($property["USER_TYPE"] == "DiskFile")
{
$result[$key]["Type"] = "S:DiskFile";
$result[$key."_PRINTABLE"] = array(
"Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
"Filterable" => false,
"Editable" => false,
"Required" => false,
"Multiple" => ($property["MULTIPLE"] == "Y"),
"Type" => "int",
);
}
elseif ($property["USER_TYPE"] == "HTML")
{
$result[$key]["Type"] = "S:HTML";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
else
{
$result[$key]["Type"] = "string";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
}
elseif ($property["PROPERTY_TYPE"] == "L")
{
$result[$key]["Type"] = "select";
$result[$key]["Options"] = array();
$dbPropertyEnums = CIBlockProperty::getPropertyEnum($property["ID"]);
while ($propertyEnum = $dbPropertyEnums->getNext())
{
$result[$key]["Options"][$propertyEnum["XML_ID"]] = $propertyEnum["~VALUE"];
if($propertyEnum["DEF"] == "Y")
$result[$key]["DefaultValue"] = $propertyEnum["~VALUE"];
}
}
elseif ($property["PROPERTY_TYPE"] == "N")
{
$result[$key]["Type"] = "double";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
elseif ($property["PROPERTY_TYPE"] == "F")
{
$result[$key]["Type"] = "file";
$result[$key."_PRINTABLE"] = array(
"Name" => $property["NAME"].GetMessage("IBD_FIELD_USERNAME_PROPERTY"),
"Filterable" => false,
"Editable" => false,
"Required" => false,
"Multiple" => ($property["MULTIPLE"] == "Y"),
"Type" => "string",
);
}
elseif ($property["PROPERTY_TYPE"] == "S")
{
$result[$key]["Type"] = "string";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
elseif ($property["PROPERTY_TYPE"] == "E")
{
$result[$key]["Type"] = "E:EList";
$result[$key]["Options"] = $property["LINK_IBLOCK_ID"];
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
else
{
$result[$key]["Type"] = "string";
$result[$key]["DefaultValue"] = $property["DEFAULT_VALUE"];
}
}
$list = new CList($iblockId);
$fields = $list->getFields();
foreach($fields as $fieldId => $field)
{
if(empty($field["SETTINGS"]))
$field["SETTINGS"] = array("SHOW_ADD_FORM" => 'Y', "SHOW_EDIT_FORM"=>'Y');
if(array_key_exists($fieldId, $ignoreProperty))
{
$ignoreProperty[$fieldId] ? $key = $ignoreProperty[$fieldId] : $key = $fieldId;
$result[$key]["sort"] = $field["SORT"];
$result[$key]["settings"] = $field["SETTINGS"];
$result[$key]["active"] = true;
$result[$key]["DefaultValue"] = $field["DEFAULT_VALUE"];
if($field["ROW_COUNT"] && $field["COL_COUNT"])
{
$result[$key]["row_count"] = $field["ROW_COUNT"];
$result[$key]["col_count"] = $field["COL_COUNT"];
}
}
else
{
$result[$fieldId] = array(
"Name" => $field['NAME'],
"Filterable" => !empty($result[$fieldId]['Filterable']) ? $result[$fieldId]['Filterable'] : false,
"Editable" => !empty($result[$fieldId]['Editable']) ? $result[$fieldId]['Editable'] : true,
"Required" => ($field['IS_REQUIRED'] == 'Y'),
"Multiple" => ($field['MULTIPLE'] == 'Y'),
"Type" => !empty($result[$fieldId]['Type']) ? $result[$fieldId]['Type'] : $field['TYPE'],
"sort" => $field["SORT"],
"settings" => $field["SETTINGS"],
"active" => true,
"active_type" => $field['TYPE'],
"DefaultValue" => $field["DEFAULT_VALUE"],
);
if(isset($field['ROW_COUNT'], $field['COL_COUNT']) && $field["ROW_COUNT"] && $field["COL_COUNT"])
{
$result[$fieldId]["row_count"] = $field["ROW_COUNT"];
$result[$fieldId]["col_count"] = $field["COL_COUNT"];
}
}
}
$keys = array_keys($result);
foreach ($keys as $k)
{
$result[$k]["BaseType"] = $documentFieldTypes[$result[$k]["Type"]]["BaseType"];
$result[$k]["Complex"] = $documentFieldTypes[$result[$k]["Type"]]["Complex"] ?? null;
}
return $result;
}