Закажите бесплатную презентацию продуктов РосБизнесСофт прямо сейчас!
В справочнике «Вложения» (references.uploads) добавить целочисленное поле type — Тип
Для добавления пользователям возможности прикреплять файлы к дукументу необходимо в шаблоне формы редактирования документа добавить такой код:
$attachmantsTitle
{FILES}
{/FILES}
<div class="btn-group overleave-click" count-children="0">
<input type="file" name="descFiles[]" multiple="true" style="width: 300px;">
</div>

В сценарии (PHP-код) в методе onSaved необходимо реализовать обработку прикрепления файла к документу.
protected function onSaved()
{
if (isset($_FILES['descFiles'])) {
$structure = $this->structure->getBlind();
if (isset($structure)) {
$count = count($_FILES['descFiles']['name']);
for ($i = 0; $i < $count; $i++) {
if (is_uploaded_file($_FILES['descFiles']['tmp_name'][$i])) {
$files = [
'putFile' => curl_file_create($_FILES['descFiles']['tmp_name'][$i], 'xml', $_FILES['descFiles']['name'][$i]),
];
$response = Transfer::sendIntoStorage('putFile', $files);
if (is_array($response) && count($response) > 0 && array_key_exists('filename', $response) && array_key_exists('file', $response) && array_key_exists('size', $response)) {
$this->Data->{'references.uploads'}->create()
->visible(1)
->date(date('d-m-Y'))
->version(1)
->name($response['filename'])
->folder($structure)
->link($response['file'])
->size($response['size'])
->status(1)
->type(1) // for Machine Description files
->storage_url($this->config['storageURL'])
->restore()->sync(true);
}
}
}
}
}
}
В сценарии (PHP-код) в методе onPlay необходимо реализовать отображения уже прикрепленных файлов.
protected function onPlay()
{
if ($this->isEditForm()) {
$uploads = $this->Data->{'references.uploads'}->filter('visible=1')->filter('folder=references.products:' . $this->structure->id)->filter('type=1');
if ($uploads->num() > 0) {
$this->page->set(['BASE.attachmantsTitle' => 'Вложения:']);
foreach ($uploads as $upload) {
$this->page->block('BASE.FILES', [
'id' => $upload->id,
'name' => $upload->name,
'link' => $this->getFileByPath($upload->link, $upload->name),
]);
}
}
}
}