23 return FieldType::FILE;
34 'callable' =>
'formatValueSrc',
39 'callable' =>
'formatValuePublicLink',
44 'callable' =>
'formatValueShortLink',
49 'callable' =>
'formatValueName',
67 if (\CBPHelper::isAssociativeArray($value))
69 $value = array_keys($value);
72 $value = current($value);
85 $value = (int) $value;
86 $iterator = \CFile::getByID($value);
87 if ($file = $iterator->fetch())
89 return '[url=/bitrix/tools/bizproc_show_file.php?f='.urlencode($file[
'FILE_NAME']).
'&hash='
90 .md5($file[
'FILE_NAME'])
91 .
'&i='.$value.
'&h='.md5($file[
'SUBDIR']).
']'
92 .htmlspecialcharsbx($file[
'ORIGINAL_NAME'])
106 $value = (int) $value;
107 $file = \CFile::getFileArray($value);
108 if ($file && $file[
'SRC'])
122 $value = (int) $value;
123 $file = \CFile::getFileArray($value);
124 if ($file && ($file[
'ORIGINAL_NAME'] || $file[
'FILE_NAME']))
126 return $file[
'ORIGINAL_NAME'] ?: $file[
'FILE_NAME'];
138 $fileId = (int) $value;
141 return \Bitrix\Bizproc\Controller\File::getPublicLink($fileId);
153 $pubLink = static::formatValuePublicLink($fieldType, $value);
156 return Main\Engine\UrlManager::getInstance()->getHostUrl().\CBXShortUri::getShortUri($pubLink);
167 public static function convertTo(
FieldType $fieldType, $value, $toTypeClass)
170 $type = $toTypeClass::getType();
173 case FieldType::FILE:
174 $value = (int) $value;
204 $value = (array) $value;
205 if (\CBPHelper::isAssociativeArray($value))
207 $value = array_keys($value);
210 return parent::convertValueMultiple($fieldType, $value, $toTypeClass);
232 if ($renderMode & FieldType::RENDER_MODE_DESIGNER)
237 $classNameHtml = htmlspecialcharsbx(static::generateControlClassName($fieldType, $field));
238 $idHtml = htmlspecialcharsbx(static::generateControlId($field));
239 $nameHtml = htmlspecialcharsbx(static::generateControlName($field));
241 if ($renderMode & FieldType::RENDER_MODE_PUBLIC)
244 $onchange =
'this.nextSibling.textContent = BX.Bizproc.FieldType.File.parseLabel(this.value);';
245 $onchange = htmlspecialcharsbx($onchange);
248 <div
class=
"{$classNameHtml}">
250 <span
class=
"webform-small-button">{$msg}</span>
252 <input type=
"file" id=
"{$idHtml}" name=
"{$nameHtml}" onchange=
"{$onchange}">
253 <span
class=
"bizproc-type-control-file-label"></span>
258 return '<input type="file" class="'.$classNameHtml.
'" id="'.$idHtml.
'" name="'.$nameHtml.
'">';
271 if ($allowSelection && $renderMode & FieldType::RENDER_MODE_PUBLIC)
273 return self::renderPublicSelectableControlSingle($fieldType, $field, $value);
276 if ($renderMode & FieldType::RENDER_MODE_MOBILE)
278 return self::renderMobileControl($fieldType, $field, $value);
281 return parent::renderControlSingle($fieldType, $field, $value, $allowSelection, $renderMode);
294 if ($renderMode & FieldType::RENDER_MODE_DESIGNER && !$allowSelection)
299 if ($allowSelection && $renderMode & FieldType::RENDER_MODE_PUBLIC)
301 return self::renderPublicSelectableControlMultiple($fieldType, $field, $value);
304 if ($renderMode & FieldType::RENDER_MODE_MOBILE)
306 return self::renderMobileControl($fieldType, $field, $value);
309 if ($renderMode & FieldType::RENDER_MODE_DESIGNER)
311 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
324 foreach ($value as $k => $v)
326 $singleField = $field;
327 $singleField[
'Index'] = $k;
328 $controls[] = parent::renderControlSingle($fieldType, $singleField, $v, $allowSelection, $renderMode);
331 return static::wrapCloneableControls($controls, static::generateControlName($field));
334 return parent::renderControlMultiple($fieldType, $field, $value, $allowSelection, $renderMode);
337 private static function renderPublicSelectableControlSingle(
FieldType $fieldType, array $field, $value)
339 $name = static::generateControlName($field);
340 $className = static::generateControlClassName($fieldType, $field);
341 $className = str_replace(
'file',
'file-selectable', $className);
344 '<input type="text" class="%s" name="%s" value="%s" placeholder="%s" data-role="inline-selector-target" data-selector-type="file" data-property="%s"/>',
345 htmlspecialcharsbx($className),
346 htmlspecialcharsbx($name),
347 htmlspecialcharsbx((
string)$value),
349 htmlspecialcharsbx(Main\Web\Json::encode($fieldType->
getProperty()))
353 private static function renderPublicSelectableControlMultiple(
FieldType $fieldType, array $field, $value)
355 if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value))
368 foreach ($value as $k => $v)
370 $singleField = $field;
371 $singleField[
'Index'] = $k;
372 $controls[] = static::renderPublicSelectableControlSingle(
379 return static::renderPublicMultipleWrapper($fieldType, $field, $controls);
382 private static function renderMobileControl(FieldType $fieldType, array $field, $value)
387 $APPLICATION->IncludeComponent(
388 'bitrix:main.file.input',
391 'MODULE_ID' =>
'bizproc',
392 'CONTROL_ID' => static::generateControlId($field),
393 'ALLOW_UPLOAD' =>
'A',
394 'INPUT_NAME' => static::generateControlName($field),
395 'INPUT_VALUE' => $value,
396 'MULTIPLE' => $fieldType->isMultiple() ?
'Y' :
'N'
400 return ob_get_clean();
411 $value = parent::extractValue($fieldType, $field, $request);
413 if (is_array($value) && !empty($value[
'name']) && !empty($value[
'tmp_name']))
415 if (!is_uploaded_file($value[
'tmp_name']))
419 'code' =>
'ErrorValue',
421 'parameter' => static::generateControlName($field),
426 if (!array_key_exists(
'MODULE_ID', $value) || $value[
'MODULE_ID'] ==
'')
427 $value[
'MODULE_ID'] =
'bizproc';
429 $value = \CFile::saveFile($value,
'bizproc_wf');
434 'code' =>
'ErrorValue',
436 'parameter' => static::generateControlName($field),
441 elseif (\CBPActivity::isExpression($value))
445 elseif (is_numeric($value) && defined(
'BX_MOBILE'))
447 $file = \CFile::getById($value)->fetch();
448 if (!$file || $file[
'MODULE_ID'] !==
'bizproc')
453 elseif (is_string($value) && $value !==
'')
457 $unsignedValue = \CBPDocument::unSignParameters($value);
458 if (isset($unsignedValue[0]) && is_numeric($unsignedValue[0]) && (
int)$unsignedValue[0] > 0)
460 $value = (int)$unsignedValue[0];
477 if ($context ===
'rest' && is_numeric($value))
479 return \CRestUtil::GetFile($value);
482 return parent::externalizeValue($fieldType, $context, $value);
487 if ($context ===
'rest')
489 $fileFields = \CRestUtil::saveFile($value);
493 $fileFields[
'MODULE_ID'] =
'bizproc';
494 return (
int) \CFile::saveFile($fileFields,
'bizproc_rest');
498 return parent::internalizeValue($fieldType, $context, $value);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)