ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSoapWebLinkAdministration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25{
26 public function __construct()
27 {
29 }
30
34 public function readWebLink(string $sid, int $request_ref_id)
35 {
36 $this->initAuth($sid);
37 $this->initIlias();
38
39 if (!$this->checkSession($sid)) {
40 return $this->raiseError($this->getMessage(), $this->getMessageCode());
41 }
42 if (!$request_ref_id) {
43 return $this->raiseError(
44 'No ref id given. Aborting!',
45 'Client'
46 );
47 }
48 global $DIC;
49
50 $rbacsystem = $DIC['rbacsystem'];
51 $tree = $DIC['tree'];
52 $ilLog = $DIC['ilLog'];
53
54 // get obj_id
55 if (!$obj_id = ilObject::_lookupObjectId($request_ref_id)) {
56 return $this->raiseError(
57 'No weblink found for id: ' . $request_ref_id,
58 'Client'
59 );
60 }
61
62 if (ilObject::_isInTrash($request_ref_id)) {
63 return $this->raiseError("Parent with ID $request_ref_id has been deleted.", 'Client');
64 }
65
66 // Check access
67 $permission_ok = false;
68 $write_permission_ok = false;
69 $ref_ids = ilObject::_getAllReferences($obj_id);
70 foreach ($ref_ids as $ref_id) {
71 if ($rbacsystem->checkAccess('edit', $ref_id)) {
72 $write_permission_ok = true;
73 break;
74 }
75 if ($rbacsystem->checkAccess('read', $ref_id)) {
76 $permission_ok = true;
77 break;
78 }
79 }
80
81 if (!$permission_ok && !$write_permission_ok) {
82 return $this->raiseError(
83 'No permission to edit the object with id: ' . $request_ref_id,
84 'Server'
85 );
86 }
87
88 try {
89 $writer = new ilWebLinkXmlWriter(true);
90 $writer->setObjId($obj_id);
91 $writer->write();
92
93 return $writer->xmlDumpMem(true);
94 } catch (UnexpectedValueException $e) {
95 return $this->raiseError($e->getMessage(), 'Client');
96 }
97 }
98
102 public function createWebLink(string $sid, int $target_id, string $weblink_xml)
103 {
104 $this->initAuth($sid);
105 $this->initIlias();
106
107 if (!$this->checkSession($sid)) {
108 return $this->raiseError($this->getMessage(), $this->getMessageCode());
109 }
110 global $DIC;
111
112 $rbacsystem = $DIC['rbacsystem'];
113 $tree = $DIC['tree'];
114 $ilLog = $DIC['ilLog'];
115
116 if (!$target_obj = ilObjectFactory::getInstanceByRefId($target_id, false)) {
117 return $this->raiseError('No valid target given.', 'Client');
118 }
119
120 if (ilObject::_isInTrash($target_id)) {
121 return $this->raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
122 }
123
124 // Check access
125 // TODO: read from object definition
126 $allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
127 if (!in_array($target_obj->getType(), $allowed_types)) {
128 return $this->raiseError(
129 'No valid target type. Target must be reference id of "course, group, root, category or folder"',
130 'Client'
131 );
132 }
133
134 if (!$rbacsystem->checkAccess('create', $target_id, "webr")) {
135 return $this->raiseError('No permission to create weblink in target ' . $target_id . '!', 'Client');
136 }
137
138 // create object, put it into the tree and use the parser to update the settings
139 $webl = new ilObjLinkResource();
140 $webl->setTitle('XML Import');
141 $webl->create();
142 $webl->createReference();
143 $webl->putInTree($target_id);
144 $webl->setPermissions($target_id);
145
146 try {
147 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
148 $parser->setMode(ilWebLinkXmlParser::MODE_CREATE);
149 $parser->start();
151 return $this->raiseError($e->getMessage(), 'Client');
152 }
153
154 // Check if required
155 return $webl->getRefId();
156 }
157
161 public function updateWebLink(string $sid, int $request_ref_id, string $weblink_xml)
162 {
163 $this->initAuth($sid);
164 $this->initIlias();
165
166 if (!$this->checkSession($sid)) {
167 return $this->raiseError($this->getMessage(), $this->getMessageCode());
168 }
169 global $DIC;
170
171 $rbacsystem = $DIC['rbacsystem'];
172 $tree = $DIC['tree'];
173 $ilLog = $DIC['ilLog'];
174
175 if (ilObject::_isInTrash($request_ref_id)) {
176 return $this->raiseError(
177 'Cannot perform update since weblink has been deleted.',
178 'CLIENT_OBJECT_DELETED'
179 );
180 }
181 // get obj_id
182 if (!$obj_id = ilObject::_lookupObjectId($request_ref_id)) {
183 return $this->raiseError(
184 'No weblink found for id: ' . $request_ref_id,
185 'CLIENT_OBJECT_NOT_FOUND'
186 );
187 }
188
189 // Check access
190 $permission_ok = false;
191 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
192 if ($rbacsystem->checkAccess('edit', $ref_id)) {
193 $permission_ok = true;
194 break;
195 }
196 }
197
198 if (!$permission_ok) {
199 return $this->raiseError(
200 'No permission to edit the weblink with id: ' . $request_ref_id,
201 'Server'
202 );
203 }
204
205 $webl = ilObjectFactory::getInstanceByObjId($obj_id, false);
206 if (!$webl instanceof ilObjLinkResource) {
207 return $this->raiseError(
208 'Wrong obj id or type for weblink with id ' . $request_ref_id,
209 'Client'
210 );
211 }
212
213 try {
215 $parser = new ilWebLinkXmlParser($webl, $weblink_xml);
216 $parser->setMode(ilWebLinkXmlParser::MODE_UPDATE);
217 $parser->start();
219 return $this->raiseError($e->getMessage(), 'Client');
220 }
221
222 // Check if required
223 return true;
224 }
225}
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _isInTrash(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
raiseError(string $a_message, $a_code)
Soap methods for adminstrating web links.
readWebLink(string $sid, int $request_ref_id)
updateWebLink(string $sid, int $request_ref_id, string $weblink_xml)
createWebLink(string $sid, int $target_id, string $weblink_xml)
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26