Documents

Create document

<?php$document_details=array('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=KObjectManager::getInstance()->getObject('com://site/docman.controller.document')->add($document_details);

Edit 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=array('title'=>'new title','storage_path'=>'new/path/to/the/file.txt'// part of the path that comes after joomlatools-files/docman-files/
);$result=KObjectManager::getInstance()->getObject('com://site/docman.controller.document')->id($document_id)->edit($document_details);

Delete document

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

Fetch documents

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=KObjectManager::getInstance()->getObject('com://site/docman.controller.document');$user=KObjectManager::getInstance()->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_categoryas$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:

Fetch categories

For fetching categories, we set permission values for the current user, limit the results to 50 categories, and call the browse event.

<?php// Get the controller
$controller=KObjectManager::getInstance()->getObject('com://site/docman.controller.category');$user=KObjectManager::getInstance()->getObject('user');// Fetch all categories
$categories=$controller->access($user->getRoles())// Permissions
->current_user($user->getId())->enabled(1)->limit(50)// Limiting to 50 categories
->offset(0)// You can set this to 50 in the next call to paginate results
->browse();foreach($categoriesas$category){var_dump($category->title);}

A complete script

Below script boots Joomla and Joomlatools framework, and then runs your custom code. Save its contents into a PHP file and run it from the browser or the command line:

<?phpdefine('_JEXEC',1);define('JPATH_BASE',__DIR__.'/administrator');if(file_exists(JPATH_BASE.'/includes/defines.php')){include_onceJPATH_BASE.'/includes/defines.php';}require_onceJPATH_BASE.'/includes/framework.php';// Instantiate the application.
$app=JFactory::getApplication('administrator');// Make sure that a user with add permissions is logged in.
$app->login(array('username'=>'admin',// Change the username here
'password'=>'admin'// Change the password here
));// Boot Joomlatools Framework
JPluginHelper::importPlugin('system','joomlatools');$document_data=array('title'=>'title',// The document title.
'docman_category_id'=>1,// The category ID.
'storage_path'=>'path/to/the/file.txt'// part of the path that comes after joomlatools-files/docman-files/
);$result=KObjectManager::getInstance()->getObject('com://admin/docman.controller.document')->add($document_data);

Need Help?

Let our developers personally assist you. You can ask development related questions in our Support Center. Only for Business or Agency subscribers.