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