Document samples
Basics
On most methods you'll see parameter named "docId". The value of this parameter can be a valid document UUID or path.
Example of docId:
- Using UUID -> "68a27519-c9cc-4490-b281-19ff9f19318b";
- Using path -> "/okm:root/SDK4PHP/logo.png"
Methods
createDocument
Description:
Method | Return values | Description |
---|---|---|
createDocument(Document $document, $content) |
Document |
Creates a new document and returns as a result an object Document with the properties of the created document. |
Parameters: $content string type is recommend using file_get_contents — Reads entire file into a string The variable path into the parameter doc, must be initializated. It indicates where the document must be stored into OpenKM.
The other variables of Document ( doc ) will not take any effect on document creation. We suggest use the method below createDocumentSimple rather this one. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateDocument() {
try {
$fileName = dirname(__FILE__) . '/files/logo.png';
$document = new \openkm\bean\Document();
$document->setPath('/okm:root/SDK4PHP/logo.png');
$doc = $this->ws->createDocument($document, file_get_contents($fileName));
var_dump($doc);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCreateDocument();
?>
createDocumentSimple
Description:
Method | Return values | Description |
---|---|---|
createDocumentSimple($docPath, $content) |
Document |
Creates a new document and returns as a result an object Document with the properties of the created document. |
Parameters: $content string type is recommend using file_get_contents — Reads entire file into a string |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateDocumentSimple() {
try {
$fileName = dirname(__FILE__) . '/files/logo.png';
$docPath = '/okm:root/SDK4PHP/logo.png';
$document = $this->ws->createDocumentSimple($docPath, file_get_contents($fileName));
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCreateDocumentSimple();
?>
deleteDocument
Description:
Method | Return values | Description |
---|---|---|
deleteDocument($docId) |
void |
Deletes a document. |
Parameters: When a document is deleted, it is automatically moved to /okm:trash/userId folder. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testDeleteDocument(){
try {
$this->ws->deleteDocument('/okm:root/SDK4PHP/logo.png');
echo 'deleted';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testDeleteDocument();
?>
getDocumentProperties
Description:
Method | Return values | Description |
---|---|---|
getDocumentProperties($docId) |
Document |
Returns the document properties. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetDocumentProperties() {
try {
$document = $this->ws->getDocumentProperties('/okm:root/SDK4PHP/logo.png');
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetDocumentProperties();
?>
getContent
Description:
Method | Return values | Description |
---|---|---|
getContent($docId) |
string |
Retrieves a document content - binary data - of the actual document version. |
Parameters: $docId string type is the uuid or path of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetContent($method) {
$content = $this->ws->getContent('/okm:root/SDK4PHP/logo.png');
switch ($method) {
case 1:
$file = fopen(dirname(__FILE__) . '/files/logo_download.png', 'w+');
fwrite($file, $content);
fclose($file);
echo 'download correct';
break;
case 2:
$document = $this->ws->getDocumentProperties('/okm:root/SDK4PHP/logo.png');
header('Expires', 'Sat, 6 May 1971 12:00:00 GMT');
header('Cache-Control', 'max-age=0, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
header('Content-Type: ' . $document->getMimeType());
header('Content-Disposition: attachment; filename="' . substr($document->getPath(), strrpos($document->getPath(), '/') + 1) . '"');
echo $content;
break;
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetContent(2);
?>
getContentByVersion
Description:
Method | Return values | Description |
---|---|---|
getContentByVersion($docId, $versionId) |
string |
Retrieves a document content ( binary data ) of some specific document version. |
Parameters: $versionId string type is the uuid or path of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetContentByVersion($method) {
$content = $this->ws->getContentByVersion('/okm:root/SDK4PHP/logo.png',1.1);
switch ($method) {
case 1:
$file = fopen(dirname(__FILE__) . '/files/logo_download_version.png', 'w+');
fwrite($file, $content);
fclose($file);
echo 'download correct';
break;
case 2:
$document = $this->ws->getDocumentProperties('/okm:root/SDK4PHP/logo.png');
header('Expires', 'Sat, 6 May 1971 12:00:00 GMT');
header('Cache-Control', 'max-age=0, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
header('Content-Type: ' . $document->getMimeType());
header('Content-Disposition: attachment; filename="' . substr($document->getPath(), strrpos($document->getPath(), '/') + 1) . '"');
echo $content;
break;
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetContentByVersion(1);
?>
getExtractedText
Description:
Method | Return values | Description |
---|---|---|
getExtractedText($docId) |
string |
Returns a String with the extracted text by text extractor process. |
Parameters: When a document is uploaded into OpenKM goes into text extraction queue. There's a crontab tab that periodically process this queue and extract document contents. Unfortunately there is not a direct way to know if a document has been processed or not from the API, because this information is only stored at the database level. Although this restriction, from API - only administrators users - can perform database queries to retrieve this information. Check Repository samples accessing database level. More information at Statistics. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\QueryParams;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetExtractedText(){
try {
$text = $this->ws->getExtractedText('/okm:root/SDK4PHP/document.odt');
var_dump($text);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetExtractedText();
?>
getThumbnail
Description:
Method | Return values | Description |
---|---|---|
getThumbnail($docId, ThumbnailType $type) |
string |
Returns thumbnail image data. |
Parameters: $type string type Available types:
Each thumbnail type has its own image dimensions. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetThumbnail($method) {
try {
$content = $this->ws->getThumbnail('/okm:root/SDK4PHP/document.odt', \openkm\bean\ThumbnailType::THUMBNAIL_LIGHTBOX);
switch ($method) {
case 1:
$file = fopen(dirname(__FILE__) . '/files/thumbnail.png', 'w+');
fwrite($file, $content);
fclose($file);
echo 'download correct';
break;
case 2:
header('Expires', 'Sat, 6 May 1971 12:00:00 GMT');
header('Cache-Control', 'max-age=0, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
header('Content-Type: ' . \openkm\util\MimeTypeConfig::MIME_PNG);
header('Content-Disposition: attachment; filename="thumbnail.png"');
echo $content;
break;
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetThumbnail(1);
?>
getDocumentChildren
Description:
Method | Return values | Description |
---|---|---|
getDocumentChildren($fldId) |
array |
Returns a list of all documents which their parent is fldId. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetDocumentChildren(){
try {
$documents = $this->ws->getDocumentChildren('/okm:root');
foreach ($documents as $document) {
var_dump($document);
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetDocumentChildren();
?>
renameDocument
Description:
Method | Return values | Description |
---|---|---|
renameDocument($docId, $newName) |
Document |
Changes the name of a document and returns the Document |
Parameters: $newName string type is the new name for the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testRenameDocument() {
try {
$document = $this->ws->renameDocument('604e17e8-3285-4e8a-910c-c99ee4e44262', 'logo_rename.png');
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testRenameDocument();
?>
setProperties
Description:
Method | Return values | Description |
---|---|---|
setProperties(Document $doc) |
void |
Change some document properties. |
Variables allowed to be changed:
The parameter Language must be ISO 691-1 compliant. More information at https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes. Only not null and not empty variables will be take on consideration. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSetProperties(){
try {
$document = $this->ws->getDocumentProperties('604e17e8-3285-4e8a-910c-c99ee4e44262');
$document->setTitle('Logo');
$document->setDescription('some description');
$document->setLanguage('es');
//Keywords
$keywords = array();
$keywords[] = 'test';
$document->setKeywords($keywords);
//Categories
$categories = array();
$category = $this->ws->getFolderProperties('/okm:categories/test');
$categories[] = $category;
$document->setCategories($categories);
$this->ws->setProperties($document);
echo 'updated';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testSetProperties();
?>
setLanguage
Description:
Method | Return values | Description |
---|---|---|
setLanguage($docId, $lang) |
void |
Sets document language. |
Parameters: $lang string type is the lang must be ISO 691-1 compliant. More information at https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSetLanguage() {
try {
$this->ws->setLanguage('/okm:root/SDK4PHP/document.odt', 'es');
echo 'updated';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testSetLanguage();
?>
setDocumentTitle
Description:
Method | Return values | Description |
---|---|---|
setDocumentTitle($docId, $title) |
void |
Set document title. |
Parameters: $title string type is the title of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testSetDocumentTitle() {
try {
$this->ws->setDocumentTitle('/okm:root/SDK4PHP/document.odt', 'Some title here');
echo 'updated';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testSetDocumentTitle();
?>
createFromTemplate
checkout
Description:
Method | Return values | Description |
---|---|---|
checkout($docId) |
void |
Mark the document for edition. |
Parameters: Only one user can modify a document at same time. Before starting edition you must perform a checkout action that locks the edition process for other users and allows it only to the user who has executed the action. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCheckout() {
try {
$this->ws->checkout('/okm:root/SDK4PHP/logo.png');
// At this point the document is locked for other users except for the user who executed the action
echo 'correct';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCheckout();
?>
cancelCheckout
Description:
Method | Return values | Description |
---|---|---|
cancelCheckout($docId) |
void |
Cancels a document edition. |
Parameters: $docId string type is the uuid or path of the Document This action can only be done by the user who previously executed the checkout action. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCancelCheckout() {
try {
// At this point the document is locked for other users except for the user who executed the action
$this->ws->cancelCheckout('/okm:root/SDK4PHP/logo.png');
// At this point other users are allowed to execute a checkout and modify the document
echo 'correct';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCancelCheckout();
?>
forceCancelCheckout
Description:
Method | Return values | Description |
---|---|---|
forceCancelCheckout($docId) |
void |
Cancels a document edition. |
Parameters: This method allows to cancel edition on any document. It is not mandatory that this action is executed by the same user who previously executed the checkout action. This action can only be done by a super user ( user with ROLE_ADMIN ). |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testForceCancelCheckout() {
try {
// At this point the document is locked for other users except for the user who executed the action
$this->ws->forceCancelCheckout('/okm:root/SDK4PHP/logo.png');
// At this point other users are allowed to execute a checkout and modify the document
echo 'correct';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testForceCancelCheckout();
?>
isCheckedOut
Description:
Method | Return values | Description |
---|---|---|
isCheckedOut($docId) |
bool |
Returns a boolean that indicate if the document is on edition or not. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testIsCheckedOut() {
try {
echo "Is the document checkout:" . $this->ws->isCheckedOut('/okm:root/SDK4PHP/logo.png');
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testIsCheckedOut();
?>
checkin
Description:
Method | Return values | Description |
---|---|---|
checkin($docId, $content, $comment) |
Version |
Updates a document with new version and return an object with new Version values. |
Parameters: $content string type is recommend using file_get_contents — Reads entire file into a string $comment string type is the comment for the new version the document Only the user who started the edition - checkout - is allowed to update the document. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCheckin() {
try {
$fileName = dirname(__FILE__) . '/files/logo.png';
$version = $this->ws->checkin('/okm:root/SDK4PHP/logo.png', file_get_contents($fileName),"optional some comment");
var_dump($version);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCheckin();
?>
getVersionHistory
Description:
Method | Return values | Description |
---|---|---|
getVersionHistory($docId) |
array |
Returns a list of all document versions. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
//ini_set('display_errors', true);
//error_reporting(E_ALL);
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetVersionHistory() {
try {
$versions = $this->ws->getVersionHistory('/okm:root/SDK4PHP/logo.png');
foreach ($versions as $version) {
var_dump($version);
}
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetVersionHistory();
?>
lock
Description:
Method | Return values | Description |
---|---|---|
lock($docId) |
LockInfo |
Locks a document and returns an object with the Lock information. |
Parameters: $docId string type is the uuid or path of the Document Only the user who locked the document is allowed to unlock. A locked document can not be modified by other users. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testLock() {
try {
$lockInfo = $this->ws->lock('/okm:root/SDK4PHP/logo.png');
var_dump($lockInfo);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testLock();
?>
unlock
Description:
Method | Return values | Description |
---|---|---|
unlock($docId) |
void |
Unlocks a locked document. |
Parameters: $docId string type is the uuid or path of the Document Only the user who locked the document is allowed to unlock. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testUnlock() {
try {
$this->ws->unlock('/okm:root/SDK4PHP/logo.png');
echo 'unlock';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testUnlock();
?>
forceUnlock
Description:
Method | Return values | Description |
---|---|---|
forceUnlock($docId) |
void |
Unlocks a locked document. |
Parameters: This method allows to unlcok any locked document. It is not mandatory execute this action by the same user who previously executed the checkout lock action. This action can only be done by a super user ( user with ROLE_ADMIN ). |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testForceUnlock() {
try {
$this->ws->forceUnlock('/okm:root/SDK4PHP/logo.png');
echo 'forceUnlock';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testForceUnlock();
?>
isLocked
Description:
Method | Return values | Description |
---|---|---|
isLocked($docId) |
bool |
Returns a boolean that indicate if the document is locked or not. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testIsLocked() {
try {
echo "Is document locked:" . $this->ws->isLocked('/okm:root/SDK4PHP/logo.png');
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testIsLocked();
?>
getLockInfo
Description:
Method | Return values | Description |
---|---|---|
getLockInfo($docId) |
LockInfo |
Returns an object with the Lock information |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetLockInfo() {
try {
var_dump($this->ws->getLockInfo('/okm:root/SDK4PHP/logo.png'));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetLockInfo();
?>
purgeDocument
Description:
Method | Return values | Description |
---|---|---|
purgeDocument($docId) |
void |
Document is definitely removed from repository. |
Parameters: Usually you will purge documents into /okm:trash/userId - the personal trash user locations - but it is possible to directly purge any document from the whole repository. When a document is purged it will only be able to be restored from a previously repository backup. The purge action removes the document definitely from the repository. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testPurgeDocument() {
try {
$this->ws->purgeDocument('/okm:root/SDK4PHP/logo.png');
echo 'purgeDocument';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testPurgeDocument();
?>
moveDocument
Description:
Method | Return values | Description |
---|---|---|
moveDocument($docId, $dstId) |
void |
Move a document into some folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testMoveDocument() {
try {
$this->ws->moveDocument('/okm:root/SDK4PHP/logo.png','/okm:root/SDK4PHP/tmp');
echo 'moveDocument';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testMoveDocument();
?>
copyDocument
Description:
Method | Return values | Description |
---|---|---|
copyDocument($docId, $dstId, $newName) |
void |
Copies a document to a folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record $newName string type is the new name for the Document When parameter newName value is null, document will preservate the same name. Only the binary data and the security grants are copied to destionation, the metadata, keywords, etc. of the document are not copied. See "extendedDocumentCopy" method for this feature. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCopyDocument() {
try {
$this->ws->copyDocument('/okm:root/SDK4PHP/logo.png','/okm:root/SDK4PHP/tmp','new_logo.png');
echo 'copyDocument';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCopyDocument();
?>
restoreVersion
Description:
Method | Return values | Description |
---|---|---|
restoreVersion($docId, $versionId) |
void |
Promotes previous document's version to the actual version. |
Parameters: $versionId string type is the version of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testRestoreVersion() {
try {
$this->ws->restoreVersion('/okm:root/SDK4PHP/logo.png','1.1');
echo 'restoreVersion';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testRestoreVersion();
?>
purgeVersionHistory
Description:
Method | Return values | Description |
---|---|---|
purgeVersionHistory($docId) |
void |
Purges all documents version except the actual version. |
Parameters: This action compact the version history of a document. This action can not be reverted. |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testPurgeVersionHistory() {
try {
// Version history has version 1.3,1.2,1.1 and 1.0
$this->ws->purgeVersionHistory('/okm:root/SDK4PHP/logo.png');
// Version history has only version 1.3
echo 'purgeVersionHistory';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testPurgeVersionHistory();
?>
getVersionHistorySize
Description:
Method | Return values | Description |
---|---|---|
getVersionHistorySize($docId) |
int |
Returns the sum in bytes of all documents into documents history. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetVersionHistorySize() {
try {
$units = array("B", "KB", "MB", "GB", "TB", "PB", "EB");
$bytes = $this->ws->getVersionHistorySize('/okm:root/SDK4PHP/logo.png');
$value = "";
for ($i = 6; $i > 0; $i--) {
$step = pow(1024, $i);
if ($bytes > $step) {
$value = number_format($bytes / $step, 2) . ' ' . $units[$i];
}
if (empty($value)) {
$value = $bytes . ' ' . $units[0];
}
}
echo $value;
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetVersionHistorySize();
?>
isValidDocument
Description:
Method | Return values | Description |
---|---|---|
isValidDocument($docId) |
bool |
Returns a boolean that indicates if the node is a document or not. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testIsValidDocument() {
try {
// Return true
var_dump($this->ws->isValidDocument("/okm:root/SDK4PHP/logo.png"));
// Return false
var_dump($this->ws->isValidDocument('/okm:root'));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testIsValidDocument();
?>
getDocumentPath
Description:
Method | Return values | Description |
---|---|---|
getDocumentPath($uuid) |
string |
Converts a document UUID to a document path. |
Parameters: |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetDocumentPath() {
try {
var_dump($this->ws->getDocumentPath("8b559709-3c90-4c26-b181-5192a17362b2"));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetDocumentPath();
?>
getDetectedLanguages
Description:
Method | Return values | Description |
---|---|---|
getDetectedLanguages() |
array |
Return a list of available document languages what OpenKM can identify |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetDetectedLanguages() {
try {
var_dump($this->ws->getDetectedLanguages());
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetDetectedLanguages();
?>
extendedDocumentCopy
Description:
Method | Return values | Description |
---|---|---|
extendedDocumentCopy($docId, $dstId, $name, $categories, $keywords, |
void |
Copies a document with associated data into a folder or record. |
Parameters: $dstId string type is the uuid or path of the Folder or Record $name string type is the new name for the Document. Value is null, document will preservate the same name. $categories bool type $keywords bool type $propertyGroups bool type $notes bool type $wiki bool type By default only the binary data and the security grants, the metadata, keywords, etc. of the document are not copied. Additional:
|
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testExtendedDocumentCopy() {
try {
$this->ws->extendedDocumentCopy('/okm:root/SDK4PHP/logo.png', '/okm:root/SDK4PHP/tmp', '', true, true, true, true, true);
echo 'extendedDocumentCopy';
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testExtendedDocumentCopy();
?>
createFromTemplate
Description:
Method | Return values | Description |
---|---|---|
Document createFromTemplate($docId, $dstPath,$categories,$keywords, |
Document |
Creates a new document from template and returns an object Document. |
Parameters: $dstPath string type is the path of the Document $categories bool type $keywords bool type $propertyGroups bool type $notes bool type $wiki bool type $formElements array type is an array of the FormElement When template use metadata groups to fill fields into, then these values are mandatory and must be set into properties parameter. For more information about Templates and metadata take a look at Creating templates. Additional:
|
Example:
The example below is based on Creating PDF template sample.
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateFromTemplate() {
try {
$formElements = array();
$name = new \openkm\bean\form\Input();
$name->setName('okp:tpl.name');
$name->setValue('Some name');
$formElements[] = $name;
$birdDate = new \openkm\bean\form\Input();
$birdDate->setName('okp:tpl.bird_date');
// Value must be converted to String ISO 8601 compliant
$birdDate->setValue(date('Ymdhis'));
$formElements[] = $birdDate;
$language = new \openkm\bean\form\Select();
$language->setName('okp:tpl.language');
$options = array();
$option = new \openkm\bean\form\Option();
$option->setValue('php');
$option->setSelected(true);
$options[] = $option;
$language->setOptions($options);
$formElements[] = $language;
$document = $this->ws->createFromTemplate('/okm:templates/tpl.pdf', '/okm:root/SDK4PHP/test.pdf', false, false, true, false,false,$formElements);
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCreateFromTemplate();
?>
createFromTemplateSimple
Description:
Method | Return values | Description |
---|---|---|
Document createFromTemplateSimple($docId, $dstPath, $categories, |
Document |
Creates a new document from template and returns an object Document. |
Parameters: $dstPath string type is the path of the Document $categories bool type $keywords bool type $propertyGroups bool type $notes bool type $wiki bool type $properties array type is an array of the SimplePropertyGroup When template use metadata groups to fill fields into, then these values are mandatory and must be set into properties parameter. For more information about Templates and metadata take a look at Creating templates. Additional:
|
Example:
The example below is based on Creating PDF template sample.
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testCreateFromTemplateSimple() {
try {
$properties = array();
$name = new \openkm\bean\SimplePropertyGroup();
$name->setName('okp:tpl.name');
$name->setValue('Some name');
$properties[] = $name;
$birdDate = new \openkm\bean\SimplePropertyGroup();
$birdDate->setName('okp:tpl.bird_date');
// Value must be converted to String ISO 8601 compliant
$birdDate->setValue(date('Ymdhis'));
$properties[] = $birdDate;
$language = new \openkm\bean\SimplePropertyGroup();
$language->setName('okp:tpl.language');
$language->setValue('php');
$properties[] = $language;
$document = $this->ws->createFromTemplateSimple('/okm:templates/tpl.pdf', '/okm:root/SDK4PHP/test.pdf', false, false, true, false, false, $properties);
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testCreateFromTemplateSimple();
?>
updateFromTemplate
Description:
Method | Return values | Description |
---|---|---|
Document updateFromTemplate($docId, $dstId, $formElements) |
Document |
Update a document previously created from template and returns an object Document. |
Parameters: $dstId string type is the uuid or path of the Document $formElements array type is an array of the FormElement This method only has sense when template use metadata groups to fill fields into. For more information about Templates and metadata take a look at Creating templates. |
Example:
The example below is based on Creating PDF template sample.
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testUpdateFromTemplate() {
try {
$formElements = array();
$name = new \openkm\bean\form\Input();
$name->setName('okp:tpl.name');
$name->setValue('Update name');
$formElements[] = $name;
$birdDate = new \openkm\bean\form\Input();
$birdDate->setName('okp:tpl.bird_date');
// Value must be converted to String ISO 8601 compliant
$birdDate->setValue(date('Ymdhis'));
$formElements[] = $birdDate;
$language = new \openkm\bean\form\Select();
$language->setName('okp:tpl.language');
$options = array();
$option = new \openkm\bean\form\Option();
$option->setValue('go');
$option->setSelected(true);
$options[] = $option;
$language->setOptions($options);
$formElements[] = $language;
$document = $this->ws->updateFromTemplate('/okm:templates/tpl.pdf', '/okm:root/SDK4PHP/test.pdf', $formElements);
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testUpdateFromTemplate();
?>
updateFromTemplateSimple
Description:
Method | Return values | Description |
---|---|---|
updateFromTemplateSimple(String docId, String dstId, Map<String, String> properties) |
Document |
Update a document previously created from template and return an object Document. |
Parameters: $dstId string type is the uuid or path of the Document $properties array type is an array of the SimplePropertyGroup This method only has sense when template use metadata groups to fill fields into. For more information about Templates and metadata take a look at Creating templates. |
Example:
The example below is based on Creating PDF template sample.
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testUpdateFromTemplateSimple() {
try {
$properties = array();
$name = new \openkm\bean\SimplePropertyGroup();
$name->setName('okp:tpl.name');
$name->setValue('Update name');
$properties[] = $name;
$birdDate = new \openkm\bean\SimplePropertyGroup();
$birdDate->setName('okp:tpl.bird_date');
// Value must be converted to String ISO 8601 compliant
$birdDate->setValue(date('Ymdhis'));
$properties[] = $birdDate;
$language = new \openkm\bean\SimplePropertyGroup();
$language->setName('okp:tpl.language');
$language->setValue('go');
$properties[] = $language;
$document = $this->ws->updateFromTemplateSimple('/okm:templates/tpl.pdf', '/okm:root/SDK4PHP/test.pdf', $properties);
var_dump($document);
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testUpdateFromTemplateSimple();
?>
getAnnotations
Description:
Method | Return values | Description |
---|---|---|
getAnnotations($docId, $verName) |
string |
Return the document annotations of some document version. |
Parameters: $verName string type is the version name of the Document |
Example:
<?php
include '../src/openkm/OpenKM.php';
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
class ExampleDocument {
const HOST = "http://localhost:8080/OpenKM/";
const USER = "okmAdmin";
const PASSWORD = "admin";
private $ws;
public function __construct() {
$this->ws = OKMWebServicesFactory::build(self::HOST, self::USER, self::PASSWORD);
}
public function testGetAnnotations(){
try {
var_dump($this->ws->getAnnotations('e34af683-7a8f-447c-98fb-8417b399f8d5', '1.0'));
} catch (Exception $e) {
var_dump($e);
}
}
}
$openkm = new OpenKM(); //autoload
$exampleDocument = new ExampleDocument();
$exampleDocument->testGetAnnotations();
?>