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