<?php

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class Test {

    const HOST = "http://localhost:8080/openkm/";
    const USER = "okmAdmin";
    const PASSWORD = "admin";

    private $ws;

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

    public function test() {
        echo '<pre>';
        try {
            $this->ws->login(self::USER, self::PASSWORD);
            $subject = "task subject";

            $start = date('YmdHis');
            $end = date('YmdHis');

            $description = "description test";

            $statusId = 1; // A valid task status id
            $projectId = 1; // A valid project id
            $typeId = 1; // A valid type id

            $user = "okmAdmin";
            $notificationUsers = [];
            $notificationUsers[] = "gnujavasergio";
            $notificationUsers[] = "sochoa";

            $externalUsers = [];
            $externalUsers[] = "gnu.java.sergio@gmail.com";

            $relatedDocuments = [];
            $relatedDocuments[] = "d701c503-87fc-4a9e-829e-478dc375eb83";
            $relatedDocuments[] = "f02053e3-2264-4040-bb84-67983a0208f7";

            $relatedFolders = [];
            $relatedFolders[] = "0a777b34-f518-4da7-9e58-8b1425e05add";
            $relatedFolders[] = "271cc3aa-218e-4574-8065-c34c704f4a20";

            $relatedMails = [];
            $relatedMails[] =  "3ae1bb26-acdf-4463-a0c1-06cc62f55b95";
            $relatedMails[] = "c599be73-7831-4e93-be91-453baeda2b00";

            $relatedRecords = [];
            $relatedRecords[] = "96801b33-e92e-436b-8ed7-5d8dea904673";
            $relatedRecords[] = "23b50095-aa18-4d16-ae75-74b994a2f2b4";

            $repeatUntil = '20240113';
            $repeatExpression = "0 0 1 * *";

            $task = $this->ws->task->createTask($subject, $start, $end, $description, $statusId, $projectId, $typeId, $user,
                $notificationUsers, $externalUsers, $relatedDocuments, $relatedFolders, $relatedRecords, $relatedMails,$repeatExpression, $repeatUntil,
                "yyyyMMddHHmmss", 10, "m", 5, "m", 10);
            var_dump($task);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$test = new Test();
$test->test();
?>