PHP Samples

Download sdk4php

The sdk4php sample below includes the most common methods used by users when integrating their PHP applications.

The OpenKM has more than 400 methods in the API, the samples below cover the most common methods used when integrating PHP applications with OpenKM.

If you have issues trying to use methods not covered in this sample, talk with the OpenKM support service.

 

ProfessionalPHP version StatusDownload 

Version 8.1.4 and upper.

 7.x Active  sdk4php-3.0.2.zip 

Preview sample

The sample below describes how to integrate OpenKM preview feature in your PHP application.

ProfessionalPHP version StatusDownload 

Version 8.1.4 and upper.

7.x

Active

okmPreview-3.0.1.zip

Login

First, you must create the webservice object:

$this->ws = OKMWebServicesFactory::build(self::HOST);

Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:

$this->ws->login(self::USER, self::PASSWORD);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

At this point you can use all the Folder methods from "folder" class as is shown below:

$folder = $this->ws->folder->getFolderProperties("4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5");
<?php
include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $folder = $this->ws->folder->getFolderProperties("4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5");
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$$test->test();
?>

Document samples

createDocument

Description:

MethodReturn valuesDescription

createDocument($uuid, $name, $content)

Document

Creates a new document and returns as a result an object Document with the properties of the created document.

Parameters:
$$uuid string type is the destination uuid of the Folder or Record

$name string type is the name document.

$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 Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $fileName = dirname(__FILE__) . '/files/test.pdf';
            $document = $this->ws->document->createDocument('f93ac8df-e83b-487f-9a14-0af9e910a818', 'test.pdf', file_get_contents($fileName));
            var_dump($document);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

deleteDocument

Description:

MethodReturn valuesDescription

deleteDocument($uuid)

void

Deletes a document.

Parameters:
$uuid string type is the uuid of the Document

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 Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->document->deleteDocument('5b37c508-b2be-4429-ba5e-acc96089c6a9');
            echo 'deleted';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getDocumentProperties

Description:

MethodReturn valuesDescription

getDocumentProperties($uuid)

Document

Returns the document properties.

Parameters:
$uuid
string type is the uuid of the Document

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $document = $this->ws->document->getDocumentProperties('7e12a9ff-95b2-4945-bf5f-1bb709d89c14');
            var_dump($document);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getContent

Description:

MethodReturn valuesDescription

getContent($uuid)

string

Retrieves a document content - binary data - of the actual document version.

Parameters:
$uuid
string type is the uuid of the Document

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        $method = 1;
        $this->ws->login(self::USER, self::PASSWORD);
        $content = $this->ws->document->getContent('b02877cc-bc71-4be9-9bfb-2e50b1732fd3');
        switch ($method) {
            case 1:
                $file = fopen(dirname(__FILE__) . '/files/logo_download.png', 'w+');
                fwrite($file, $content);
                fclose($file);
                echo 'download correct';
                break;
            case 2:
                ob_clean();
                $document = $this->ws->document->getDocumentProperties('b02877cc-bc71-4be9-9bfb-2e50b1732fd3');
                $name = PathUtils::getName($document->getPath());
                header("Cache-Control:  maxage=1");
                header("Pragma: public");
                header("Content-Type: " . $document->getMimeType());
                header('Content-Disposition: attachment; filename="' . $name . '"');
                header("Content-Length: " . strlen($content));
                echo $content;
                break;
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getDocumentChildren

Description:

MethodReturn valuesDescription

getDocumentChildren($uuid)

array

Returns a list of all documents which their parent is fldId.

Parameters:
$fldId
string type is the uuid or path of the Document or a record node.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $documents = $this->ws->document->getDocumentChildren('f93ac8df-e83b-487f-9a14-0af9e910a818');
            foreach ($documents as $document) {
                var_dump($document);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

moveDocument

Description:

MethodReturn valuesDescription

moveDocument($uuid, $dstId)

void

Move a document into some folder or record.

Parameters:
$uuid
string type is the uuid of the Document

$dstId string type is the uuid of the Folder or Record

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->document->moveDocument('b02877cc-bc71-4be9-9bfb-2e50b1732fd3', '55102c84-e4f5-4cbc-a3d1-cf1896367752');
            echo 'moveDocument';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

copyDocument

Description:

MethodReturn valuesDescription

copyDocument($uuid, $dstId, $newName)

void

Copies a document to a folder or record.

Parameters:
$uuid
string type is the uuid of the Document

$dstId string type is the uuid 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 Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $document = $this->ws->document->copyDocument('b02877cc-bc71-4be9-9bfb-2e50b1732fd3', '55102c84-e4f5-4cbc-a3d1-cf1896367752', 'new_logo.png');
            var_dump($document);
            echo 'copyDocument';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

Folder sample

createFolder

Description:

MethodReturn valuesDescription

createFolder($uuid, $name)

Folder

Creates a new folder and return it as a result of an object Folder.

Parameters:
$uuid string type is the destination uuid of the Folder or Record

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $folder = $this->ws->folder->createFolder('f93ac8df-e83b-487f-9a14-0af9e910a818', 'test');
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getFolderProperties

Description:

MethodReturn valuesDescription

getFolderProperties($uuid)

Folder

Returns the folder properties.

Parameters:
$uuid string type is the uuid of the Folder

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    // const HOST = "http://localhost:8080/openkm/";
    const HOST = "http://192.168.1.11:8888/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $folder = $this->ws->folder->getFolderProperties("4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5");
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

deleteFolder

Description:

MethodReturn valuesDescription

deleteFolder($uuid)

void

Deletes a folder.

Parameters:
$uuid
string type is the uuid of the Folder

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    // const HOST = "http://localhost:8080/openkm/";
    const HOST = "http://192.168.1.11:8888/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->folder->deleteFolder("56c4d33b-daad-4389-bfdc-ee8dd5273899");
            echo 'delete folder';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

renameFolder

Description:

MethodReturn valuesDescription

renameFolder($uuid, $newName)

void

Renames a folder.

Parameters:
$uuid
string type is the uuid of the Folder

$newName string type is the new name for the Folder

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            // Exists folder /okm:root/sdk/test
            $folder = $this->ws->folder->renameFolder("0b89e4ca-0019-4837-82a4-05bc05d83353", "renamedFolder");
            // Folder has renamed to /okm:root/sdk/renamedFolder
            echo 'rename Folder';
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

moveFolder

Description:

MethodReturn valuesDescription

moveFolder($uuid, $dstId)

void

Moves a folder into other folder or record.

Parameters:
$uuid
string type is the uuid of the Folder

$dstId string type is the uuid of the Folder or record

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            // Exists folder /okm:root/sdk/test
            $this->ws->folder->moveFolder("0b89e4ca-0019-4837-82a4-05bc05d83353", "55102c84-e4f5-4cbc-a3d1-cf1896367752");
            // Folder has moved to /okm:root/move/test
            echo 'move Folder';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getFolderChildren

Description:

MethodReturn valuesDescription

getFolderChildren($uuid)

array

Returns an array of all folders which their parent is fldId.

Parameters:
$uuid
string type is the uuid of the Folder or Record node

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $folders = $this->ws->folder->getFolderChildren('f93ac8df-e83b-487f-9a14-0af9e910a818');
            foreach ($folders as $folder) {
                var_dump($folder);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

copyFolder

Description:

MethodReturn valuesDescription

copyFolder($uuid, $dstId, $newName)

void

Copies a folder into other folder or record.

Parameters:
$uuid
string type is the uuid of the Folder

$dstId string type is the uuid of the Folder or Record

$newName string type is the new name for the Folder. Value is null, folder will preservates the same name.

Only the security grants are copied to the destination, the metadata, keywords, etc. of the folder are not copied.

See "extendedFolderCopy" method for this feature.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->folder->copyFolder('4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5', '55102c84-e4f5-4cbc-a3d1-cf1896367752', "new_name");
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

extendedFolderCopy

Description:

MethodReturn valuesDescription

extendedFolderCopy($uuid, $dstId, $categories, $keywords, $propertyGroups, $notes, $security)

void

Copies a folder with associated data into other folder or record.

Parameters:
$uuid
string type is the uuid of the Folder

$dstId string type is the uuid of the Folder or Record

$categories boolean type

$keywords boolean type

$propertyGroups boolean type

$notes boolean type

$security boolean type

By default only the binary data and the security grants, the metadata, keywords, etc. of the folder are not copied.

Additionally:

  • When category parameter is true the original values of the categories will be copied.
  • When keywords parameter is true the original values of the keywords will be copied.
  • When propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When notes parameter is true the original values of the notes will be copied.
  • When security parameter is true the original values of the security will be copied.

 

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $folder = $this->ws->folder->extendedFolderCopy('4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5', '55102c84-e4f5-4cbc-a3d1-cf1896367752', 'new name extend copy', true, true, true, true, true);
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getContentInfo

Description:

MethodReturn valuesDescription

getContentInfo($uuid)

ContentInfo

Return and object ContentInfo with information about folder.

Parameters:
$uuid
string type is the uuid or path of the Folder.

The ContentInfo object retrives information about:

  • The number of folders into.
  • The number of documents into.
  • The number of records into.
  • The number of mails into.
  • The size in bytes of all objects into the folder.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            var_dump($this->ws->folder->getContentInfo('4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5'));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

purgeFolder

Description:

MethodReturn valuesDescription

purgeFolder($uuid)

void

Folder is definitely removed from repository.

Parameters:
$uuid
string type is the uuid or path of the Folder.

Usually you will purge folders into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any folder from the whole repository.

When a folder is purged only will be able to be restored from a previously repository backup. The purge action remove the folder definitely from the repository.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->folder->purgeFolder('d1faccb3-9e64-4d2d-865f-1c057e3a279b');
            echo 'purge folder';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

setStyle

Description:

MethodReturn valuesDescription

setStyle($uuid, $styleId)

void

Set the folder style.

Parameters:
$uuid
string type is the uuid or path of the Folder.

$styleId long type is the id of the style.

More information at: Folder style.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->folder->setStyle('0b89e4ca-0019-4837-82a4-05bc05d83353', 1);
            echo 'set style';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

createMissingFolders

Description:

MethodReturn valuesDescription

createMissingFolders($fldPath)

void

Create missing folders.

Parameters:
$fldPath
string type is the path of the Folder.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->folder->createMissingFolders("/okm:root/sdk/missingfld2/missingfld3");
            var_dump('create missing folders');
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

createFolderFromTemplate

Description:

MethodReturn valuesDescription

createFolderFromTemplate($uuid, $dstPath, $language, $categories,
            $keywords, $propertyGroups, $notes, $properties)

Folder

Creates a new folder from the template and returns an object Folder.

The $uuid parameter is the UUID value of the template file.

The $dstPath value is the folder destination path.

The $language paramater is optional.

When the template uses metadata groups to fill in fields, then these values are mandatory and must be set into properties parameter.

Additional:

  • When category parameter is true the original values of the categories will be copied.
  • When keywords parameter is true the original values of the keywords will be copied.
  • When property Groups parameter is true the original values of the metadata groups will be copied.
  • When notes parameter is true the original values of the notes will be copied.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    // const HOST = "http://localhost:8080/openkm/";
    const HOST = "http://192.168.1.11:8888/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);

            $properties = [];
            $properties["okp:consulting.name"] = "update value";
            $properties["okp:consulting.important"] = "false";

            $folder = $this->ws->folder->createFolderFromTemplate('47c70047-2924-483c-bc42-23d0cbef6b17', '/okm:root/sdk/foldertemplate', 'es', true, true, true, true, $properties);
            var_dump($folder);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

PropertyGroup samples

addPropertyGroup

Description:

MethodReturn valuesDescription

addPropertyGroup($uuid, $grpName, $properties)

void

Adds an empty metadata group to a node.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $properties = [];
            $properties["okp:consulting.name"] = "new value";
            $properties["okp:consulting.important"] = "true";
            $this->ws->propertyGroup->addPropertyGroup('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting', $properties);
            echo 'Add Group';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

removePropertyGroup

Description:

MethodReturn valuesDescription

removePropertyGroup($uuid, $grpName)

void

Removes a metadata group of a node.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->propertyGroup->removePropertyGroup('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting');
            echo 'Remove Group';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getPropertyGroups

Description:

MethodReturn valuesDescription

getPropertyGroups($uuid)

array

Retrieves a list of metadata groups assigned to a node.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $propertyGroups = $this->ws->propertyGroup->getPropertyGroups('7e12a9ff-95b2-4945-bf5f-1bb709d89c14');
            foreach ($propertyGroups as $propertyGroup) {
                var_dump($propertyGroup);
                echo '<br>';
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getAllPropertyGroups

Description:

MethodReturn valuesDescription

getAllPropertyGroups()

array

Retrieves a list of all metadata groups set into the application.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $propertyGroups = $this->ws->propertyGroup->getAllPropertyGroups();
            foreach ($propertyGroups as $propertyGroup) {
                var_dump($propertyGroup);
                echo '<br>';
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getPropertyGroupForm

Description:

MethodReturn valuesDescription

getPropertyGroupForm($grpName)

array

Retrieves a list of all metadata group elements definition.

Parameters:

$grpName string type is the grpName should be a valid Metadata group name.

 

The method is usually used to display empty form elements for creating new metadata values.

 

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExamplePropertyGroup {

    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 testGetPropertyGroupForm() {
        try {
            $formElements = $this->ws->getPropertyGroupForm('okg:consulting');
            foreach ($formElements as $formElement) {
               var_dump($formElement);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
}

$openkm = new OpenKM(); //autoload
$examplePropertyGroup = new ExamplePropertyGroup();
$examplePropertyGroup->testGetPropertyGroupPropertiesSimple();
?>

getPropertyGroupFormByNode

Description:

MethodReturn valuesDescription

getPropertyGroupFormByNode($uuid, $grpName)

array

Retrieves a list of all metadata group elements definition by node

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

The method is usually used to display empty form elements for creating new metadata values.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $formElements = $this->ws->propertyGroup->getPropertyGroupFormByNode('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting');
            foreach ($formElements as $formElement) {
                var_dump($formElement);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

setPropertyGroupProperties

Description:

MethodReturn valuesDescription

setPropertyGroupProperties($uuid, $grpName, $properties)

void

Changes the metadata group values of a node.

Parameters:

$uuid string type is the uuid or path of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

$properties array type is an array

Before changing metadata, you should have the group added in the node ( see addGroup method ) otherwise will be raised and error.

Is not mandatory set into properties parameter all fields values, is enough with the fields you wish to change its values.

The sample below is based on this Metadata group definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.0//EN"
                                 "http://www.openkm.com/dtd/property-groups-2.0.dtd">
<property-groups>
  <property-group label="Consulting" name="okg:consulting">
    <input label="Name" type="text" name="okp:consulting.name"/>
    <input label="Date" type="date" name="okp:consulting.date" />
    <checkbox label="Important" name="okp:consulting.important"/>
    <textarea label="Comment" name="okp:consulting.comment"/>
  </property-group>
</property-groups>

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $properties = [];
            $properties["okp:consulting.name"] = "update value";
            $properties["okp:consulting.important"] = "false";

            $this->ws->login(self::USER, self::PASSWORD);
            $this->ws->propertyGroup->setPropertyGroupProperties('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting', $properties);
            echo 'updated';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

hasPropertyGroup

Description:

MethodReturn valuesDescription

hasPropertyGroup($uuid, $grpName)

bool

Returns a boolean that indicate if the node has or not a metadata group.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            echo 'Have metadata group: ' . $this->ws->propertyGroup->hasPropertyGroup('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting');
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getRegisteredPropertyGroupDefinition

Description:

MethodReturn valuesDescription

getRegisteredPropertyGroupDefinition()

string

Return the XML Metada groups definition.

The method only can be executed by super user grants ( ROLE_ADMIN member user).

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            var_dump($this->ws->propertyGroup->getRegisteredPropertyGroupDefinition());
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getPropertyGroupSuggestions

Description:

MethodReturn valuesDescription

getPropertyGroupSuggestions($uuid, $grpName, $propName)

array

Retrieves a list of a suggested metadata field values.

 Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

$propName string type is the propName parameter should be a Metadata Select field type.

The propName parameter should be a Metadata Select field type.

The sample below is based on this Metadata group definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.0//EN"
                                 "http://www.openkm.com/dtd/property-groups-2.0.dtd">
<property-groups>
  <property-group label="Technology" name="okg:technology">
    <select label="Type" name="okp:technology.type" type="multiple">
      <option label="Alfa" value="t1"/>
      <option label="Beta" value="t2" />
      <option label="Omega" value="t3" />
    </select>
    <select label="Language" name="okp:technology.language" type="simple">
      <option label="Java" value="java"/>
      <option label="Python" value="python"/>
      <option label="PHP" value="php" />
    </select>
    <input label="Comment" name="okp:technology.comment"/>
    <textarea label="Description" name="okp:technology.description"/>
    <input label="Link" type="link" name="okp:technology.link"/>
  </property-group>
</property-groups>

 

 

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $suggestions = $this->ws->propertyGroup->getPropertyGroupSuggestions('055b5206-35d0-4351-ba92-c304bbba7ddf', 'okg:technology', 'okp:technology.priority');
            foreach ($suggestions as $suggestion) {
                var_dump($suggestion);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

registerPropertyGroupDefinition

Description:

MethodReturn valuesDescription

registerPropertyGroupDefinition($content, $name)

void

Sets the XML Metada groups definition into the repository.

 Parameters:

$content string type is recommend using file_get_contents — Reads entire file into a string

$name string type is the name propertygroup

The method only can be executed by super user grants ( ROLE_ADMIN member user).

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $fileName = dirname(__FILE__) . '/propertygroup/propertyGroups.xml';
            $this->ws->propertyGroup->registerPropertyGroupDefinition(file_get_contents($fileName), 'sdk4php');
            var_dump('Register Definition correct');
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getPropertyGroupProperties

Description:

MethodReturn valuesDescription

getPropertyGroupProperties($uuid, $grpName)

array

Retrieves a list of all metadata group elements and its values of a node.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

The method is usually used to display form elements with its values to be shown or changed by user.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $properties = $this->ws->propertyGroup->getPropertyGroupProperties('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting');
            foreach ($properties as $key => $value) {
                echo 'key: ' . $key . ' value: ' . $value;
                echo '<br>';
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

getPropertyGroupPropertiesByVersion

Description:

MethodReturn valuesDescription

getPropertyGroupPropertiesByVersion($uuid, $grpName, $versionName)

array

Retrieves a list of all metadata group elements and its values of a node.

Parameters:

$uuid string type is the uuid of the document, folder, mail or record.

$grpName string type is the grpName should be a valid Metadata group name.

$versionName string type is the version of the document, folder, mail or record.

The method is usually used to display form elements with its values to be shown or changed by user.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $properties = $this->ws->propertyGroup->getPropertyGroupPropertiesByVersion('7e12a9ff-95b2-4945-bf5f-1bb709d89c14', 'okg:consulting', '1.3');
            foreach ($properties as $key => $value) {
                echo 'key: ' . $key . ' value: ' . $value;
                echo '<br>';
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

Search samples

find

Description:

MethodReturn valuesDescription

find(QueryParams $queryParams, $propertiesPlugin)

array

Returns a list of QueryResults filtered by the values of the queryParams parameter.

Parameters:
$queryParams
QueryParams type

$propertiesPlugin string type, must be the canonical class name of the class which implements the NodeProperties interface.

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $queryParams = new QueryParams();
            $queryParams->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
            $queryParams->setFolder("f93ac8df-e83b-487f-9a14-0af9e910a818");
            $queryParams->setFolderRecursive(true);
            $queryParams->setLastModifiedFrom(20150628000000);
            $queryParams->setLastModifiedTo(date('Ymdhis'));
            $queryResults = $this->ws->search->find($queryParams, null);
            foreach ($queryResults as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>

findPaginated

Description:

MethodReturn valuesDescription

findPaginated(QueryParams $queryParams, $offset, $limit, $propertiesPlugin)

ResultSet

Returns a list of paginated results filtered by the values of the queryParams parameter.

Parameters:
$queryParams
QueryParams type

$offset int type

$limit int type

$propertiesPlugin string type, must be the canonical class name of the class which implements the NodeProperties interface.

The parameter "limit" and "offset" allow you to retrieve just a portion of the results of a query.

  • The parameter "limit" is used to limit the number of results returned.
  • The parameter "offset" says to skip that many results before the beginning to return results.

For example if your query have 1000 results, but you only want to return the first 10, you should use these values:

  • limit=10
  • offset=0

Now suppose you want to show the results from 11-20, you should use these values:

  • limit=10
  • offset=10

Retrieving entire Objects ( Document, Folder, Record, Mail ) from REST can take a lot of time - marshalling and unmarshalling process - while you are only interesting on using only few Objects variables. If its your case you can use NodeProperties classes for retrieving the Object variables what you really need.

Example:

<?php

include '../src/openkm/OpenKM.php';

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

    public function __construct() {
        $this->ws = OKMWebServicesFactory::build(self::HOST);
    }

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $queryParams = new QueryParams();
            $queryParams->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
            $queryParams->setFolder("f93ac8df-e83b-487f-9a14-0af9e910a818");
            $queryParams->setFolderRecursive(true);
            $queryParams->setLastModifiedFrom(20150628000000);
            $queryParams->setLastModifiedTo(date('Ymdhis'));
            $resultSet = $this->ws->search->findPaginated($queryParams, 0, 10, null);
            echo "Total results:" . $resultSet->getTotal();
            foreach ($resultSet->getResults() as $queryResult) {
                var_dump($queryResult);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>