1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6
7/**
8* XML writer class
9*
10* Class to simplify manual writing of xml documents.
11* It only supports writing xml sequentially, because the xml document
12* is saved in a string with no additional structure information.
13* The author is responsible for well-formedness and validity
14* of the xml document.
15*
16* @author Stefan Meyer <meyer@leifos.com>
17* @version $Id: class.ilObjectXMLWriter.php,v 1.3 2005/11/04 12:50:24 smeyer Exp $
18*/
19class ilSoapRoleObjectXMLWriter extends ilXmlWriter
20{
21    public $ilias;
22    public $xml;
23    public $roles;
24    public $role_type;
25    public $user_id = 0;
26
27    /**
28    * constructor
29    * @param	string	xml version
30    * @param	string	output encoding
31    * @param	string	input encoding
32    * @access	public
33    */
34    public function __construct()
35    {
36        global $DIC;
37
38        $ilias = $DIC['ilias'];
39        $ilUser = $DIC['ilUser'];
40
41        parent::__construct();
42
43        $this->ilias =&$ilias;
44        $this->user_id = $ilUser->getId();
45    }
46
47
48    public function setObjects(&$roles)
49    {
50        $this->roles = &$roles;
51    }
52
53    public function setType($type)
54    {
55        $this->role_type = $type;
56    }
57
58
59    public function start()
60    {
61        global $DIC;
62
63        $rbacreview = $DIC['rbacreview'];
64        if (!is_array($this->roles)) {
65            return false;
66        }
67
68        $this->__buildHeader();
69
70        include_once './Services/AccessControl/classes/class.ilObjRole.php';
71        include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
72
73        foreach ($this->roles as $role) {
74            // if role type is not empty and does not match, then continue;
75            if (!empty($this->role_type) && strcasecmp($this->role_type, $role["role_type"]) != 0) {
76                continue;
77            }
78            if ($rbacreview->isRoleDeleted($role["obj_id"])) {
79                continue;
80            }
81
82            $attrs = array(	'role_type' => ucwords($role["role_type"]),
83                'id' => "il_" . IL_INST_ID . "_role_" . $role["obj_id"]);
84
85            // open tag
86            $this->xmlStartTag("Role", $attrs);
87
88
89            $this->xmlElement('Title', null, $role["title"]);
90            $this->xmlElement('Description', null, $role["description"]);
91            $this->xmlElement('Translation', null, ilObjRole::_getTranslation($role["title"]));
92
93            if ($ref_id = ilUtil::__extractRefId($role["title"])) {
94                $ownerObj = IlObjectFactory::getInstanceByRefId($ref_id, false);
95
96                if (is_object($ownerObj)) {
97                    $attrs = array("obj_id" =>
98                        "il_" . IL_INST_ID . "_" . $ownerObj->getType() . "_" . $ownerObj->getId(), "ref_id" => $ownerObj->getRefId(), "type" => $ownerObj->getType());
99                    $this->xmlStartTag('AssignedObject', $attrs);
100                    $this->xmlElement('Title', null, $ownerObj->getTitle());
101                    $this->xmlElement('Description', null, $ownerObj->getDescription());
102                    ilObjectXMLWriter::appendPathToObject($this, $ref_id);
103                    $this->xmlEndTag('AssignedObject', $attrs);
104                }
105            }
106
107            $this->xmlEndTag("Role");
108        }
109
110        $this->__buildFooter();
111
112        return true;
113    }
114
115    public function getXML()
116    {
117        return $this->xmlDumpMem(false);
118    }
119
120
121    public function __buildHeader()
122    {
123        $this->xmlSetDtdDef("<!DOCTYPE Roles PUBLIC \"-//ILIAS//DTD ILIAS Roles//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_role_object_3_10.dtd\">");
124        $this->xmlSetGenCmt("Roles information of ilias system");
125        $this->xmlHeader();
126
127        $this->xmlStartTag('Roles');
128
129        return true;
130    }
131
132    public function __buildFooter()
133    {
134        $this->xmlEndTag('Roles');
135    }
136}
137