Difference between revisions of "PHP client - OpenKM 5.1"

From OpenKM Documentation
Jump to: navigation, search
(Authentication)
(List documents)
Line 19: Line 19:
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
 +
  function printFolder($folder) {
 +
    echo "[FOLDER] Path: ".$folder->path.", Author: ".$folder->author."<br>";
 +
  }
 +
 +
  function printDocument($document) {
 +
    echo "[DOCUMENT] Path: ".$document->path.", Author: ".$document->author.", Size: ".$document->actualVersion->size."<br>";
 +
  }
 +
 +
  // Register WSDL
 
   $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
 
   $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
 +
  $OKMDocument = new SoapClient('http://localhost:8080/OpenKM/OKMDocument?wsdl');
 +
  $OKMFolder = new SoapClient('http://localhost:8080/OpenKM/OKMFolder?wsdl');
 +
  $path = '/okm:root';
 +
 +
  // Login
 
   $token = $OKMAuth->login('okmAdmin','admin');
 
   $token = $OKMAuth->login('okmAdmin','admin');
   echo "Token: ".$token;
+
   echo "Token: ".$token."<br>";
 +
  echo "Path: ".$path."<br>";
 +
 
 +
  // List folders
 +
  $folderArrayResult = $OKMFolder->getChilds($token, $path);
 +
  $folderArray = $folderArrayResult->value;
 +
 
 +
  if ($folderArray) {
 +
    if (is_array($folderArray)) {
 +
      foreach ($folderArray as $folder) {
 +
        printFolder($folder);
 +
      }
 +
    } else {
 +
      printFolder($folderArray);
 +
    }
 +
  }
 +
 
 +
  // List documents
 +
  $documentArrayResult = $OKMDocument->getChilds($token, $path);
 +
  $documentArray = $documentArrayResult->value;
 +
 
 +
  if ($documentArray) {
 +
    if (is_array($documentArray)) {
 +
      foreach ($documentArray as $document) {
 +
        printDocument($document);
 +
      }
 +
    } else {
 +
      printDocument($documentArray);
 +
    }
 +
  }
 +
 
 +
  // Logout
 
   $OKMAuth->logout($token);
 
   $OKMAuth->logout($token);
 
?>
 
?>

Revision as of 17:13, 8 March 2010

Authentication

<?php
  // Register WSDL
  $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
  
  // Login
  $token = $OKMAuth->login('okmAdmin','admin');
  echo "Token: ".$token;
  
  // Logout
  $OKMAuth->logout($token);
?>

List documents

<?php
  function printFolder($folder) {
    echo "[FOLDER] Path: ".$folder->path.", Author: ".$folder->author."<br>";
  }

  function printDocument($document) {
    echo "[DOCUMENT] Path: ".$document->path.", Author: ".$document->author.", Size: ".$document->actualVersion->size."<br>";
  }

  // Register WSDL
  $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
  $OKMDocument = new SoapClient('http://localhost:8080/OpenKM/OKMDocument?wsdl');
  $OKMFolder = new SoapClient('http://localhost:8080/OpenKM/OKMFolder?wsdl');
  $path = '/okm:root';

  // Login
  $token = $OKMAuth->login('okmAdmin','admin');
  echo "Token: ".$token."<br>";
  echo "Path: ".$path."<br>";

  // List folders
  $folderArrayResult = $OKMFolder->getChilds($token, $path);
  $folderArray = $folderArrayResult->value;

  if ($folderArray) {
    if (is_array($folderArray)) {
      foreach ($folderArray as $folder) {
        printFolder($folder);
      }
    } else {
      printFolder($folderArray);
    }
  }

  // List documents
  $documentArrayResult = $OKMDocument->getChilds($token, $path);
  $documentArray = $documentArrayResult->value;

  if ($documentArray) {
    if (is_array($documentArray)) {
      foreach ($documentArray as $document) {
        printDocument($document);
      }
    } else {
      printDocument($documentArray);
    }
  }

  // Logout
  $OKMAuth->logout($token);
?>

Create document

<?php
  $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
  $token = $OKMAuth->login('okmAdmin','admin');
  echo "Token: ".$token;
  $OKMAuth->logout($token);
?>

List folders

<?php
  $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
  $token = $OKMAuth->login('okmAdmin','admin');
  echo "Token: ".$token;
  $OKMAuth->logout($token);
?>

Create folder

<?php
  $OKMAuth = new SoapClient('http://localhost:8080/OpenKM/OKMAuth?wsdl');
  $token = $OKMAuth->login('okmAdmin','admin');
  echo "Token: ".$token;
  $OKMAuth->logout($token);
?>