Relation samples

Basics

On most methods you'll see parameter named "nodeId". The value of this parameter can be a valid document, folder, mail or record UUID or path.

Example of nodeId:

  • Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
  • Using path -> "/okm:root/SDK4PHP/logo.png"

Methods

getRelationTypes

Description:

MethodReturn valuesDescription

getRelationTypes($type)

array(RelationType)

Retrieves a list of all relations defined of a type.

Parameters:
$type string type

Available types values:

  • RelationType::BIDIRECTIONAL
  • RelationType::PARENT_CHILD
  • RelationType::MANY_TO_MANY

More information at Relation types.

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testGetRelationTypes() {
        try {
            $relationTypes = $this->ws->getRelationTypes(\openkm\bean\RelationType::PARENT_CHILD);
            foreach ($relationTypes as $relationType) {
                var_dump($relationType);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testGetRelationTypes();
?>

addRelation

Description:

MethodReturn valuesDescription

addRelation($nodeAId, $nodeBId, long relTypeId)

void

Sets a relation between two nodes.

Parameters:
$nodeAId string type is the UUID or path of the document, folder, mail or record

$nodeBId string type is the UUID or path of the document, folder, mail or record

$relTypeId int type is the id RelationType

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testAddRelation() {
        try {
            $relationTypes = $this->ws->getRelationTypes(\openkm\bean\RelationType::PARENT_CHILD);
            foreach ($relationTypes as $relationType) {
                // looking for a relation named Invoice of
                if($relationType->getTitleAToB() == 'Invoice of'){
                    $this->ws->addRelation('/okm:root/SDK4PHP/invoice.pdf', '/okm:root/SDK4PHP/budget.pdf', $relationType->getId());
                    echo 'add Relation';
                }
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }
}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testAddRelation();
?>

deleteRelation

Description:

MethodReturn valuesDescription

deleteRelation($relationId)

void

Deletes a relation.

Parameters

$relationId int type

Only when the relation will not be used by any node is able to be deleted, otherwise you'll get an error.

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testDeleteRelation() {
        try {
            $relations = $this->ws->getRelations('/okm:root/SDK4PHP/invoice.pdf');
            foreach ($relations as $relation) {
                //looking for a relation named Invoice of
                if ($relation->getRelationTitle() == 'Invoice of') {
                    $this->ws->deleteRelation($relation->getId());
                    echo 'delete Relation';
                }
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testDeleteRelation();
?>

getRelations

Description:

MethodReturn valuesDescription

getRelations($nodeId)

array(Relation)

Retrieves a list of all relations of a node.

Parameters:
$nodeId
string type is the UUID or path of the document, folder, mail or record

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testGetRelations() {
        try {
            $relations = $this->ws->getRelations('/okm:root/SDK4PHP/invoice.pdf');
            foreach ($relations as $relation) {
                var_dump($relation);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testGetRelations();
?>

getRelationGroups

Description:

MethodReturn valuesDescription

getRelationGroups($nodeId)

array(RelationGroup)

Retrieves a list of all relation groups of a node.

Parameters:
$nodeId
string type is the UUID or path of the document, folder, mail or record

Example:

<?php

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

ini_set('display_errors', true);
error_reporting(E_ALL);

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testGetRelationGroups() {
        try {
            $relationGroups = $this->ws->getRelationGroups('/okm:root/SDK4PHP/invoice.pdf');
            foreach ($relationGroups as $relationGroup) {
                var_dump($relationGroup);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testGetRelationGroups();
?>

addRelationGroup

Description:

MethodReturn valuesDescription

addRelationGroup($nodeId, $groupName, $type)

void

Adds a relation group at a node.

Parameters:
$nodeId
string type is the UUID or path of the document, folder, mail or record

$groupName string type 

$type int type is the

On a relation group only has sense to apply a relation type of Relation Type::MANY_TO_MANY.

More information at Relation types.

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testAddRelationGroup() {
        try {
            $relationTypes = $this->ws->getRelationTypes(\openkm\bean\RelationType::MANY_TO_MANY);
            foreach ($relationTypes as $relationType) {                
                if ($relationType->getTitle() == 'staple') {
                    $this->ws->addRelationGroup('/okm:root/SDK4PHP/invoice.pdf', 'staple group', $relationType->getId());
                    echo 'add Relation Group';
                }
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testAddRelationGroup();
?>

addNodeToGroup

Description:

MethodReturn valuesDescription

addNodeToGroup($nodeId, $groupId)

void

Adds a node to an existing relation group.

Parameters:
$nodeId
string type is the UUID or path of the document, folder, mail or record

$groupId int type 

On a relation group only has sense apply the type RelationType::MANY_TO_MANY.

More information at Relation types.

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testAddNodeToGroup() {
        try {
            $relationGroups = $this->ws->getRelationGroups('/okm:root/SDK4PHP/invoice.pdf');
            foreach ($relationGroups as $relationGroup) {
                if ($relationGroup->getName() == 'staple group') {
                    $this->ws->addNodeToGroup('/okm:root/SDK4PHP/complaint.pdf', $relationGroup->getId());
                    echo 'add Node To Group';
                }
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testAddNodeToGroup();
?>

deleteRelationGroup

Description:

MethodReturn valuesDescription

deleteRelationGroup($nodeId, $groupId)

void

Removes a node from a relation group.

Parameters:
$nodeId
string type is the UUID or path of the document, folder, mail or record

$groupId int type 

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testDeleteRelationGroup() {
        try {
            $relationGroups = $this->ws->getRelationGroups('/okm:root/SDK4PHP/invoice.pdf');
            foreach ($relationGroups as $relationGroup) {
                if ($relationGroup->getName() == 'staple group') {
                    $this->ws->deleteRelationGroup('/okm:root/SDK4PHP/complaint.pdf', $relationGroup->getId());
                    echo 'delete relation group';
                }
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testDeleteRelationGroup();
?>

findRelationGroup

Description:

MethodReturn valuesDescription

findRelationGroup($groupId)

RelationGroup

Finds a relation group by id.

Parameters:

$groupId int type 

Example:

<?php

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

ini_set('display_errors', true);
error_reporting(E_ALL);

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testFindRelationGroup() {
        try {
            $groupId = 2;
            var_dump($this->ws->findRelationGroup($groupId));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testFindRelationGroup();
?>

setRelationGroupName

Description:

MethodReturn valuesDescription

setRelationGroupName($groupId, $groupName)

void

Changes the relation group name.

Parameters:

$groupId int type 

$groupName string type 

Example:

<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleRelation {

    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 testSetRelationGroupName() {
        try {
            $groupId = 2;
            $this->ws->setRelationGroupName($groupId, 'new name');
            echo 'set group name';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleRelation = new ExampleRelation();
$exampleRelation->testSetRelationGroupName();
?>