PropertyGroup samples

Basics

From older OpenKM version we named "Metadata Groups" as "Property Groups".

Although we understand this name does not help a lot to identifying these methods with metadata ones, for historical reason, we continue maintaining the nomenclature.

For more information about Metadata.

On almost 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

addGroup

Description:

MethodReturn valuesDescription

addGroup($nodeId, $grpName)

void

Add an empty metadata group to a node.

Parameters:

$nodeId 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.

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 testAddGroup() {
        try {
            $this->ws->addGroup('/okm:root/SDK4PHP/logo.png', 'okg:consulting');
            echo 'addGroup';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

removeGroup

Description:

MethodReturn valuesDescription

removeGroup($nodeId, $grpName)

void

Removes a metadata group of a node.

Parameters:

$nodeId 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.

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 testRemoveGroup() {
        try {
            $this->ws->removeGroup('/okm:root/SDK4PHP/logo.png', 'okg:consulting');
            echo 'Remove Group';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

getGroups

Description:

MethodReturn valuesDescription

getGroups($nodeId)

array

Retrieves a list of metadata groups assigned to 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 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 testGetGroups() {
        try {
            $propertyGroups = $this->ws->getGroups('/okm:root/SDK4PHP/logo.png');
            foreach ($propertyGroups as $propertyGroup) {
                var_dump($propertyGroup);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

getAllGroups

Description:

MethodReturn valuesDescription

getAllGroups()

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 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 testGetAllGroups() {
        try {
            $propertyGroups = $this->ws->getAllGroups();
            foreach ($propertyGroups as $propertyGroup) {
                var_dump($propertyGroup);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

getPropertyGroupProperties

Description:

MethodReturn valuesDescription

getPropertyGroupProperties(String nodeId, String grpName)

List<FormElement>

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

Parameters:

$nodeId 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.

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

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 testGetPropertyGroupProperties() {
        try {
            $formElements = $this->ws->getPropertyGroupProperties('/okm:root/SDK4PHP/logo.png', 'okg:consulting');
            foreach ($formElements as $formElement) {
               var_dump($formElement);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

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();
?>

setPropertyGroupProperties

Description:

MethodReturn valuesDescription

setPropertyGroupProperties($nodeId, $grpName, $formElements)

void

Changes the metadata group values of a node.

Parameters:

$nodeId 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.

$formElements array type is an array of the FormElement

Is not mandatory set into parameter ofeList all FormElement, is enought with the formElements 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 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 testSetPropertyGroupProperties() {
        try {
            // Same modification with only affected FormElement
            $formElements = array();
            $name = new \openkm\bean\form\Input();
            $name->setName("okp:consulting.name");
            $name->setValue("new value");
            $formElements[] = $name;
            $this->ws->setPropertyGroupProperties('/okm:root/SDK4PHP/logo.png', 'okg:consulting', $formElements);
            echo 'updated';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

setPropertyGroupPropertiesSimple

Description:

MethodReturn valuesDescription

setPropertyGroupPropertiesSimple($nodeId, $grpName, $properties)

void

Changes the metadata group values of a node.

Parameters:

$nodeId 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 of the SimplePropertyGroup

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';

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

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 testSetPropertyGroupPropertiesSimple() {
        try {
            $properties = [];
            $properties["okp:consulting.name"] = "new value";
            $properties["okp:consulting.important"] = "true";

            $this->ws->setPropertyGroupPropertiesSimple('/okm:root/SDK4PHP/logo.png', 'okg:consulting', $properties);
            echo 'updated';
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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

hasGroup

Description:

MethodReturn valuesDescription

hasGroup($nodeId, $grpName)

bool

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

Parameters:

$nodeId 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.

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 testSetPropertyGroupPropertiesSimple() {
        try {
            echo 'Have metadata group: ' . $this->ws->hasGroup('/okm:root/SDK4PHP/logo.png', 'okg:consulting');
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

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