dolibarr  17.0.4
Public Member Functions | Private Member Functions | List of all members
Documents Class Reference

API class for receive files. More...

Inheritance diagram for Documents:
Inheritance graph
[legend]
Collaboration diagram for Documents:
Collaboration graph
[legend]

Public Member Functions

 __construct ()
 Constructor.
 
 index ($modulepart, $original_file='')
 Download a document. More...
 
 builddoc ($modulepart, $original_file='', $doctemplate='', $langcode='')
 Build a document. More...
 
 getDocumentsListByElement ($modulepart, $id=0, $ref='', $sortfield='', $sortorder='')
 Return the list of documents of a dedicated element (from its ID or Ref) More...
 
 post ($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0, $createdirifnotexists=1)
 Return a document. More...
 
 delete ($modulepart, $original_file)
 Delete a document. More...
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor. More...
 

Private Member Functions

 _validate_file ($data)
 Validate fields before create or update object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name. More...
 
 _cleanObjectDatas ($object)
 Clean sensible object datas. More...
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used. More...
 
- Static Protected Member Functions inherited from DolibarrApi
static _checkAccessToResource ($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
 Check access by user to a given resource. More...
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string. More...
 

Detailed Description

API class for receive files.

@access protected ,external}

Definition at line 32 of file api_documents.class.php.

Member Function Documentation

◆ _validate_file()

Documents::_validate_file (   $data)
private

Validate fields before create or update object.

Parameters
array$dataArray with data to verify
Returns
array
Exceptions
RestException

Definition at line 851 of file api_documents.class.php.

◆ builddoc()

Documents::builddoc (   $modulepart,
  $original_file = '',
  $doctemplate = '',
  $langcode = '' 
)

Build a document.

Test sample 1: { "modulepart": "invoice", "original_file": "FA1701-001/FA1701-001.pdf", "doctemplate": "crabe", "langcode": "fr_FR" }.

Parameters
string$modulepartName of module or area concerned by file download ('thirdparty', 'member', 'proposal', 'supplier_proposal', 'order', 'supplier_order', 'invoice', 'supplier_invoice', 'shipment', 'project', ...)
string$original_fileRelative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf).
string$doctemplateSet here the doc template to use for document generation (If not set, use the default template).
string$langcodeLanguage code like 'en_US', 'fr_FR', 'es_ES', ... (If not set, use the default language).
Returns
array List of documents
Exceptions
RestException500 System error
RestException501
RestException400
RestException401
RestException404

@url PUT /builddoc

Definition at line 137 of file api_documents.class.php.

◆ delete()

Documents::delete (   $modulepart,
  $original_file 
)

Delete a document.

Parameters
string$modulepartName of module or area concerned by file download ('product', ...)
string$original_fileRelative path with filename, relative to modulepart (for example: PRODUCT-REF-999/IMAGE-999.jpg)
Returns
array List of documents
Exceptions
RestException400
RestException401
RestException404

@url DELETE /

Definition at line 786 of file api_documents.class.php.

◆ getDocumentsListByElement()

Documents::getDocumentsListByElement (   $modulepart,
  $id = 0,
  $ref = '',
  $sortfield = '',
  $sortorder = '' 
)

Return the list of documents of a dedicated element (from its ID or Ref)

Parameters
string$modulepartName of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'supplier_invoice', 'shipment', 'project', ...)
int$idID of element
string$refRef of element
string$sortfieldSort criteria ('','fullname','relativename','name','date','size')
string$sortorderSort order ('asc' or 'desc')
Returns
array Array of documents with path
Exceptions
RestException400
RestException401
RestException404
RestException500 System error

@url GET /

Definition at line 256 of file api_documents.class.php.

◆ index()

Documents::index (   $modulepart,
  $original_file = '' 
)

Download a document.

Note that, this API is similar to using the wrapper link "documents.php" to download a file (used for internal HTML links of documents into application), but with no need to have a session cookie (the token is used instead).

Parameters
string$modulepartName of module or area concerned by file download ('facture', ...)
string$original_fileRelative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
Returns
array List of documents
Exceptions
RestException400
RestException401
RestException404

@url GET /download

Definition at line 68 of file api_documents.class.php.

◆ post()

Documents::post (   $filename,
  $modulepart,
  $ref = '',
  $subdir = '',
  $filecontent = '',
  $fileencoding = '',
  $overwriteifexists = 0,
  $createdirifnotexists = 1 
)

Return a document.

Parameters
int$idID of document
Returns
array Array with data of file
Exceptions
RestExceptionUpload a file.

Test sample for invoice: { "filename": "mynewfile.txt", "modulepart": "invoice", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. Test sample for supplier invoice: { "filename": "mynewfile.txt", "modulepart": "supplier_invoice", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }. Test sample for medias file: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }.

Parameters
string$filenameName of file to create ('FA1705-0123.txt')
string$modulepartName of module or area concerned by file upload ('product', 'service', 'invoice', 'proposal', 'project', 'project_task', 'supplier_invoice', 'expensereport', 'member', ...)
string$refReference of object (This will define subdir automatically and store submited file into it)
string$subdirSubdirectory (Only if ref not provided)
string$filecontentFile content (string with file content. An empty file will be created if this parameter is not provided)
string$fileencodingFile encoding (''=no encoding, 'base64'=Base 64)
int$overwriteifexistsOverwrite file if exists (1 by default)
int$createdirifnotexistsCreate subdirectories if the doesn't exists (1 by default)
Returns
string
Exceptions
RestException400
RestException401
RestException404
RestException500 System error

@url POST /upload

Definition at line 586 of file api_documents.class.php.


The documentation for this class was generated from the following file: