ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSoapWebLinkAdministration.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './webservice/soap/classes/class.ilSoapAdministration.php';
5
14{
18 public function __construct()
19 {
20 parent::__construct();
21 }
22
29 public function readWebLink($sid, $ref_id)
30 {
31 $this->initAuth($sid);
32 $this->initIlias();
33
34 if (!$this->__checkSession($sid)) {
35 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
36 }
37 if (!strlen($ref_id)) {
38 return $this->__raiseError(
39 'No ref id given. Aborting!',
40 'Client'
41 );
42 }
43 global $rbacsystem, $tree, $ilLog;
44
45 // get obj_id
46 if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
47 return $this->__raiseError(
48 'No weblink found for id: ' . $ref_id,
49 'Client'
50 );
51 }
52
53 if (ilObject::_isInTrash($ref_id)) {
54 return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
55 }
56
57 // Check access
58 $permission_ok = false;
59 $write_permission_ok = false;
60 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
61 if ($rbacsystem->checkAccess('edit', $ref_id)) {
62 $write_permission_ok = true;
63 break;
64 }
65 if ($rbacsystem->checkAccess('read', $ref_id)) {
66 $permission_ok = true;
67 break;
68 }
69 }
70
71 if (!$permission_ok && !$write_permission_ok) {
72 return $this->__raiseError(
73 'No permission to edit the object with id: ' . $ref_id,
74 'Server'
75 );
76 }
77
78 try {
79 include_once './Modules/WebResource/classes/class.ilWebLinkXmlWriter.php';
80 $writer = new ilWebLinkXmlWriter();
81 $writer->setObjId($obj_id);
82 $writer->write();
83
84 return $writer->xmlDumpMem(true);
85 } catch (UnexpectedValueException $e) {
86 return $this->__raiseError($e->getMessage(), 'Client');
87 }
88 }
89
99 public function createWebLink($sid, $target_id, $weblink_xml)
100 {
101 $this->initAuth($sid);
102 $this->initIlias();
103
104 if (!$this->__checkSession($sid)) {
105 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
106 }
107 global $rbacsystem, $tree, $ilLog;
108
109 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($target_id, false)) {
110 return $this->__raiseError('No valid target given.', 'Client');
111 }
112
114 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
115 }
116
117 // Check access
118 // TODO: read from object definition
119 $allowed_types = array('cat','grp','crs','fold','root');
120 if (!in_array($target_obj->getType(), $allowed_types)) {
121 return $this->__raiseError('No valid target type. Target must be reference id of "course, group, root, category or folder"', 'Client');
122 }
123
124 if (!$rbacsystem->checkAccess('create', $target_id, "webr")) {
125 return $this->__raiseError('No permission to create weblink in target ' . $target_id . '!', 'Client');
126 }
127
128
129 // create object, put it into the tree and use the parser to update the settings
130 include_once './Modules/WebResource/classes/class.ilObjLinkResource.php';
131 include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
132
133 $webl = new ilObjLinkResource();
134 $webl->setTitle('XML Import');
135 $webl->create(true);
136 $webl->createReference();
137 $webl->putInTree($target_id);
138 $webl->setPermissions($target_id);
139
140 try {
141 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
143 $parser->start();
144 } catch (ilSaxParserException $e) {
145 return $this->__raiseError($e->getMessage(), 'Client');
146 } catch (ilWebLinkXMLParserException $e) {
147 return $this->__raiseError($e->getMessage(), 'Client');
148 }
149
150 // Check if required
151 return $webl->getRefId();
152 }
153
163 public function updateWebLink($sid, $ref_id, $weblink_xml)
164 {
165 $this->initAuth($sid);
166 $this->initIlias();
167
168 if (!$this->__checkSession($sid)) {
169 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
170 }
171 global $rbacsystem, $tree, $ilLog;
172
173 if (ilObject::_isInTrash($ref_id)) {
174 return $this->__raiseError('Cannot perform update since weblink has been deleted.', 'CLIENT_OBJECT_DELETED');
175 }
176 // get obj_id
177 if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
178 return $this->__raiseError(
179 'No weblink found for id: ' . $ref_id,
180 'CLIENT_OBJECT_NOT_FOUND'
181 );
182 }
183
184 // Check access
185 $permission_ok = false;
186 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
187 if ($rbacsystem->checkAccess('edit', $ref_id)) {
188 $permission_ok = true;
189 break;
190 }
191 }
192
193 if (!$permission_ok) {
194 return $this->__raiseError(
195 'No permission to edit the weblink with id: ' . $ref_id,
196 'Server'
197 );
198 }
199
200 $webl = ilObjectFactory::getInstanceByObjId($obj_id, false);
201 if (!is_object($webl) or $webl->getType()!= "webr") {
202 return $this->__raiseError(
203 'Wrong obj id or type for weblink with id ' . $ref_id,
204 'Client'
205 );
206 }
207
208 try {
209 include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
210 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
212 $parser->start();
213 } catch (ilSaxParserException $e) {
214 return $this->__raiseError($e->getMessage(), 'Client');
215 } catch (ilWebLinkXMLParserException $e) {
216 return $this->__raiseError($e->getMessage(), 'Client');
217 }
218
219 // Check if required
220 return true;
221 }
222}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
Class ilObjLinkResource.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
static _isInTrash($a_ref_id)
checks wether object is in trash
SaxParserException thrown by ilSaxParser if property throwException is set.
initAuth($sid)
Init authentication.
__raiseError($a_message, $a_code)
Soap methods for adminstrating web links.
updateWebLink($sid, $ref_id, $weblink_xml)
update a weblink with id.
readWebLink($sid, $ref_id)
Get Weblink xml.
createWebLink($sid, $target_id, $weblink_xml)
add an exercise with id.
XML parser for weblink xml.
XML writer for weblinks.
$target_id
Definition: goto.php:49