• SDK for PHP - how to return only specify value in the object/array instead of a bunch of information?

  • Do you want to create a native client or integrate with third party applications: webservices are the solution.
Do you want to create a native client or integrate with third party applications: webservices are the solution.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #52964  by frankywong
 
Hi Sir,

Need some help on PHP SDK. My company have been using both OpenKM Pro(V6.4.49) and OpenKM Community(V6.3.2) for several years.
Now I would like to develop a more simple PHP web application to access to OpenKM Community to retrieve the folder list & PDF file inside those folders.

I tried to go through and study SDK PHP 1.1.2 from here (https://docs.openkm.com/kcenter/view/sd ... mples.html). However I see most of the sample/guides here will only use PHP function var_dump() to show the result.
In this case, I just need the specific "path" data, how can I get it to return only this "path" data? I tried to search in this forum as well as google search, but look like no one have a simple guide on this.

Can I ask if you could please help to guild me or show some simple code to achieve above information? Is that the SDK provided is just sample, which I need to modify it before use?

Example Script:
Code: Select all
<?php

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

use openkm\OKMWebservices;
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\Folder;

class ExampleFolder {

    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 testGetFolderChildren(){
        try {            
            $folders = $this->ws->getFolderChildren("/okm:root/TLMS/CDR/COMDWG");            
            foreach ($folders as $folder) {
                var_dump($folder);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
}

$openkm = new OpenKM(); //autoload
$exampleFolder = new ExampleFolder();
$exampleFolder->testGetFolderChildren();

?>
and the results showing
D:\wamp\www\sdk4php-1.1.2\test\TestOKM.php:46:
object(openkm\bean\Folder)[24]
private 'hasChildren' => string 'false' (length=5)
protected 'created' => string '2021-04-19T11:42:13+08:00' (length=25)
protected 'path' => string '/okm:root/TLMS/CDR/COMDWG/[027]PRE-FORMING' (length=42)
protected 'author' => string 'okmAdmin' (length=8)
protected 'permissions' => int 15
protected 'uuid' => string '39e2a2f7-909f-4937-89e9-9afb5ad5c97d' (length=36)
protected 'subscribed' => string 'false' (length=5)
protected 'subscriptors' =>
array (size=0)
empty
protected 'keywords' =>
array (size=0)
empty
protected 'categories' =>
array (size=0)
empty
protected 'notes' =>
array (size=0)
empty
 #52971  by sochoa
 
Hello, good morning, here is an example of all the properties that a folder and a document can have.

IDEs like netbeans, Intellij IDEA can help you to more easily recognize the properties that a class has.

If you enter the path / src / openkm / bean /
You can see all the classes and their properties that the sdk has and that you can use in your php project
Code: Select all
<?php

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

use openkm\bean\LockInfo;
use openkm\bean\Version;
use openkm\OKMWebservices;
use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\Folder;
use openkm\bean\Document;

class ExampleFolder {

    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 testGetFolderChildren(){
        try {
            $folders = $this->ws->getFolderChildren("/okm:root/PDF");
            foreach ($folders as $folder) {
                $this->printFolder($folder);
            }
            $documents = $this->ws->getDocumentChildren("/okm:root/PDF");
            foreach ($documents as $document) {
                $this->printDocument($document);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function printFolder(Folder $folder) {
        echo '<h2>' . $this->getName($folder->getPath()) . '</h2>';
        echo '<div style="margin-left:30px">';
        echo '<p><strong>Author</strong>:' . $folder->getAuthor() . '</p>';
        echo '<p><strong>Created</strong>:' . $folder->getCreated() . '</p>';
        echo '<p><strong>Path</strong>:' . $folder->getPath() . '</p>';
        echo '<p><strong>Permissions</strong>:' . $folder->getPermissions() . '</p>';
        echo '<p><strong>Subscribed</strong>:' . $folder->isSubscribed() . '</p>';
        echo '<p><strong>Uuid</strong>:' . $folder->getUuid() . '</p>';
        echo '<p><strong>HasChildrend</strong>:' . $folder->isHasChildren() . '</p>';
        echo '<p><strong>Style</strong>:' . $folder->getStyle() . '</p>';
        foreach ($folder->getCategories() as $category) {
            echo '<h3>Categories</h3>';
            echo '<p><strong>Author</strong>:' . $category->getAuthor() . '</p>';
            echo '<p><strong>Created</strong>:' . $category->getCreated() . '</p>';
            echo '<p><strong>Path</strong>:' . $category->getPath() . '</p>';
            echo '<p><strong>Permissions</strong>:' . $category->getPermissions() . '</p>';
            echo '<p><strong>Subscribed</strong>:' . $category->isSubscribed() . '</p>';
            echo '<p><strong>Uuid</strong>:' . $category->getUuid() . '</p>';
            echo '<p><strong>HasChildrend</strong>:' . $category->isHasChildren() . '</p>';
            echo '<p><strong>Style</strong>:' . $category->getStyle() . '</p>';
        }
        foreach ($folder->getKeywords() as $keyword) {
            echo '<h3>Keywords: ' . $keyword . '</h3>';
        }

        foreach ($folder->getNotes() as $note) {
            echo '<h3>Notes</h3>';
            echo '<p><strong>Author</strong>:' . $note->getAuthor() . '</p>';
            echo '<p><strong>Date</strong>:' . $note->getDate() . '</p>';
            echo '<p><strong>Path</strong>:' . $note->getPath() . '</p>';
            echo '<p><strong>text</strong>:' . $note->getText() . '</p>';
        }
        foreach ($folder->getSubscriptors() as $subscriptor) {
            echo '<h3>Subscriptors: ' . $subscriptor . '</h3>';
        }
        echo '</div>';
    }

    public function printDocument(Document $document) {
        echo '<h2>' . $this->getName($document->getPath()) . '</h2>';
        echo '<div style="margin-left:30px">';
        echo '<p><strong>Author</strong>:' . $document->getAuthor() . '</p>';
        echo '<p><strong>Created</strong>:' . $document->getCreated() . '</p>';
        echo '<p><strong>Path</strong>:' . $document->getPath() . '</p>';
        echo '<p><strong>Permissions</strong>:' . $document->getPermissions() . '</p>';
        echo '<p><strong>Subscribed</strong>:' . $document->isSubscribed() . '</p>';
        echo '<p><strong>Uuid</strong>:' . $document->getUuid() . '</p>';
        echo '<p><strong>CheckedOut</strong>:' . $document->isCheckedOut() . '</p>';
        echo '<p><strong>ConvertiblePdf</strong>:' . $document->isConvertibleToPdf() . '</p>';
        echo '<p><strong>ConvertibleSwf</strong>:' . $document->isConvertibleToSwf() . '</p>';
        echo '<p><strong>Description</strong>:' . $document->getDescription() . '</p>';
        echo '<p><strong>Language</strong>:' . $document->getLanguage() . '</p>';
        echo '<p><strong>LastModified</strong>:' . $document->getLastModified() . '</p>';
        echo '<p><strong>Locked</strong>:' . $document->isLocked() . '</p>';
        echo '<p><strong>MineType</strong>:' . $document->getMimeType() . '</p>';
        echo '<p><strong>Signed</strong>:' . $document->isSigned() . '</p>';
        echo '<p><strong>Title</strong>:' . $document->getTitle() . '</p>';

        $this->printVersion($document->getActualVersion());

        $this->printLockInfo($document->getLockInfo());

        foreach ($document->getCategories() as $category) {
            echo '<h3>Categories</h3>';
            echo '<p><strong>Author</strong>:' . $category->getAuthor() . '</p>';
            echo '<p><strong>Created</strong>:' . $category->getCreated() . '</p>';
            echo '<p><strong>Path</strong>:' . $category->getPath() . '</p>';
            echo '<p><strong>Permissions</strong>:' . $category->getPermissions() . '</p>';
            echo '<p><strong>Subscribed</strong>:' . $category->isSubscribed() . '</p>';
            echo '<p><strong>Uuid</strong>:' . $category->getUuid() . '</p>';
            echo '<p><strong>HasChildrend</strong>:' . $category->isHasChildren() . '</p>';
            echo '<p><strong>Style</strong>:' . $category->getStyle() . '</p>';
        }
        foreach ($document->getKeywords() as $keyword) {
            echo '<h3>Keywords: ' . $keyword . '</h3>';
        }

        foreach ($document->getNotes() as $note) {
            echo '<h3>Notes</h3>';
            echo '<p><strong>Author</strong>:' . $note->getAuthor() . '</p>';
            echo '<p><strong>Date</strong>:' . $note->getDate() . '</p>';
            echo '<p><strong>Path</strong>:' . $note->getPath() . '</p>';
            echo '<p><strong>text</strong>:' . $note->getText() . '</p>';
        }
        foreach ($document->getSubscriptors() as $subscriptor) {
            echo '<h3>Subscriptors: ' . $subscriptor . '</h3>';
        }
        echo '</div>';
    }

    public function printVersion(Version $version) {
        echo '<h2>Version</h2>';
        echo '<p><strong>Actual</strong>:' . $version->getActual() . '</p>';
        echo '<p><strong>Author</strong>:' . $version->getAuthor() . '</p>';
        echo '<p><strong>Checksum</strong>:' . $version->getChecksum() . '</p>';
        echo '<p><strong>Created</strong>:' . $version->getCreated() . '</p>';
        echo '<p><strong>Name</strong>:' . $version->getName() . '</p>';
        echo '<p><strong>Size</strong>:' . $version->getSize() . '</p>';
    }

    public function printLockInfo(LockInfo $lockInfo) {
        echo '<h2>LockInfo</h2>';
        echo '<p><strong>NodePath</strong>:' . $lockInfo->getNodePath() . '</p>';
        echo '<p><strong>Owner</strong>:' . $lockInfo->getOwner() . '</p>';
        echo '<p><strong>Token</strong>:' . $lockInfo->getToken() . '</p>';
    }

    public function getName($path) {
        return substr($path, strrpos($path, '/') + 1);
    }
}

$openkm = new OpenKM(); //autoload
$exampleFolder = new ExampleFolder();
$exampleFolder->testGetFolderChildren();

?>

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.