<?php

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

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

use openkm\OKMWebServicesFactory;
use openkm\OpenKM;

class ExampleTask {

    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 testCreateTask() {
        try {
            $usersId = array();
            $usersId[] = 'okmAdmin';
            $usersId[] = 'sochoa';
            $rolesId = array();
            $rolesId[] = 'ROLE_USER';
            $description = '<p><strong>Esta</strong> es la descripcion</p>';

            $task = $this->ws->createTask('Subject 2', date('YmdHis'), date('YmdHis'), 1, 2, 1, $description, $usersId, $rolesId);
            var_dump($task);
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testFindTask() {
        try {
            var_dump($this->ws->findTask(1));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testDeleteTask() {
        try {
            
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetAssigned() {
        try {
            
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetActive() {
        try {
            
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetFinished() {
        try {
            
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testFindStatus() {
        try {
            var_dump($this->ws->findStatus(1));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testFindProject() {
        try {
            var_dump($this->ws->findProject(1));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testFindType() {
        try {
            var_dump($this->ws->findType(1));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testFindNote() {
        try {
            var_dump($this->ws->findNote(1));
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetStatuses() {
        try {
            $taskStatuses = $this->ws->getStatuses();
            foreach ($taskStatuses as $taskStatus) {
                var_dump($taskStatus);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetProjects() {
        try {
            $taskProjects = $this->ws->getProjects(true);
            foreach ($taskProjects as $taskProject) {
                var_dump($taskProject);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetTypes() {
        try {
            $taskTypes = $this->ws->getTypes(true);
            foreach ($taskTypes as $taskType) {
                var_dump($taskType);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

    public function testGetNotes() {
        try {
            $taskNotes = $this->ws->getNotes(1);
            foreach ($taskNotes as $taskNote) {
                var_dump($taskNote);
            }
        } catch (Exception $e) {
            var_dump($e);
        }
    }

}

$openkm = new OpenKM(); //autoload
$exampleTask = new ExampleTask();
$exampleTask->testCreateTask();
?>