ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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 $DIC;
44
45 $rbacsystem = $DIC['rbacsystem'];
46 $tree = $DIC['tree'];
47 $ilLog = $DIC['ilLog'];
48
49 // get obj_id
50 if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
51 return $this->__raiseError(
52 'No weblink found for id: ' . $ref_id,
53 'Client'
54 );
55 }
56
57 if (ilObject::_isInTrash($ref_id)) {
58 return $this->__raiseError("Parent with ID $ref_id has been deleted.", 'Client');
59 }
60
61 // Check access
62 $permission_ok = false;
63 $write_permission_ok = false;
64 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
65 if ($rbacsystem->checkAccess('edit', $ref_id)) {
66 $write_permission_ok = true;
67 break;
68 }
69 if ($rbacsystem->checkAccess('read', $ref_id)) {
70 $permission_ok = true;
71 break;
72 }
73 }
74
75 if (!$permission_ok && !$write_permission_ok) {
76 return $this->__raiseError(
77 'No permission to edit the object with id: ' . $ref_id,
78 'Server'
79 );
80 }
81
82 try {
83 include_once './Modules/WebResource/classes/class.ilWebLinkXmlWriter.php';
84 $writer = new ilWebLinkXmlWriter();
85 $writer->setObjId($obj_id);
86 $writer->write();
87
88 return $writer->xmlDumpMem(true);
90 return $this->__raiseError($e->getMessage(), 'Client');
91 }
92 }
93
103 public function createWebLink($sid, $target_id, $weblink_xml)
104 {
105 $this->initAuth($sid);
106 $this->initIlias();
107
108 if (!$this->__checkSession($sid)) {
109 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
110 }
111 global $DIC;
112
113 $rbacsystem = $DIC['rbacsystem'];
114 $tree = $DIC['tree'];
115 $ilLog = $DIC['ilLog'];
116
117 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($target_id, false)) {
118 return $this->__raiseError('No valid target given.', 'Client');
119 }
120
122 return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
123 }
124
125 // Check access
126 // TODO: read from object definition
127 $allowed_types = array('cat','grp','crs','fold','root');
128 if (!in_array($target_obj->getType(), $allowed_types)) {
129 return $this->__raiseError('No valid target type. Target must be reference id of "course, group, root, category or folder"', 'Client');
130 }
131
132 if (!$rbacsystem->checkAccess('create', $target_id, "webr")) {
133 return $this->__raiseError('No permission to create weblink in target ' . $target_id . '!', 'Client');
134 }
135
136
137 // create object, put it into the tree and use the parser to update the settings
138 include_once './Modules/WebResource/classes/class.ilObjLinkResource.php';
139 include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
140
141 $webl = new ilObjLinkResource();
142 $webl->setTitle('XML Import');
143 $webl->create(true);
144 $webl->createReference();
145 $webl->putInTree($target_id);
146 $webl->setPermissions($target_id);
147
148 try {
149 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
151 $parser->start();
152 } catch (ilSaxParserException $e) {
153 return $this->__raiseError($e->getMessage(), 'Client');
154 } catch (ilWebLinkXMLParserException $e) {
155 return $this->__raiseError($e->getMessage(), 'Client');
156 }
157
158 // Check if required
159 return $webl->getRefId();
160 }
161
171 public function updateWebLink($sid, $ref_id, $weblink_xml)
172 {
173 $this->initAuth($sid);
174 $this->initIlias();
175
176 if (!$this->__checkSession($sid)) {
177 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
178 }
179 global $DIC;
180
181 $rbacsystem = $DIC['rbacsystem'];
182 $tree = $DIC['tree'];
183 $ilLog = $DIC['ilLog'];
184
185 if (ilObject::_isInTrash($ref_id)) {
186 return $this->__raiseError('Cannot perform update since weblink has been deleted.', 'CLIENT_OBJECT_DELETED');
187 }
188 // get obj_id
189 if (!$obj_id = ilObject::_lookupObjectId($ref_id)) {
190 return $this->__raiseError(
191 'No weblink found for id: ' . $ref_id,
192 'CLIENT_OBJECT_NOT_FOUND'
193 );
194 }
195
196 // Check access
197 $permission_ok = false;
198 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
199 if ($rbacsystem->checkAccess('edit', $ref_id)) {
200 $permission_ok = true;
201 break;
202 }
203 }
204
205 if (!$permission_ok) {
206 return $this->__raiseError(
207 'No permission to edit the weblink with id: ' . $ref_id,
208 'Server'
209 );
210 }
211
212 $webl = ilObjectFactory::getInstanceByObjId($obj_id, false);
213 if (!is_object($webl) or $webl->getType()!= "webr") {
214 return $this->__raiseError(
215 'Wrong obj id or type for weblink with id ' . $ref_id,
216 'Client'
217 );
218 }
219
220 try {
221 include_once './Modules/WebResource/classes/class.ilWebLinkXmlParser.php';
222 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
224 $parser->start();
225 } catch (ilSaxParserException $e) {
226 return $this->__raiseError($e->getMessage(), 'Client');
227 } catch (ilWebLinkXMLParserException $e) {
228 return $this->__raiseError($e->getMessage(), 'Client');
229 }
230
231 // Check if required
232 return true;
233 }
234}
$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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46