Documentation

Document

Document class generates a document instance or handles already existing document. Document is created based on template containing a file + field settings + main provider type. After that, field/placeholder values must be passed to the document. Now, document must be generated. It will be automatically saved in the document table after generation.

Class methods

MethodDescription
createByTemplate(\Bitrix\DocumentGenerator\Template $template, $value)Creates new instance based on template. Here $value its the value of the main provider.
loadById($documentId)Uploads a document instance from the database by its ID $documentId.
setValues(array $values)Sets field values. In the array $values key is the field name and value. Method does not resets to zero already set values, but re-writes the old ones.
setFields(array $fields)Sets fields descriptions. In the array $fields the key is field name and value is field description as an array. Method does not rest already set descriptions, but re-writes old ones.
checkFields($requiredOnly = true)Method returns array of descriptions for empty fields. When $requiredOnly = true, only required fields are checked. Otherwise returns description of all fields without values
getTemplate()Method returns document template when template is available.
getFile($sendToTransformation = true, $skipTransformationError = false)Method generates new document if not created previously. Returns object \Bitrix\Main\Result, containing array of data as follows:
[
    'downloadUrl' => '', // download link 
    'publicUrl' => '', // public link, when available
    'title' => '', // header 
    'number' => '', //number
    'id' => '', //ID
    'createTime' => '', //generation time
    'updateTime' => '', //update time
    'stampsEnabled' => '', //true when has stamps and signatures, otherwise false
    'isTransformationError' => '', //true with conversion error, otherwise false
    'value' => '', //values of the created main provider
    'values' => [], // array of additional values
];

When $sendToTransformation = false - file is not sent for conversion automatically.
When $skipTransformationError = true, conversion errors won't be added the result (used for suppressing this error to REST methods).
getProvider()Method returns an instance of \Bitrix\DocumentGenerator\DataProvider used for generating document. This method may return false, when failing to create an instance.
update(array $values)Method updates existing document with new set of values. Array $values is similar to the parameter in the method setValues().
getFields(array $fieldNames = [], $isConvertValuesToString = false, $groupsAsArrays = false)Method returns list of grouped fields with final values $fields - array of field names for printing the description
$isConvertValuesToString - when true - objects will be converted int strings (generally, for json)


© «Bitrix24», 2001-2024