/** * @param FieldType $fieldType * @param array $field * @param mixed $value * @param bool $allowSelection * @param int $renderMode * @return string */ protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode) { if ($value !== null && !is_array($value)) { $value = array($value); } $value = \CBPHelper::usersArrayToString($value, null, $fieldType->getDocumentType()); $renderResult = parent::renderControl($fieldType, $field, $value, $allowSelection, $renderMode); $renderResult .= static::renderControlSelector($field, null, false, '', $fieldType); return $renderResult; }
/** * @param FieldType $fieldType * @param array $field * @param mixed $value * @param bool $allowSelection * @param int $renderMode * @return string */ protected static function renderControl(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode) { $renderResult = '<select id="' . htmlspecialcharsbx(static::generateControlId($field)) . '" name="' . htmlspecialcharsbx(static::generateControlName($field)) . '">'; if (!$fieldType->isRequired()) { $renderResult .= '<option value="">[' . Loc::getMessage("BPDT_BOOL_NOT_SET") . ']</option>'; } $renderResult .= '<option value="Y"' . ($value == "Y" ? ' selected' : '') . '>' . Loc::getMessage("BPDT_BOOL_YES") . '</option> <option value="N"' . ($value == "N" ? ' selected' : '') . '>' . Loc::getMessage("BPDT_BOOL_NO") . '</option> </select>'; return $renderResult; }
/** * @param FieldType $fieldType * @return array */ private static function getDocumentSelectFields(FieldType $fieldType) { $runtime = \CBPRuntime::getRuntime(); $runtime->startRuntime(); $documentService = $runtime->getService("DocumentService"); $result = array(); $fields = $documentService->getDocumentFields($fieldType->getDocumentType()); foreach ($fields as $key => $field) { if ($field['Type'] == 'select' && substr($key, -10) != '_PRINTABLE') { $result[$key] = $field; } } return $result; }
/** * @param FieldType $fieldType * @param string $callbackFunctionName * @param mixed $value * @return string */ public static function renderControlOptions(FieldType $fieldType, $callbackFunctionName, $value) { if (is_array($value)) { reset($value); $valueTmp = (int) current($value); } else { $valueTmp = (int) $value; } $iblockId = 0; if ($valueTmp > 0) { $elementIterator = \CIBlockElement::getList(array(), array('ID' => $valueTmp), false, false, array('ID', 'IBLOCK_ID')); if ($element = $elementIterator->fetch()) { $iblockId = $element['IBLOCK_ID']; } } if ($iblockId <= 0 && (int) $fieldType->getOptions() > 0) { $iblockId = (int) $fieldType->getOptions(); } $defaultIBlockId = 0; $result = '<select id="WFSFormOptionsX" onchange="' . htmlspecialcharsbx($callbackFunctionName) . '(this.options[this.selectedIndex].value)">'; $iblockTypeIterator = \CIBlockParameters::getIBlockTypes(); foreach ($iblockTypeIterator as $iblockTypeId => $iblockTypeName) { $result .= '<optgroup label="' . htmlspecialcharsbx($iblockTypeName) . '">'; $iblockIterator = \CIBlock::getList(array('SORT' => 'ASC'), array('TYPE' => $iblockTypeId, 'ACTIVE' => 'Y')); while ($iblock = $iblockIterator->fetch()) { $result .= '<option value="' . $iblock['ID'] . '"' . ($iblock['ID'] == $iblockId ? ' selected' : '') . '>' . htmlspecialcharsbx($iblock['NAME']) . '</option>'; if ($defaultIBlockId <= 0 || $iblock['ID'] == $iblockId) { $defaultIBlockId = $iblock['ID']; } } $result .= '</optgroup>'; } $result .= '</select><!--__defaultOptionsValue:' . $defaultIBlockId . '--><!--__modifyOptionsPromt:' . Loc::getMessage('UTP_ELIST_DOCUMENT_MOPROMT') . '-->'; $fieldType->setOptions($defaultIBlockId); return $result; }
/** * @param array $parameterDocumentType * @return array */ public function getTypesMap(array $parameterDocumentType) { $k = implode('@', $parameterDocumentType); if (isset($this->typesMapCache[$k])) { return $this->typesMapCache[$k]; } $result = FieldType::getBaseTypesMap(); $documentFieldTypes = $this->GetDocumentFieldTypes($parameterDocumentType); foreach ($documentFieldTypes as $name => $field) { if (isset($field['typeClass'])) { $result[strtolower($name)] = $field['typeClass']; } } $this->typesMapCache[$k] = $result; return $result; }
public function GetDocumentFieldTypes($documentType) { $v = substr($documentType, strlen("type_")); if (intval($v) . "!" != $v . "!") { throw new CBPArgumentOutOfRangeException("documentType", $documentType); } $iblockId = intval($v); $typesMap = FieldType::getBaseTypesMap(); $arResult = array("S" => array("Name" => GetMessage("BPVDX_STRING"), "BaseType" => "string", 'typeClass' => $typesMap[FieldType::STRING]), "T" => array("Name" => GetMessage("BPVDX_TEXT"), "BaseType" => "text", 'typeClass' => $typesMap[FieldType::TEXT]), "N" => array("Name" => GetMessage("BPVDX_NUM"), "BaseType" => "double", 'typeClass' => $typesMap[FieldType::DOUBLE]), "L" => array("Name" => GetMessage("BPVDX_LIST"), "BaseType" => "select", "Complex" => true, 'typeClass' => $typesMap[FieldType::SELECT]), "F" => array("Name" => GetMessage("BPVDX_FILE"), "BaseType" => "file", 'typeClass' => $typesMap[FieldType::FILE]), "B" => array("Name" => GetMessage("BPVDX_YN"), "BaseType" => "bool", 'typeClass' => $typesMap[FieldType::BOOL])); foreach (CIBlockProperty::GetUserType() as $ar) { $t = $ar["PROPERTY_TYPE"] . ":" . $ar["USER_TYPE"]; if (COption::GetOptionString("bizproc", "SkipNonPublicCustomTypes", "N") == "Y" && !array_key_exists("GetPublicEditHTML", $ar) && $t != "S:UserID" && $t != "S:DateTime") { continue; } $arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string", 'typeClass' => '\\Bitrix\\Iblock\\BizprocType\\UserTypeProperty'); if ($t == "S:UserID") { $arResult[$t]["BaseType"] = "user"; $arResult[$t]['typeClass'] = $typesMap[FieldType::USER]; } elseif ($t == "S:employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y") { $arResult[$t]["BaseType"] = "user"; $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyEmployee'; } elseif ($t == "S:DateTime") { $arResult[$t]["BaseType"] = "datetime"; $arResult[$t]["typeClass"] = $typesMap[FieldType::DATETIME]; } elseif ($t == "S:Date") { $arResult[$t]["BaseType"] = "date"; $arResult[$t]["typeClass"] = $typesMap[FieldType::DATE]; } elseif ($t == "E:EList") { $arResult[$t]["BaseType"] = "string"; $arResult[$t]["Complex"] = true; $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyElist'; } elseif ($t == 'S:HTML') { $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyHtml'; } elseif ($t == 'S:DiskFile') { $arResult[$t]["BaseType"] = "int"; $arResult[$t]['typeClass'] = '\\Bitrix\\Iblock\\BizprocType\\UserTypePropertyDiskFile'; } } return $arResult; }
/** * @param FieldType $fieldType * @return array */ protected static function getFieldOptions(FieldType $fieldType) { $options = $fieldType->getOptions(); return self::normalizeOptions($options); }
protected static function getUserType(FieldType $fieldType) { return \CIBlockProperty::getUserType(substr($fieldType->getType(), 2)); }
public static function GetPropertiesDialogValues($documentType, $activityName, &$arWorkflowTemplate, &$arWorkflowParameters, &$arWorkflowVariables, $arCurrentValues, &$arErrors) { $arErrors = array(); $runtime = CBPRuntime::GetRuntime(); $arProperties = array("FieldValue" => array()); /** @var CBPDocumentService $documentService */ $documentService = $runtime->GetService("DocumentService"); $arNewFieldsMap = array(); if (array_key_exists("new_field_name", $arCurrentValues) && is_array($arCurrentValues["new_field_name"])) { $arNewFieldKeys = array_keys($arCurrentValues["new_field_name"]); foreach ($arNewFieldKeys as $k) { $code = trim($arCurrentValues["new_field_code"][$k]); $arFieldsTmp = array("name" => $arCurrentValues["new_field_name"][$k], "code" => $code, "type" => $arCurrentValues["new_field_type"][$k], "multiple" => $arCurrentValues["new_field_mult"][$k], "required" => $arCurrentValues["new_field_req"][$k], "options" => $arCurrentValues["new_field_options"][$k]); $newCode = $documentService->AddDocumentField($documentType, $arFieldsTmp); $property = FieldType::normalizeProperty($arFieldsTmp); $property['Code'] = $newCode; $property['Name'] = $arFieldsTmp['name']; $arNewFieldsMap[$code] = $property; } } $arDocumentFields = $documentService->GetDocumentFields($documentType); foreach ($arCurrentValues as $key => $value) { if (strpos($key, 'document_field_') !== 0) { continue; } $fieldKey = array_key_exists($value, $arNewFieldsMap) ? $arNewFieldsMap[$value]['Code'] : $value; if (!isset($arDocumentFields[$fieldKey]) || !$arDocumentFields[$fieldKey]["Editable"]) { continue; } $property = array_key_exists($value, $arNewFieldsMap) ? $arNewFieldsMap[$value] : $arDocumentFields[$fieldKey]; $r = $documentService->GetFieldInputValue($documentType, $property, $value, $arCurrentValues, $arErrors); if (count($arErrors) > 0) { return false; } if (CBPHelper::getBool($property['Required']) && CBPHelper::isEmptyValue($r)) { $arErrors[] = array("code" => "NotExist", "parameter" => $fieldKey, "message" => GetMessage("BPSFA_ARGUMENT_NULL", array('#PARAM#' => $property['Name']))); return false; } $arProperties["FieldValue"][$fieldKey] = $r; } $arErrors = self::ValidateProperties($arProperties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser)); if (count($arErrors) > 0) { return false; } $arCurrentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($arWorkflowTemplate, $activityName); $arCurrentActivity["Properties"] = $arProperties; return true; }
private static function getIblockId(FieldType $fieldType) { $documentType = $fieldType->getDocumentType(); $type = explode('_', $documentType[2]); return intval($type[1]); }
public static function clearValueMultiple(FieldType $fieldType, $values) { if (!Loader::includeModule('disk')) { return; } if (!is_array($values)) { $values = array($values); } $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType('lists_workflow'); $documentType = $fieldType->getDocumentType(); $iblockId = intval(substr($documentType[2], strlen("iblock_"))); if (!$iblockId) { return; } foreach ($values as $value) { $attachedModel = \Bitrix\Disk\AttachedObject::load(array('OBJECT_ID' => $value, '=ENTITY_TYPE' => $connectorClass, '=ENTITY_ID' => $iblockId, '=MODULE_ID' => $moduleId)); if (!$attachedModel) { continue; } if ($userFieldManager->belongsToEntity($attachedModel, "lists_workflow", $iblockId)) { \Bitrix\Disk\AttachedObject::detachByFilter(array('ID' => $attachedModel->getId())); } } }
public static function clearValueSingle(FieldType $fieldType, $value) { if (!Loader::includeModule('disk')) { return; } $value = (int) $value; if (!$value) { return; } $documentType = $fieldType->getDocumentType(); $iblockId = intval(substr($documentType[2], strlen("iblock_"))); if (!$iblockId) { return; } $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); list($type, $realId) = \Bitrix\Disk\Uf\FileUserType::detectType($value); if ($type == \Bitrix\Disk\Uf\FileUserType::TYPE_ALREADY_ATTACHED) { $attachedModel = \Bitrix\Disk\AttachedObject::loadById($realId); if (!$attachedModel) { return; } if ($userFieldManager->belongsToEntity($attachedModel, "iblock_workflow", $iblockId)) { \Bitrix\Disk\AttachedObject::detachByFilter(array('ID' => $realId)); } } }
/** * @param array $field * @param null|string $value * @param bool $showInput * @param string $selectorMode * @param FieldType $fieldType * @return string */ protected static function renderControlSelector(array $field, $value = null, $showInput = false, $selectorMode = '', FieldType $fieldType = null) { $html = ''; $controlId = static::generateControlId($field); if ($showInput) { $controlId = $controlId . '_text'; $name = static::generateControlName($field) . '_text'; $html = '<input type="text" id="' . htmlspecialcharsbx($controlId) . '" name="' . htmlspecialcharsbx($name) . '" value="' . htmlspecialcharsbx((string) $value) . '">'; } $html .= '<input type="button" value="..." onclick="BPAShowSelector(\'' . htmlspecialcharsbx($controlId) . '\', \'' . htmlspecialcharsbx(static::getType()) . '\', ' . ($selectorMode ? '\'' . htmlspecialcharsbx($selectorMode) . '\'' : 'null') . ', null, ' . htmlspecialcharsbx(\Bitrix\Main\Web\Json::encode($fieldType ? $fieldType->getDocumentType() : null)) . ');">'; return $html; }