Documents

Create a document

You can create a new document by calling the add method of the document controller with document details.

You can find a complete list of document fields in our JSON API documentation.

<?php
$document_details = [
    'title'              => 'document title',
    'docman_category_id' => 1,
    'storage_path'       => 'path/to/the/file.txt' // part of the path that comes after joomlatools-files/docman-files/
];
$result = Koowa::getObject('com://site/docman.controller.document')
    ->add($document_details);

Edit a document

Editing a document is done by passing the ID of the document to the controller and then calling the edit action:

<?php
$document_id      = 12345; // document ID
$document_details = [
    'title'        => 'new title',
    'storage_path' => 'new/path/to/the/file.txt' // part of the path that comes after joomlatools-files/docman-files/
];
$result = Koowa::getObject('com://site/docman.controller.document')
    ->id($document_id)
    ->edit($document_details);

Delete a document

Deleting is done by passing the ID of the document to the controller and then calling the delete action:

<?php
$document_id = 12345; // document ID
$result  = Koowa::getObject('com://site/docman.controller.document')
    ->id($document_id)
    ->delete();

Fetch document(s)

For fetching documents, we set permission values for the current user, limit the results to 50 documents, and optionally filter by category as well:

<?php
// Get the controller
$controller = Koowa::getObject('com://site/docman.controller.document');
$user       = Koowa::getObject('user');
// Fetch documents in a category
$documents_in_a_category = $controller
    ->access($user->getRoles()) // Permissions
    ->current_user($user->getId())
    ->enabled(1)
    ->status('published') 
    ->category(1) // Category ID here
    ->limit(50)   // Limiting to 50 documents
    ->offset(0)   // You can set this to 50 in the next call to paginate results
    ->browse();
foreach ($documents_in_a_category as $document){
    var_dump($document->title);
}

Find the documents for a specific file

Here we set permission values for the current user, filter by storage path of the document, and then call the browse event:

<?php
// Get the controller
$controller = Koowa::getObject('com://site/docman.controller.document');
$user       = Koowa::getObject('user');
// Fetch documents in a category
$documents_for_a_file = $controller
    ->access($user->getRoles()) // Permissions
    ->current_user($user->getId())
    ->enabled(1)
    ->status('published') 
    ->storage_path('path/to/file') // Enter the file path here
    ->browse();
foreach ($documents_for_a_file as $document){
    var_dump($document->title);
}