Difference between revisions of "SDK for PHP 2.0.2"

From OpenKM Documentation
Jump to: navigation, search
(Created page with "{{TOCright}} __TOC__ {{Note|If '''you want to collaborate''' extending features or add newer '''contact with us at''' [http://www.openkm.com/en/contact.html contact website fo...")
 
Line 117: Line 117:
 
</source>
 
</source>
  
An example of searching with the sdk and how to know if a document or folder.   
+
An example of searching with the sdk and how to know if the result node is document or folder.   
  
 
<source lang="php">
 
<source lang="php">

Revision as of 08:18, 2 July 2014


Nota clasica.png If you want to collaborate extending features or add newer contact with us at contact website form indicating this URL.

OpenKM SDK for php is a set of software developement tools that allows for the creation of applications for OpenKM. The OpenKM SDK for php include a webservices library. This webservices library is a complete API layer to access OpenKM through webservices and provides complete compatibility between OpenKM webservices versions without change code.

Available zip file

Advantage of use

We recommend to use SDK for php because it implements an extra layer between webservices and logic -factory- which allow transparently change between webservices versions without major effors. Simply instance other webservices version from factory in your source code.

Example

In zip file into folder called test there are some php testing files. Consider some const values must be changed to get it running in your OpenKM. For example const TEST_FLD = "e0856a93-3b25-4726-88fc-632dec7c6ab0"; in example you got below must be changed for some folder UUID in your OpenKM.

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

	use openkm\OKMWebServicesFactory;
	use openkm\OpenKM;
	use openkm\bean\Auth;

	/**
	 * TestAuth
	 *
	 * @author sochoa
	 */
	class TestAuth {

                const HOST = "http://localhost:8080/OpenKM/";
                const USER = "okmAdmin";
                const PASSWORD = "admin";
                const TEST_DOC_PATH = "/okm:root/OpenKM/architecture.html";
                const TEST_DOC_UUID = 'e0856a93-3b25-4726-88fc-632dec7c6ab0';

		private $ws;

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

		public function test() {
                    //getGrantedRoles
                    echo '<h2>getGrantedRoles</h2>';
                    $grantedRoles = $this->ws->getGrantedRoles(self::TEST_DOC_UUID);
                    foreach ($grantedRoles as $grantedRole) {
                       echo '<div style="margin-left:30px">';
                       echo '<h3>GrantedRole</h3>';
                       echo '<p><strong>Role:</strong>' .$grantedRole->getRole() . '</p>';
                       echo '<p><strong>Permissions:</strong>' .$grantedRole->getPermissions() . '</p>';
                       echo '</div>';
                    }

                    //getGrantedUsers
                    echo '<h2>getGrantedUsers</h2>';
                    $grantedUsers = $this->ws->getGrantedUsers(self::TEST_DOC_UUID);
                    foreach ($grantedUsers as $grantedUser) {
                       echo '<div style="margin-left:30px">';
                       echo '<h3>GrantedUser</h3>';
                       echo '<p><strong>User:</strong>' .$grantedUser->getUser() . '</p>';
                       echo '<p><strong>Permissions:</strong>' . $grantedUser->getPermissions() . '</p>';
                       echo '</div>';
                    }
 
                    //getRoles
                    echo '<h2>getRoles</h2>';
                    $roles = $this->ws->getRoles();
                    foreach ($roles as $role) {
                       echo '<div style="margin-left:30px">';
                       echo '<p>' . $role . '</p>';
                       echo '</div>';
                    }

                    //getUsers
                    echo '<h2>getUsers</h2>';
                    $users = $this->ws->getUsers();
                    foreach ($users as $user) {
                       echo '<div style="margin-left:30px">';
                       echo '<p>' . $user . '</p>';
                       echo '</div>';
                    }

                    //getUsersByRole
                    echo '<h2>getUsersByRole</h2>';
                    $users = $this->ws->getUsersByRole('ROLE_ADMIN');
                    foreach ($users as $user) {
                       echo '<div style="margin-left:30px">';
                       echo '<p>' . $user . '</p>';
                       echo '</div>';
                     } 
        
                    //getRolesByUser
                    echo '<h2>getRolesByUser</h2>';
                    $roles = $this->ws->getRolesByUser('okmAdmin');
                    foreach ($roles as $role) {
                       echo '<div style="margin-left:30px">';
                       echo '<p>' . $role . '</p>';
                       echo '</div>';
                    }
        
                    //getMail
                    echo '<h2>getMail</h2>';
                    echo '<p>' . $this->ws->getMail('okmAdmin') , '</p>';

                    //getName
                    echo '<h2>getName</h2>';
                    echo '<p>' . $this->ws->getName('okmAdmin') . '</p>';
	     	}

	}

	$openkm = new OpenKM();
	$testAuth = new TestAuth();
	$testAuth->test();
?>

An example of searching with the sdk and how to know if the result node is document or folder.

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;
use openkm\bean\Folder;
use openkm\bean\Document;
use openkm\bean\Version;
use openkm\bean\LockInfo;
use openkm\bean\QueryResult;
use openkm\bean\QueryParams;

/**
 * TestSearch
 *
 * @author sochoa
 */
class TestSearch {

    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 test() {
       
        //find
        $queryParams = new QueryParams();
        $queryParams->setDomain(QueryParams::DOCUMENT + QueryParams::FOLDER);
        $queryParams->setName('text');
        $queryResults = $this->ws->find($queryParams);
        foreach ($queryResults as $queryResult) {
            $this->printQueryResult($queryResult, 'find');
        }         
    }

    public function printQueryResult(QueryResult $queryResult, $title) {        
        echo '<h2>QueryResult - ' . $title . '</h2>';
        echo '<div style="margin-left:30px">';
        echo '<p><strong>Attachment</strong>:' . $queryResult->isAttachment() . '</p>';
        echo '<p><strong>Excerpt</strong>:' . $queryResult->getExcerpt() . '</p>';
        echo '<p><strong>Score</strong>:' . $queryResult->getScore() . '</p>';
        if($queryResult->getNode() instanceof Document){
            $this->printDocument($queryResult->getNode(), $title);
        } else if($queryResult->getNode() instanceof Folder){
            $this->printFolder($queryResult->getNode(), $title);
        }
        echo '</div>';
    }    

    public function printDocument(Document $document, $title) {
        echo '<h2>Document - ' . $title . '</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>NodeClass:</stron>' . $document->getNodeClass() . '</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>ConvertibleDxf</strong>:' . $document->isConvertibleToDxf() . '</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>NodeClass:</stron>' . $category->getNodeClass() . '</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 printFolder(Folder $folder, $title) {
        echo '<h2>Folder - ' . $title . '</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>NodeClass:</stron>' . $folder->getNodeClass() . '</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>NodeClass:</stron>' . $category->getNodeClass() . '</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>';
    }    

}

$openkm = new OpenKM();
$testSearch = new TestSearch();
$testSearch->test();
?>

Available functions and classes

Classes

  • AppVersion
  • CheckBox
  • Document
  • Entry
  • Folder
  • FormElement
  • FormElementComplex
  • GrantedRole
  • GrantedUser
  • Input
  • KeywordMap
  • LockInfo
  • Node
  • Note
  • Option
  • Permission
  • PropertyGroup
  • ProposedQueryReceived
  • ProposedQuerySent
  • QueryParams
  • QueryResult
  • ResultSet
  • Select
  • Separator
  • SuggestBox
  • SimplePropertyGroup
  • Text
  • TextArea
  • Validator
  • Version

Auth

    public function getGrantedRoles($nodeId);
    public function getGrantedUsers($nodeId);
    public function getMail($user);
    public function getName($user);
    public function getRoles();
    public function getRolesByUser($user);
    public function getUsers();
    public function getUsersByRole($role);
    public function revokeRole($nodeId, $role, $permissions, $recursive);
    public function revokeUser($nodeId, $user, $permissions, $recursive);
    public function grantRole($nodeId, $role, $permissions, $recursive);
    public function grantUser($nodeId, $user, $permissions, $recursive);
    public void createUser($user, $password, $email, $name, $active);
    public void deleteUser($user);
    public void updateUser($user, $password, $email, $name, $active);
    public void createRole($role, $active);
    public void deleteRole($role);
    public void updateRole($role, $active);
    public void assignRole($user, $role);
    public void removeRole($user, $role);

Repository

    public function getRootFolder();
    public function getTrashFolder();
    public function getTemplatesFolder();
    public function getPersonalFolder();
    public function getMailFolder();
    public function getThesaurusFolder();
    public function getCategoriesFolder();
    public function purgeTrash();
    public function getUpdateMessage();
    public function getRepositoryUuid();
    public function hasNode($nodeId);
    public function getNodePath($uuid);
    public function getNodeUuid($nodePath);
    public function getAppVersion();

Document

    public function createDocument(Document $okmDocument, $is);
    public function createDocumentSimple($docPath, $is);
    public function deleteDocument($docId);
    public function getDocumentProperties($docId);
    public function getContent($docId);
    public function getContentByVersion($docId, $versionId);
    public function getDocumentChildren($fldId);
    public function renameDocument($docId, $newName);
    public function setProperties(Document $okmDocument);
    public function setLanguage($docId, $lang);
    public function setTitle($docId, $title);
    public function checkout($docId);
    public function cancelCheckout($docId);
    public function forceCancelCheckout($docId);
    public function isCheckedOut($docId);
    public function checkin($docId, $is, $comment);
    public function getVersionHistory($docId);
    public function lock($docId);
    public function unlock($docId);
    public function forceUnlock($docId);
    public function isLocked($docId);
    public function getLockInfo($docId);
    public function purgeDocument($docId);
    public function moveDocument($docId, $dstId);
    public function copyDocument($docId, $dstId);
    public function restoreVersion($docId, $versionId);
    public function purgeVersionHistory($docId);
    public function getVersionHistorySize($docId);
    public function isValidDocument($docId);
    public function getDocumentPath($uuid);
    public function setLanguage($docId, $lang);
    public function setTitle($docId, $title);
    public function setDocumentNodeClass($docId, $ncId);
    public Function getDetectedLanguages();

Folder

    public function createFolder(Folder $okmFolder);
    public function createFolderSimple($fldPath);
    public function getFolderProperties($fldId);
    public function deleteFolder($fldId);
    public function renameFolder($fldId, $newName);
    public function moveFolder($fldId, $dstId);
    public function getFolderChildren($fldId);
    public function isValidFolder($fldId);
    public function getFolderPath($uuid);

Note

    public function addNote($nodeId, $text);
    public function getNote($noteId);
    public function deleteNote($noteId);
    public function setNote($noteId, $text);
    public function listNotes($nodeId);

PropertyGroup

    public function addGroup($nodeId, $grpName);
    public function removeGroup($nodeId, $grpName);
    public function getGroups($nodeId);
    public function getAllGroups();
    public function getPropertyGroupProperties($nodeId, $grpName);
    public function setPropetyGroupProperties($nodeId, $grpName, $formElementList = array());
    public function setPropertyGroupPropertiesSimple($nodeId, $grpName, $properties = array());
    public function hasGroup($nodeId, $grpName);
    public function getPropertyGroupForm($grpName);

Property

    public function addCategory($nodeId, $catId);
    public function removeCategory($nodeId, $catId);
    public function addKeyword($nodeId, $keyword);
    public function removeKeyword($nodeId, $keyword);
    public function setEncryption($nodeId, $cipherName);
    public function unsetEncryption($nodeId);
    public function setSigned($nodeId, $signed);

Search

    public function findByContent($content);
    public function findByName($name);
    public function findByKeywords($keywords = array());
    public function find(QueryParams $queryParams);
    public function findPaginated(QueryParams $queryParams, $offset, $limit);
    public function findSimpleQueryPaginated($statement, $offset, $limit);
    public function findMoreLikeThis($uuid, $max);
    public function getKeywordMap($filter = array());
    public function getCategorizedDocuments($categoryId);
    public function saveSearch(QueryParams $params);
    public function updateSearch(QueryParams $params);
    public function getSearch($qpId);
    public function getAllSearchs();
    public function deleteSearch($qpId);