ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSoapObjectAdministration.php
Go to the documentation of this file.
1<?php
2 /*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22 */
23
24
34include_once './webservice/soap/classes/class.ilSoapAdministration.php';
35
37{
46 public function addDesktopItems($sid, $user_id, $reference_ids)
47 {
48 $this->initAuth($sid);
49 $this->initIlias();
50
51 if (!$this->__checkSession($sid)) {
52 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
53 }
54
55 global $DIC;
56
57 $access = $DIC->rbac()->system();
58 $logger = $DIC->logger()->wsrv();
59
60 if (!$access->checkAccess('edit_userassignment', ROLE_FOLDER_ID)) {
61 $logger->warning('Missing permission "edit_userassignment".');
62 return $this->__raiseError(
63 'Missing permission "edit_userassignment".',
64 'Client'
65 );
66 }
67
69 if (!$user instanceof ilObjUser) {
70 $logger->warning('Invalid user id given. Cannot instantiate user for id: ' . $user_id);
71 return $this->__raiseError(
72 'Invalid user id given. Cannot instantiate user for id: ' . $user_id,
73 'Client'
74 );
75 }
76 $num_added = 0;
77 foreach ($reference_ids as $ref_id) {
78 // short "validation" of reference id
79 $ref_obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
80 if (!$ref_obj instanceof ilObject) {
81 $logger->warning('Invalid reference id passed to SOAP::addDesktopItems: ' . $ref_id);
82 continue;
83 }
84
85 $num_added++;
87 $user->getId(),
88 $ref_id,
89 ilObject::_lookupType($ref_id, true)
90 );
91 }
92 return $num_added;
93 }
94
103 public function removeDesktopItems($sid, $user_id, $reference_ids)
104 {
105 $this->initAuth($sid);
106 $this->initIlias();
107
108 if (!$this->__checkSession($sid)) {
109 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
110 }
111
112 global $DIC;
113
114 $access = $DIC->rbac()->system();
115 $logger = $DIC->logger()->wsrv();
116
117 if (!$access->checkAccess('edit_userassignment', ROLE_FOLDER_ID)) {
118 $logger->warning('Missing permission "edit_userassignment".');
119 return $this->__raiseError(
120 'Missing permission "edit_userassignment".',
121 'Client'
122 );
123 }
124
126 if (!$user instanceof ilObjUser) {
127 $logger->warning('Invalid user id given. Cannot instantiate user for id: ' . $user_id);
128 return $this->__raiseError(
129 'Invalid user id given. Cannot instantiate user for id: ' . $user_id,
130 'Client'
131 );
132 }
133 $num_removed = 0;
134 foreach ($reference_ids as $ref_id) {
135 // short "validation" of reference id
136 $ref_obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
137 if (!$ref_obj instanceof ilObject) {
138 $logger->warning('Invalid reference id passed to SOAP::removeDesktopItems: ' . $ref_id);
139 continue;
140 }
141
142 $num_added++;
144 $user->getId(),
145 $ref_id,
146 ilObject::_lookupType($ref_id, true)
147 );
148 }
149 return $num_removed;
150 }
151
152
153 public function getObjIdByImportId($sid, $import_id)
154 {
155 $this->initAuth($sid);
156 $this->initIlias();
157
158 if (!$this->__checkSession($sid)) {
159 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
160 }
161 if (!$import_id) {
162 return $this->__raiseError(
163 'No import id given.',
164 'Client'
165 );
166 }
167
168 global $DIC;
169
170 $ilLog = $DIC['ilLog'];
171
172 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
173 $ilLog->write("SOAP getObjIdByImportId(): import_id = " . $import_id . ' obj_id = ' . $obj_id);
174
175 return $obj_id ? $obj_id : "0";
176 }
177
178 public function getRefIdsByImportId($sid, $import_id)
179 {
180 $this->initAuth($sid);
181 $this->initIlias();
182
183 if (!$this->__checkSession($sid)) {
184 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
185 }
186 if (!$import_id) {
187 return $this->__raiseError(
188 'No import id given.',
189 'Client'
190 );
191 }
192
193 global $DIC;
194
195 $tree = $DIC['tree'];
196
197 $obj_id = ilObject::_lookupObjIdByImportId($import_id);
198
199
200 $ref_ids = ilObject::_getAllReferences($obj_id);
201
202 foreach ($ref_ids as $ref_id) {
203 // only get non deleted reference ids
204 if ($tree->isInTree($ref_id)) {
205 $new_refs[] = $ref_id;
206 }
207 }
208 return $new_refs ? $new_refs : array();
209 }
210
211 public function getRefIdsByObjId($sid, $obj_id)
212 {
213 $this->initAuth($sid);
214 $this->initIlias();
215
216 if (!$this->__checkSession($sid)) {
217 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
218 }
219 if (!$obj_id) {
220 return $this->__raiseError(
221 'No object id given.',
222 'Client'
223 );
224 }
225
226 $ref_ids = ilObject::_getAllReferences($obj_id);
227 foreach ($ref_ids as $ref_id) {
228 $new_refs[] = $ref_id;
229 }
230 return $new_refs ? $new_refs : array();
231 }
232
241 public function getObjIdsByRefIds($sid, $ref_ids)
242 {
243 $this->initAuth($sid);
244 $this->initIlias();
245
246 if (!$this->__checkSession($sid)) {
247 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
248 }
249
250
251 if (!count($ref_ids) || !is_array($ref_ids)) {
252 return $this->__raiseError('No reference id(s) given.', 'Client');
253 }
254
255 $obj_ids = array();
256 if (count($ref_ids)) {
257 foreach ($ref_ids as $ref_id) {
258 $ref_id = trim($ref_id);
259 if (!is_numeric($ref_id)) {
260 return $this->__raiseError('Reference ID has to be numeric. Value: ' . $ref_id, 'Client');
261 }
262
263 $obj_id = ilObject::_lookupObjectId($ref_id);
264 if (!$obj_id) {
265 return $this->__raiseError('No object found for reference ID. Value: ' . $ref_id, 'Client');
266 }
267 if (!ilObject::_hasUntrashedReference($obj_id)) {
268 return $this->__raiseError('No untrashed reference found for reference ID. Value: ' . $ref_id, 'Client');
269 }
270 $obj_ids[] = $obj_id;
271 }
272 }
273 return $obj_ids;
274 }
275
276
277
278 public function getObjectByReference($sid, $a_ref_id, $user_id)
279 {
280 $this->initAuth($sid);
281 $this->initIlias();
282
283 if (!$this->__checkSession($sid)) {
284 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
285 }
286 if (!is_numeric($a_ref_id)) {
287 return $this->__raiseError(
288 'No valid reference id given. Please choose an existing reference id of an ILIAS object',
289 'Client'
290 );
291 }
292
293 if (!$tmp_obj = ilObjectFactory::getInstanceByRefId($a_ref_id, false)) {
294 return $this->__raiseError('Cannot create object instance!', 'Server');
295 }
296
297
298 if (ilObject::_isInTrash($a_ref_id)) {
299 return $this->__raiseError("Object with ID $a_ref_id has been deleted.", 'Client');
300 }
301
302 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
303
304 $xml_writer = new ilObjectXMLWriter();
305 $xml_writer->enablePermissionCheck(true);
306 if ($user_id) {
307 $xml_writer->setUserId($user_id);
308 $xml_writer->enableOperations(true);
309 }
310 $xml_writer->setObjects(array($tmp_obj));
311 if ($xml_writer->start()) {
312 return $xml_writer->getXML();
313 }
314
315 return $this->__raiseError('Cannot create object xml !', 'Server');
316 }
317
318 public function getObjectsByTitle($sid, $a_title, $user_id)
319 {
320 $this->initAuth($sid);
321 $this->initIlias();
322
323 if (!$this->__checkSession($sid)) {
324 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
325 }
326 if (!strlen($a_title)) {
327 return $this->__raiseError(
328 'No valid query string given.',
329 'Client'
330 );
331 }
332
333 include_once './Services/Search/classes/class.ilQueryParser.php';
334
335 $query_parser = new ilQueryParser($a_title);
336 $query_parser->setMinWordLength(0, true);
337 $query_parser->setCombination(QP_COMBINATION_AND);
338 $query_parser->parse();
339 if (!$query_parser->validate()) {
340 return $this->__raiseError(
341 $query_parser->getMessage(),
342 'Client'
343 );
344 }
345
346 include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
347
348 include_once 'Services/Search/classes/Like/class.ilLikeObjectSearch.php';
349 $object_search = new ilLikeObjectSearch($query_parser);
350
351 #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
352 $object_search->setFields(array('title'));
353 $object_search->appendToFilter('role');
354 $object_search->appendToFilter('rolt');
355 $res =&$object_search->performSearch();
356 if ($user_id) {
357 $res->setUserId($user_id);
358 }
359
360 $res->filter(ROOT_FOLDER_ID, true);
361
362 $objs = array();
363 foreach ($res->getUniqueResults() as $entry) {
364 if ($entry['type'] == 'role' or $entry['type'] == 'rolt') {
365 if ($tmp = ilObjectFactory::getInstanceByObjId($entry['obj_id'], false)) {
366 $objs[] = $tmp;
367 }
368 continue;
369 }
370 if ($tmp = ilObjectFactory::getInstanceByRefId($entry['ref_id'], false)) {
371 $objs[] = $tmp;
372 }
373 }
374 if (!count($objs)) {
375 return '';
376 }
377
378 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
379
380 $xml_writer = new ilObjectXMLWriter();
381 $xml_writer->enablePermissionCheck(true);
382 if ($user_id) {
383 $xml_writer->setUserId($user_id);
384 $xml_writer->enableOperations(true);
385 }
386 $xml_writer->setObjects($objs);
387 if ($xml_writer->start()) {
388 return $xml_writer->getXML();
389 }
390
391 return $this->__raiseError('Cannot create object xml !', 'Server');
392 }
393
394 public function searchObjects($sid, $types, $key, $combination, $user_id)
395 {
396 $this->initAuth($sid);
397 $this->initIlias();
398
399 if (!$this->__checkSession($sid)) {
400 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
401 }
402 if (!is_array($types)) {
403 return $this->__raiseError(
404 'Types must be an array of object types.',
405 'Client'
406 );
407 }
408 if ($combination != 'and' and $combination != 'or') {
409 return $this->__raiseError(
410 'No valid combination given. Must be "and" or "or".',
411 'Client'
412 );
413 }
414
415 // begin-patch fm
416 include_once './Services/Search/classes/class.ilSearchSettings.php';
417 if (ilSearchSettings::getInstance()->enabledLucene()) {
418 ilSearchSettings::getInstance()->setMaxHits(25);
419
420 $typeFilterQuery = '';
421 if (is_array($types)) {
422 foreach ($types as $objectType) {
423 if (0 === strlen($typeFilterQuery)) {
424 $typeFilterQuery .= '+( ';
425 } else {
426 $typeFilterQuery .= 'OR';
427 }
428 $typeFilterQuery .= (' type:' . (string) $objectType . ' ');
429 }
430 $typeFilterQuery .= ') ';
431 }
432
433 include_once './Services/Search/classes/Lucene/class.ilLuceneQueryParser.php';
434 $query_parser = new ilLuceneQueryParser($typeFilterQuery . $key);
435 $query_parser->parse();
436
437 include_once './Services/Search/classes/Lucene/class.ilLuceneSearcher.php';
438 $searcher = ilLuceneSearcher::getInstance($query_parser);
439 $searcher->search();
440
441 include_once './Services/Search/classes/Lucene/class.ilLuceneSearchResultFilter.php';
442 include_once './Services/Search/classes/Lucene/class.ilLucenePathFilter.php';
443 $filter = ilLuceneSearchResultFilter::getInstance($user_id);
444 $filter->setCandidates($searcher->getResult());
445 $filter->filter();
446
447 $result_ids = $filter->getResults();
448 $objs = array();
449 $objs[ROOT_FOLDER_ID] = ilObjectFactory::getInstanceByRefId(ROOT_FOLDER_ID, false);
450 foreach ((array) $result_ids as $ref_id => $obj_id) {
451 $obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
452 if ($obj instanceof ilObject) {
453 $objs[] = $obj;
454 }
455 }
456 include_once './Services/Search/classes/Lucene/class.ilLuceneHighlighterResultParser.php';
457 $highlighter = new ilLuceneHighlighterResultParser();
458 if ($filter->getResultObjIds()) {
459 $highlighter = $searcher->highlight($filter->getResultObjIds());
460 }
461 } else {
462 include_once './Services/Search/classes/class.ilQueryParser.php';
463
464 $query_parser = new ilQueryParser($key);
465 #$query_parser->setMinWordLength(3);
466 $query_parser->setCombination($combination == 'and' ? QP_COMBINATION_AND : QP_COMBINATION_OR);
467 $query_parser->parse();
468 if (!$query_parser->validate()) {
469 return $this->__raiseError(
470 $query_parser->getMessage(),
471 'Client'
472 );
473 }
474
475 #include_once './Services/Search/classes/class.ilObjectSearchFactory.php';
476 #$object_search =& ilObjectSearchFactory::_getObjectSearchInstance($query_parser);
477
478 include_once './Services/Search/classes/Like/class.ilLikeObjectSearch.php';
479 $object_search = new ilLikeObjectSearch($query_parser);
480
481 $object_search->setFilter($types);
482
483 $res =&$object_search->performSearch();
484 if ($user_id) {
485 $res->setUserId($user_id);
486 }
487 // begin-patch fm
488 $res->setMaxHits(100);
489 // begin-patch fm
490 $res->filter(ROOT_FOLDER_ID, $combination == 'and' ? true : false);
491
492 $counter = 0;
493 $objs = array();
494 foreach ($res->getUniqueResults() as $entry) {
495 $obj = ilObjectFactory::getInstanceByRefId($entry['ref_id'], false);
496 if ($obj instanceof ilObject) {
497 $objs[] = $obj;
498 }
499 }
500 }
501
502 if (!count($objs)) {
503 return '';
504 }
505
506 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
507
508 $xml_writer = new ilObjectXMLWriter();
509
510 // begin-patch fm
511 if (ilSearchSettings::getInstance()->enabledLucene()) {
512 $xml_writer->enableReferences(false);
513 $xml_writer->setMode(ilObjectXmlWriter::MODE_SEARCH_RESULT);
514 $xml_writer->setHighlighter($highlighter);
515 }
516
517 $xml_writer->enablePermissionCheck(true);
518
519 if ($user_id) {
520 $xml_writer->setUserId($user_id);
521 $xml_writer->enableOperations(true);
522 }
523
524 $xml_writer->setObjects($objs);
525 if ($xml_writer->start()) {
526 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': '.$xml_writer->xmlDumpMem(true));
527 return $xml_writer->getXML();
528 }
529
530 return $this->__raiseError('Cannot create object xml !', 'Server');
531 }
532
533 public function getTreeChilds($sid, $ref_id, $types, $user_id)
534 {
535 $this->initAuth($sid);
536 $this->initIlias();
537
538 if (!$this->__checkSession($sid)) {
539 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
540 }
541
542 $all = false;
543
544 global $DIC;
545
546 $tree = $DIC['tree'];
547
548 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($ref_id, false)) {
549 return $this->__raiseError(
550 'No valid reference id given.',
551 'Client'
552 );
553 }
554 if (intval($ref_id) == SYSTEM_FOLDER_ID) {
555 return $this->__raiseError(
556 'No valid reference id given.',
557 'Client'
558 );
559 }
560
561 if (!$types) {
562 $all = true;
563 }
564
565 $objs = array();
566
567 // begin-patch filemanager
568 include_once './Services/WebServices/FileManager/classes/class.ilFMSettings.php';
569 if (in_array('parent', (array) $types)) {
570 $objs[] = $target_obj;
571 }
572 // end-patch filemanager
573
574 foreach ($tree->getChilds($ref_id, 'title') as $child) {
575 if ($all or in_array($child['type'], $types)) {
576 if ($tmp = ilObjectFactory::getInstanceByRefId($child['ref_id'], false)) {
577 $objs[] = $tmp;
578 }
579 }
580 }
581
582 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
583
584 $xml_writer = new ilObjectXMLWriter();
585 // begin-patch filemanager
586 if (ilFMSettings::getInstance()->isEnabled()) {
587 $xml_writer->enableReferences(false);
588 }
589 // end-patch filemanager
590 $xml_writer->enablePermissionCheck(true);
591 $xml_writer->setObjects($objs);
592 $xml_writer->enableOperations(true);
593 if ($user_id) {
594 $xml_writer->setUserId($user_id);
595 }
596
597 if ($xml_writer->start()) {
598 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': '.$xml_writer->getXML());
599 return $xml_writer->getXML();
600 }
601
602 return $this->__raiseError('Cannot create object xml !', 'Server');
603 }
604
605 public function getXMLTree($sid, $ref_id, $types, $user_id)
606 {
607 $this->initAuth($sid);
608 $this->initIlias();
609
610 if (!$this->__checkSession($sid)) {
611 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
612 }
613
614 global $DIC;
615
616 $tree = $DIC['tree'];
617
618 $nodedata = $tree->getNodeData($ref_id);
619 $nodearray = $tree->getSubTree($nodedata);
620
621
622 $filter = (array) $types;
623
624 global $DIC;
625
626 $objDefinition = $DIC['objDefinition'];
627 foreach ($nodearray as $node) {
628 if (!$objDefinition->isAdministrationObject($node['type']) && !$objDefinition->isSystemObject($node['type'])) {
629 if (!in_array($node['type'], $filter)) {
630 if ($tmp = ilObjectFactory::getInstanceByRefId($node['ref_id'], false)) {
631 $nodes[] = $tmp;
632 }
633 }
634 }
635 }
636
637
638 include_once './webservice/soap/classes/class.ilObjectXMLWriter.php';
639
640 $xml_writer = new ilObjectXMLWriter();
641 $xml_writer->enablePermissionCheck(true);
642 $xml_writer->setObjects($nodes);
643 $xml_writer->enableOperations(false);
644
645 if ($user_id) {
646 $xml_writer->setUserId($user_id);
647 }
648
649 if ($xml_writer->start()) {
650 return $xml_writer->getXML();
651 }
652
653 return $this->__raiseError('Cannot create object xml !', 'Server');
654 }
655
656 public function addObject($sid, $a_target_id, $a_xml)
657 {
658 $this->initAuth($sid);
659 $this->initIlias();
660
661 if (!$this->__checkSession($sid)) {
662 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
663 }
664 if (!strlen($a_xml)) {
665 return $this->__raiseError(
666 'No valid xml string given.',
667 'Client'
668 );
669 }
670
671 global $DIC;
672
673 $rbacsystem = $DIC['rbacsystem'];
674 $objDefinition = $DIC['objDefinition'];
675 $ilUser = $DIC['ilUser'];
676 $lng = $DIC['lng'];
677 $ilObjDataCache = $DIC['ilObjDataCache'];
678
679 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($a_target_id, false)) {
680 return $this->__raiseError(
681 'No valid target given.',
682 'Client'
683 );
684 }
685
686 if (ilObject::_isInTrash($a_target_id)) {
687 return $this->__raiseError("Parent with ID $a_target_id has been deleted.", 'Client');
688 }
689
690 $allowed_types = array('root','cat','grp','crs','fold');
691 if (!in_array($target_obj->getType(), $allowed_types)) {
692 return $this->__raiseError(
693 'No valid target type. Target must be reference id of "course, group, category or folder"',
694 'Client'
695 );
696 }
697
698 $allowed_subtypes = $target_obj->getPossibleSubObjects();
699
700 foreach ($allowed_subtypes as $row) {
701 if ($row['name'] != 'rolf') {
702 $allowed[] = $row['name'];
703 }
704 }
705
706 include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
707
708 $xml_parser = new ilObjectXMLParser($a_xml, true);
709 try {
710 $xml_parser->startParsing();
711 } catch (ilSaxParserException $se) {
712 return $this->__raiseError($se->getMessage(), 'Client');
713 } catch (ilObjectXMLException $e) {
714 return $this->__raiseError($e->getMessage(), 'Client');
715 }
716
717 foreach ($xml_parser->getObjectData() as $object_data) {
718 $res = $this->validateReferences('create', $object_data, $a_target_id);
719 if ($this->isFault($res)) {
720 return $res;
721 }
722
723 // Check possible subtype
724 if (!in_array($object_data['type'], $allowed)) {
725 return $this->__raiseError(
726 'Objects of type: ' . $object_data['type'] . ' are not allowed to be subobjects of type ' .
727 $target_obj->getType() . '!',
728 'Client'
729 );
730 }
731 if (!$rbacsystem->checkAccess('create', $a_target_id, $object_data['type'])) {
732 return $this->__raiseError(
733 'No permission to create objects of type ' . $object_data['type'] . '!',
734 'Client'
735 );
736 }
737 // begin-patch fm
738 /*
739 if($object_data['type'] == 'crs')
740 {
741 return $this->__raiseError('Cannot create course objects. Use method addCourse() ',
742 'Client');
743 }
744 */
745 // end-patch fm
746
747 // It's not possible to add objects with non unique import ids
748 if (strlen($object_data['import_id']) and ilObject::_lookupObjIdByImportId($object_data['import_id'])) {
749 return $this->__raiseError(
750 'An object with import id ' . $object_data['import_id'] . ' already exists!',
751 'Server'
752 );
753 }
754
755 // call gui object method
756 $class_name = $objDefinition->getClassName($object_data['type']);
757 $location = $objDefinition->getLocation($object_data['type']);
758
759 $class_constr = "ilObj" . $class_name;
760 require_once($location . "/class.ilObj" . $class_name . ".php");
761
762 $newObj = new $class_constr();
763
764 if (isset($object_data['owner']) && strlen($object_data['owner'])) {
765 if ((int) $object_data['owner']) {
766 if (ilObject::_exists((int) $object_data['owner']) &&
767 $ilObjDataCache->lookupType((int) $object_data['owner']) == 'usr') {
768 $newObj->setOwner((int) $object_data['owner']);
769 }
770 } else {
771 $usr_id = ilObjUser::_lookupId(trim($object_data['owner']));
772 if ((int) $usr_id) {
773 $newObj->setOwner((int) $usr_id);
774 }
775 }
776 }
777
778 $newObj->setType($object_data['type']);
779 if (strlen($object_data['import_id'])) {
780 $newObj->setImportId($object_data['import_id']);
781 }
782
783 if ($objDefinition->supportsOfflineHandling($newObj->getType())) {
784 $newObj->setOfflineStatus((bool) $object_data['offline']);
785 }
786 $newObj->setTitle($object_data['title']);
787 $newObj->setDescription($object_data['description']);
788 $newObj->create(); // true for upload
789 $newObj->createReference();
790 $newObj->putInTree($a_target_id);
791 $newObj->setPermissions($a_target_id);
792
793 switch ($object_data['type']) {
794 case 'grp':
795 // Add member
796 $newObj->addMember(
797 $object_data['owner'] ? $object_data['owner'] : $ilUser->getId(),
798 $newObj->getDefaultAdminRole()
799 );
800 break;
801
802 // begin-patch fm
803 case 'crs':
804 $newObj->getMemberObject()->add($ilUser->getId(), IL_CRS_ADMIN);
805 break;
806 // end-patch fm
807 case 'lm':
808 $newObj->createLMTree();
809 break;
810 case 'cat':
812 $newObj->addTranslation($object_data["title"], $object_data["description"], $lng->getLangKey(), true);
813 break;
814 }
815
816 $this->addReferences($newObj, $object_data);
817 }
818 $ref_id = $newObj->getRefId();
819 return $ref_id ? $ref_id : "0";
820 }
821
822 public function addReference($sid, $a_source_id, $a_target_id)
823 {
824 $this->initAuth($sid);
825 $this->initIlias();
826
827 if (!$this->__checkSession($sid)) {
828 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
829 }
830 if (!is_numeric($a_source_id)) {
831 return $this->__raiseError(
832 'No source id given.',
833 'Client'
834 );
835 }
836 if (!is_numeric($a_target_id)) {
837 return $this->__raiseError(
838 'No target id given.',
839 'Client'
840 );
841 }
842
843 global $DIC;
844
845 $objDefinition = $DIC['objDefinition'];
846 $rbacsystem = $DIC['rbacsystem'];
847 $tree = $DIC['tree'];
848
849 if (!$source_obj =&ilObjectFactory::getInstanceByRefId($a_source_id, false)) {
850 return $this->__raiseError(
851 'No valid source id given.',
852 'Client'
853 );
854 }
855 if (!$target_obj =&ilObjectFactory::getInstanceByRefId($a_target_id, false)) {
856 return $this->__raiseError(
857 'No valid target id given.',
858 'Client'
859 );
860 }
861
862 if (!$objDefinition->allowLink($source_obj->getType()) and
863 $source_obj->getType() != 'cat' and
864 $source_obj->getType() != 'crs') {
865 return $this->__raiseError(
866 'Linking of object type: ' . $source_obj->getType() . ' is not allowed',
867 'Client'
868 );
869 }
870
871 $allowed_subtypes = $target_obj->getPossibleSubObjects();
872 foreach ($allowed_subtypes as $row) {
873 if ($row['name'] != 'rolf') {
874 $allowed[] = $row['name'];
875 }
876 }
877 if (!in_array($source_obj->getType(), $allowed)) {
878 return $this->__raiseError(
879 'Objects of type: ' . $source_obj->getType() . ' are not allowed to be subobjects of type ' .
880 $target_obj->getType() . '!',
881 'Client'
882 );
883 }
884
885 // Permission checks
886 if (!$rbacsystem->checkAccess('create', $target_obj->getRefId(), $source_obj->getType())) {
887 return $this->__raiseError(
888 'No permission to create objects of type ' . $source_obj->getType() . '!',
889 'Client'
890 );
891 }
892 if (!$rbacsystem->checkAccess('delete', $source_obj->getRefId())) {
893 return $this->__raiseError(
894 'No permission to link object with id: ' . $source_obj->getRefId() . '!',
895 'Client'
896 );
897 }
898
899
900 if ($source_obj->getType() != 'cat' and $source_obj->getType() != 'crs') {
901 // check if object already linked to target
902 $possibleChilds = $tree->getChildsByType($target_obj->getRefId(), $source_obj->getType());
903 foreach ($possibleChilds as $child) {
904 if ($child["obj_id"] == $source_obj->getId()) {
905 return $this->__raiseError("Object already linked to target.", "Client");
906 }
907 }
908
909 // Finally link it to target position
910
911 $new_ref_id = $source_obj->createReference();
912 $source_obj->putInTree($target_obj->getRefId());
913 $source_obj->setPermissions($target_obj->getRefId());
914
915 return $new_ref_id ? $new_ref_id : "0";
916 } else {
917 switch ($source_obj->getType()) {
918 case 'cat':
919 include_once('./Modules/CategoryReference/classes/class.ilObjCategoryReference.php');
920 $new_ref = new ilObjCategoryReference();
921 break;
922
923 case 'crs':
924 include_once('./Modules/CourseReference/classes/class.ilObjCourseReference.php');
925 $new_ref = new ilObjCourseReference();
926 break;
927 case 'grp':
928 include_once('./Modules/GroupReference/classes/class.ilObjGroupReference.php');
929 $new_ref = new ilObjGroupReference();
930 break;
931 }
932 $new_ref->create();
933 $new_ref_id = $new_ref->createReference();
934
935 $new_ref->putInTree($target_obj->getRefId());
936 $new_ref->setPermissions($target_obj->getRefId());
937
938 $new_ref->setTargetId($source_obj->getId());
939 $new_ref->update();
940
941 return $new_ref_id ? $new_ref_id : 0;
942 }
943 }
944
945 public function deleteObject($sid, $reference_id)
946 {
947 $this->initAuth($sid);
948 $this->initIlias();
949
950 if (!$this->__checkSession($sid)) {
951 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
952 }
953 if (!is_numeric($reference_id)) {
954 return $this->__raiseError(
955 'No reference id given.',
956 'Client'
957 );
958 }
959 global $DIC;
960
961 $tree = $DIC['tree'];
962 $rbacsystem = $DIC['rbacsystem'];
963 $rbacadmin = $DIC['rbacadmin'];
964
965 if (!$del_obj =&ilObjectFactory::getInstanceByRefId($reference_id, false)) {
966 return $this->__raiseError(
967 'No valid reference id given.',
968 'Client'
969 );
970 }
971 if (!$rbacsystem->checkAccess('delete', $del_obj->getRefId())) {
972 return $this->__raiseError(
973 'No permission to delete object with id: ' . $del_obj->getRefId() . '!',
974 'Client'
975 );
976 }
977
978 // Delete tree
979 if ($tree->isDeleted($reference_id)) {
980 return $this->__raiseError('Node already deleted', 'Server');
981 }
982
983 if ($del_obj->getType() == 'rolf') {
984 return $this->__raiseError('Delete is not available for role folders.', 'Client');
985 }
986
987 $subnodes = $tree->getSubtree($tree->getNodeData($reference_id));
988 foreach ($subnodes as $subnode) {
989 $rbacadmin->revokePermission($subnode["child"]);
990 // remove item from all user desktops
991 $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
992 }
993 if (!$tree->saveSubTree($reference_id, true)) {
994 return $this->__raiseError('Node already deleted', 'Client');
995 }
996
997 return true;
998 }
999
1000 public function removeFromSystemByImportId($sid, $import_id)
1001 {
1002 $this->initAuth($sid);
1003 $this->initIlias();
1004
1005 if (!$this->__checkSession($sid)) {
1006 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
1007 }
1008 if (!strlen($import_id)) {
1009 return $this->__raiseError(
1010 'No import id given. Aborting!',
1011 'Client'
1012 );
1013 }
1014 global $DIC;
1015
1016 $rbacsystem = $DIC['rbacsystem'];
1017 $tree = $DIC['tree'];
1018 $ilLog = $DIC['ilLog'];
1019
1020 // get obj_id
1021 if (!$obj_id = ilObject::_lookupObjIdByImportId($import_id)) {
1022 return $this->__raiseError(
1023 'No object found with import id: ' . $import_id,
1024 'Client'
1025 );
1026 }
1027
1028 // Check access
1029 $permission_ok = false;
1030 foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
1031 if ($rbacsystem->checkAccess('delete', $ref_id)) {
1032 $permission_ok = true;
1033 break;
1034 }
1035 }
1036 if (!$permission_ok) {
1037 return $this->__raiseError(
1038 'No permission to delete the object with import id: ' . $import_id,
1039 'Server'
1040 );
1041 }
1042
1043 // Delete all references (delete permssions and entries in object_reference)
1044 foreach ($ref_ids as $ref_id) {
1045 // All subnodes
1046 $node_data = $tree->getNodeData($ref_id);
1047 $subtree_nodes = $tree->getSubtree($node_data);
1048
1049 foreach ($subtree_nodes as $node) {
1050 $ilLog->write('Soap: removeFromSystemByImportId(). Deleting object with title id: ' . $node['title']);
1051 $tmp_obj = ilObjectFactory::getInstanceByRefId($node['ref_id']);
1052 if (!is_object($tmp_obj)) {
1053 return $this->__raiseError(
1054 'Cannot create instance of reference id: ' . $node['ref_id'],
1055 'Server'
1056 );
1057 }
1058 $tmp_obj->delete();
1059 }
1060 // Finally delete tree
1061 $tree->deleteTree($node_data);
1062 }
1063
1064 return true;
1065 }
1066
1067
1068 public function updateObjects($sid, $a_xml)
1069 {
1070 $this->initAuth($sid);
1071 $this->initIlias();
1072
1073 if (!$this->__checkSession($sid)) {
1074 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
1075 }
1076 if (!strlen($a_xml)) {
1077 return $this->__raiseError(
1078 'No valid xml string given.',
1079 'Client'
1080 );
1081 }
1082
1083 global $DIC;
1084
1085 $rbacreview = $DIC['rbacreview'];
1086 $rbacsystem = $DIC['rbacsystem'];
1087 $lng = $DIC['lng'];
1088 $ilAccess = $DIC['ilAccess'];
1089 $objDefinition = $DIC['objDefinition'];
1090
1091 include_once './webservice/soap/classes/class.ilObjectXMLParser.php';
1092 $xml_parser = new ilObjectXMLParser($a_xml, true);
1093 try {
1094 $xml_parser->startParsing();
1095 } catch (ilSaxParserException $se) {
1096 return $this->__raiseError($se->getMessage(), 'Client');
1097 } catch (ilObjectXMLException $e) {
1098 return $this->__raiseError($e->getMessage(), 'Client');
1099 }
1100
1101
1102 // Validate incoming data
1103 $object_datas = $xml_parser->getObjectData();
1104 foreach ($object_datas as &$object_data) {
1105 $res = $this->validateReferences('update', $object_data);
1106 if ($this->isFault($res)) {
1107 return $res;
1108 }
1109
1110
1111 if (!$object_data["obj_id"]) {
1112 return $this->__raiseError('No obj_id in xml found.', 'Client');
1113 } elseif ((int) $object_data["obj_id"] == -1 && count($object_data["references"])>0) {
1114 // object id might be unknown, resolve references instead to determine object id
1115 // all references should point to the same object, so using the first one is ok.
1116 foreach ($object_data["references"] as $refid) {
1117 if (ilObject::_isInTrash($refid)) {
1118 continue;
1119 }
1120 break;
1121 }
1122
1123 $obj_id_from_refid = ilObject::_lookupObjectId($object_data["references"][0], false);
1124 if (!$obj_id_from_refid) {
1125 return $this->__raiseError('No obj_id found for reference id ' . $object_data["references"][0], 'CLIENT_OBJECT_NOT_FOUND');
1126 } else {
1127 $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
1128 $object_data["obj_id"] = $obj_id_from_refid;
1129 }
1130 }
1131
1132 $tmp_obj = ilObjectFactory::getInstanceByObjId($object_data['obj_id'], false);
1133 if ($tmp_obj == null) {
1134 return $this->__raiseError('No object for id ' . $object_data['obj_id'] . '!', 'CLIENT_OBJECT_NOT_FOUND');
1135 } else {
1136 $object_data["instance"] = $tmp_obj;
1137 }
1138
1139 if ($object_data['type'] == 'role') {
1140 $rolf_ids = $rbacreview->getFoldersAssignedToRole($object_data['obj_id'], true);
1141 $rolf_id = $rolf_ids[0];
1142
1143 if (!$rbacsystem->checkAccess('write', $rolf_id)) {
1144 return $this->__raiseError('No write permission for object with id ' . $object_data['obj_id'] . '!', 'Client');
1145 }
1146 } else {
1147 $permission_ok = false;
1148 foreach (ilObject::_getAllReferences($object_data['obj_id']) as $ref_id) {
1149 if ($ilAccess->checkAccess('write', '', $ref_id)) {
1150 $permission_ok = true;
1151 break;
1152 }
1153 }
1154 if (!$permission_ok) {
1155 return $this->__raiseError('No write permission for object with id ' . $object_data['obj_id'] . '!', 'Client');
1156 }
1157 }
1158 }
1159 // perform update
1160 if (count($object_datas) > 0) {
1161 foreach ($object_datas as $object_data) {
1162 $this->updateReferences($object_data);
1166 $tmp_obj = $object_data["instance"];
1167 $tmp_obj->setTitle($object_data['title']);
1168 $tmp_obj->setDescription($object_data['description']);
1169
1170 if ($objDefinition->supportsOfflineHandling($tmp_obj->getType())) {
1171 $tmp_obj->setOfflineStatus($object_data['offline']);
1172 }
1173
1174 $tmp_obj->update();
1175 if (strlen($object_data['owner']) && is_numeric($object_data['owner'])) {
1176 $tmp_obj->setOwner($object_data['owner']);
1177 $tmp_obj->updateOwner();
1178 }
1179 }
1180 return true;
1181 }
1182 return false;
1183 }
1184
1185 public function moveObject($sid, $ref_id, $target_id)
1186 {
1187 $this->initAuth($sid);
1188 $this->initIlias();
1189
1190 if (!$this->__checkSession($sid)) {
1191 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
1192 }
1193
1194 include_once './webservice/soap/classes/class.ilSoapUtils.php';
1195 global $DIC;
1196
1197 $rbacreview = $DIC['rbacreview'];
1198 $rbacadmin = $DIC['rbacadmin'];
1199 $objDefinition = $DIC['objDefinition'];
1200 $rbacsystem = $DIC['rbacsystem'];
1201 $lng = $DIC['lng'];
1202 $ilUser = $DIC['ilUser'];
1203 $tree = $DIC['tree'];
1204
1205 // does source object exist
1206 if (!$source_object_type = ilObjectFactory::getTypeByRefId($ref_id, false)) {
1207 return $this->__raiseError('No valid source given.', 'Client');
1208 }
1209
1210 // does target object exist
1211 if (!$target_object_type = ilObjectFactory::getTypeByRefId($target_id, false)) {
1212 return $this->__raiseError('No valid target given.', 'Client');
1213 }
1214
1215 // check for trash
1216 if (ilObject::_isInTrash($ref_id)) {
1217 return $this->__raiseError('Object is trashed.', 'Client');
1218 }
1219
1221 return $this->__raiseError('Object is trashed.', 'Client');
1222 }
1223
1224 $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1225 if ($this->isFault($canAddType)) {
1226 return $canAddType;
1227 }
1228
1229 // check if object already linked to target
1230 $possibleChilds = $tree->getChildsByType($target_id, $ref_id);
1231 foreach ($possibleChilds as $child) {
1232 if ($child["obj_id"] == $ref_id) {
1233 return $this->__raiseError("Object already exists in target.", "Client");
1234 }
1235 }
1236
1237 // CHECK IF PASTE OBJECT SHALL BE CHILD OF ITSELF
1238 if ($tree->isGrandChild($ref_id, $target_id)) {
1239 return $this->__raiseError("Cannot move object into itself.", "Client");
1240 }
1241
1242 $old_parent = $tree->getParentId($ref_id);
1243 $tree->moveTree($ref_id, $target_id);
1244 $rbacadmin->adjustMovedObjectPermissions($ref_id, $old_parent);
1245
1246 include_once('./Services/Conditions/classes/class.ilConditionHandler.php');
1248 return true;
1249 }
1250
1256 public function copyObject($sid, $copy_settings_xml)
1257 {
1258 $this->initAuth($sid);
1259 $this->initIlias();
1260
1261 if (!$this->__checkSession($sid)) {
1262 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
1263 }
1264
1265
1266 include_once './webservice/soap/classes/class.ilSoapUtils.php';
1267 global $DIC;
1268
1269 $rbacreview = $DIC['rbacreview'];
1270 $objDefinition = $DIC['objDefinition'];
1271 $rbacsystem = $DIC['rbacsystem'];
1272 $lng = $DIC['lng'];
1273 $ilUser = $DIC['ilUser'];
1274
1275 include_once './webservice/soap/classes/class.ilCopyWizardSettingsXMLParser.php';
1276 $xml_parser = new ilCopyWizardSettingsXMLParser($copy_settings_xml);
1277 try {
1278 $xml_parser->startParsing();
1279 } catch (ilSaxParserException $se) {
1280 return $this->__raiseError($se->getMessage(), "Client");
1281 }
1282
1283 // checking copy permissions, objects and create permissions
1284 if (!$rbacsystem->checkAccess('copy', $xml_parser->getSourceId())) {
1285 return $this->__raiseError("Missing copy permissions for object with reference id " . $xml_parser->getSourceId(), 'Client');
1286 }
1287
1288 // checking copy permissions, objects and create permissions
1289 $source_id = $xml_parser->getSourceId();
1290 $target_id = $xml_parser->getTargetId();
1291
1292
1293 // does source object exist
1294 if (!$source_object_type = ilObjectFactory::getTypeByRefId($source_id, false)) {
1295 return $this->__raiseError('No valid source given.', 'Client');
1296 }
1297
1298 // does target object exist
1299 if (!$target_object_type = ilObjectFactory::getTypeByRefId($xml_parser->getTargetId(), false)) {
1300 return $this->__raiseError('No valid target given.', 'Client');
1301 }
1302
1303
1304 $canAddType = $this->canAddType($source_object_type, $target_object_type, $target_id);
1305 if ($this->isFault($canAddType)) {
1306 return $canAddType;
1307 }
1308
1309 // if is container object than clone with sub items
1310 $options = $xml_parser->getOptions();
1311 // print_r($options);
1312 $source_object = ilObjectFactory::getInstanceByRefId($source_id);
1313 if ($source_object instanceof ilContainer) {
1314 // get client id from sid
1315 $clientid = substr($sid, strpos($sid, "::") + 2);
1316 $sessionid = str_replace("::" . $clientid, "", $sid);
1317 // call container clone
1318 $ret = $source_object->cloneAllObject(
1319 $sessionid,
1320 $clientid,
1321 $source_object_type,
1322 $target_id,
1323 $source_id,
1324 $options,
1325 true
1326 );
1327
1328 return $ret['ref_id'];
1329 } else {
1330 // create copy wizard settings
1332 $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
1333 $wizard_options->saveOwner($ilUser->getId());
1334 $wizard_options->saveRoot($source_id);
1335
1336 foreach ($options as $source_id => $option) {
1337 $wizard_options->addEntry($source_id, $option);
1338 }
1339 $wizard_options->read();
1340
1341 // call object clone
1342 $newObject = $source_object->cloneObject($xml_parser->getTargetId(), $copy_id);
1343 return is_object($newObject) ? $newObject->getRefId() : -1;
1344 }
1345 }
1346
1347 public function getPathForRefId($sid, $ref_id)
1348 {
1349 $this->initAuth($sid);
1350 $this->initIlias();
1351
1352 if (!$this->__checkSession($sid)) {
1353 return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
1354 }
1355
1356 global $DIC;
1357
1358 $ilAccess = $DIC['ilAccess'];
1359 $objDefinition = $DIC['objDefinition'];
1360 $rbacsystem = $DIC['rbacsystem'];
1361 $lng = $DIC['lng'];
1362 $ilUser = $DIC['ilUser'];
1363
1364 if (!$rbacsystem->checkAccess('read', $ref_id)) {
1365 return $this->__raiseError("Missing read permissions for object with reference id " . $ref_id, 'Client');
1366 }
1367
1368 if (ilObject::_isInTrash($ref_id)) {
1369 return $this->__raiseError("Object is in Trash", 'Client');
1370 }
1371 global $DIC;
1372
1373 $tree = $DIC['tree'];
1374 $lng = $DIC['lng'];
1375 $items = $tree->getPathFull($ref_id);
1376
1377 include_once 'webservice/soap/classes/class.ilXMLResultSet.php';
1378 include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
1379 include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
1380
1381 $xmlResultSet = new ilXMLResultSet();
1382 $xmlResultSet->addColumn("ref_id");
1383 $xmlResultSet->addColumn("type");
1384 $xmlResultSet->addColumn("title");
1385
1386 $writer = new ilXMLResultSetWriter($xmlResultSet);
1387 foreach ($items as $item) {
1388 if ($item["ref_id"] == $ref_id) {
1389 continue;
1390 }
1391 if ($item["title"] == "ILIAS" && $item["type"] == "root") {
1392 $item["title"] = $lng->txt("repository");
1393 }
1394
1395 $row = new ilXMLResultSetRow();
1396 $xmlResultSet->addRow($row);
1397 $row->setValue("ref_id", $item["ref_id"]);
1398 $row->setValue("type", $item["type"]);
1399 $row->setValue("title", $item["title"]);
1400 }
1401 $writer->start();
1402 return $writer->getXML();
1403 }
1404
1405
1407 {
1408 // checking for target subtypes. Can we add source to target
1409 global $DIC;
1410
1411 $objDefinition = $DIC['objDefinition'];
1412 $rbacsystem = $DIC['rbacsystem'];
1413
1414 $allowed_types = array('root','cat','grp','crs','fold');
1415 if (!in_array($target_type, $allowed_types)) {
1416 return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
1417 }
1418
1419 $allowed_subtypes = $objDefinition->getSubObjects($target_type);
1420 $allowed = array();
1421
1422 foreach ($allowed_subtypes as $row) {
1423 if ($row['name'] != 'rolf') {
1424 $allowed[] = $row['name'];
1425 }
1426 }
1427
1428 if (!in_array($type, $allowed)) {
1429 return $this->__raiseError('Objects of type: ' . $type . ' are not allowed to be subobjects of type ' . $target_type . '!', 'Client');
1430 }
1431 if (!$rbacsystem->checkAccess('create', $target_id, $type)) {
1432 return $this->__raiseError('No permission to create objects of type ' . $type . '!', 'Client');
1433 }
1434
1435 return true;
1436 }
1437
1438 private function validateReferences($a_action, $a_object_data, $a_target_id = 0)
1439 {
1440 global $DIC;
1441
1442 $ilAccess = $DIC['ilAccess'];
1443
1444 if (!isset($a_object_data['references']) or !count($a_object_data['references'])) {
1445 return true;
1446 }
1447 if ($a_action == 'create') {
1448 if (count($a_object_data['references']) > 1) {
1449 if (in_array($a_object_data['type'], array('cat','crs','grp','fold'))) {
1450 return $this->__raiseError(
1451 "Cannot create references for type " . $a_object_data['type'],
1452 'Client'
1453 );
1454 }
1455 }
1456 if (count($a_object_data['references']) == 1) {
1457 if ($a_target_id != $a_object_data['references'][0]['parent_id']) {
1458 return $this->__raiseError(
1459 "Cannot create references for type " . $a_object_data['type'],
1460 'Client'
1461 );
1462 }
1463 }
1464
1465 foreach ($a_object_data['references'] as $ref_data) {
1466 if (!$ref_data['parent_id']) {
1467 return $this->__raiseError('Element References: No parent Id given!', 'Client');
1468 }
1469
1471 $can_add_type = $this->canAddType($a_object_data['type'], $target_type, $ref_data['parent_id']);
1472 if ($this->isFault($can_add_type)) {
1473 return $can_add_type;
1474 }
1475 }
1476 return true;
1477 }
1478
1479 if ($a_action == 'update') {
1480 foreach ($a_object_data['references'] as $ref_data) {
1481 if (!$ref_data['ref_id']) {
1482 return $this->__raiseError('Element References: No reference id given!', 'Client');
1483 }
1484 // check permissions
1485 if (!$ilAccess->checkAccess('write', '', $ref_data['ref_id'])) {
1486 return $this->__raiseError('No write permission for object with reference id ' . $ref_data['ref_id'] . '!', 'Client');
1487 }
1488 // TODO: check if all references belong to the same object
1489 }
1490 return true;
1491 }
1492 }
1493
1494 private function updateReferences($a_object_data)
1495 {
1496 global $DIC;
1497
1498 $tree = $DIC['tree'];
1499 $ilLog = $DIC['ilLog'];
1500
1501 if (!isset($a_object_data['references']) or !count($a_object_data['references'])) {
1502 return true;
1503 }
1504
1505 foreach ($a_object_data['references'] as $ref_data) {
1506 if (isset($ref_data['time_target']) /* and ($crs_ref_id = $tree->checkForParentType($ref_data['ref_id'],'crs')) */) {
1507 include_once('./webservice/soap/classes/class.ilObjectXMLWriter.php');
1508 include_once('./Services/Object/classes/class.ilObjectActivation.php');
1509 $old = ilObjectActivation::getItem($ref_data['ref_id']);
1510
1511 $items = new ilObjectActivation();
1512 $items->toggleChangeable(isset($ref_data['time_target']['changeable']) ? $ref_data['time_target']['changeable'] : $old['changeable']);
1513 $items->setTimingStart(isset($ref_data['time_target']['starting_time']) ? $ref_data['time_target']['starting_time'] : $old['timing_start']);
1514 $items->setTimingEnd(isset($ref_data['time_target']['ending_time']) ? $ref_data['time_target']['ending_time'] : $old['timing_end']);
1515 $items->toggleVisible(isset($ref_data['time_target']['timing_visibility']) ? $ref_data['time_target']['timing_visibility'] : $old['visible']);
1516 $items->setSuggestionStart(isset($ref_data['time_target']['suggestion_start']) ? $ref_data['time_target']['suggestion_start'] : $old['suggestion_start']);
1517 $items->setSuggestionEnd(isset($ref_data['time_target']['suggestion_end']) ? $ref_data['time_target']['suggestion_end'] : $old['suggestion_end']);
1518
1519 switch ($ref_data['time_target']['timing_type']) {
1521 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_DEACTIVATED . ' ' . $ref_data['time_target']['timing_type']);
1522 $items->setTimingType(ilObjectActivation::TIMINGS_DEACTIVATED);
1523 break;
1524
1526 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_ACTIVATION . ' ' . $ref_data['time_target']['timing_type']);
1527 $items->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
1528 break;
1529
1531 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_PRESETTING . ' ' . $ref_data['time_target']['timing_type']);
1532 $items->setTimingType(ilObjectActivation::TIMINGS_PRESETTING);
1533 break;
1534 }
1535 $items->update($ref_data['ref_id']);
1536 }
1537 }
1538 return true;
1539 }
1540
1541
1542 private function addReferences($source, $a_object_data)
1543 {
1544 global $DIC;
1545
1546 $tree = $DIC['tree'];
1547 $ilLog = $DIC['ilLog'];
1548
1549 if (!isset($a_object_data['references']) or !count($a_object_data['references'])) {
1550 return true;
1551 }
1552
1553 $original_id = $source->getRefId();
1554
1555 foreach ($a_object_data['references'] as $ref_data) {
1556 $new_ref_id = $ref_id = $original_id;
1557 if ($tree->getParentId($original_id) != $ref_data['parent_id']) {
1558 // New reference requested => create it
1559 $new_ref_id = $source->createReference();
1560 $source->putInTree($ref_data['parent_id']);
1561 $source->setPermissions($ref_data['parent_id']);
1562 }
1563 if (isset($ref_data['time_target']) /* and ($crs_ref_id = $tree->checkForParentType($new_ref_id,'crs')) */) {
1564 include_once('./webservice/soap/classes/class.ilObjectXMLWriter.php');
1565 include_once('./Services/Object/classes/class.ilObjectActivation.php');
1566
1567 if (!isset($ref_data['time_target']['starting_time'])) {
1568 $ref_data['time_target']['starting_time'] = time();
1569 }
1570 if (!isset($ref_data['time_target']['ending_time'])) {
1571 $ref_data['time_target']['ending_time'] = time();
1572 }
1573
1574 $items = new ilObjectActivation();
1575 $items->toggleChangeable($ref_data['time_target']['changeable']);
1576 $items->setTimingStart($ref_data['time_target']['starting_time']);
1577 $items->setTimingEnd($ref_data['time_target']['ending_time']);
1578 $items->toggleVisible($ref_data['time_target']['timing_visibility']);
1579 $items->setSuggestionStart($ref_data['time_target']['suggestion_start']);
1580 $items->setSuggestionEnd($ref_data['time_target']['suggestion_end']);
1581
1582 switch ($ref_data['time_target']['timing_type']) {
1584 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_DEACTIVATED . ' ' . $ref_data['time_target']['timing_type']);
1585 $items->setTimingType(ilObjectActivation::TIMINGS_DEACTIVATED);
1586 break;
1587
1589 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_ACTIVATION . ' ' . $ref_data['time_target']['timing_type']);
1590 $items->setTimingType(ilObjectActivation::TIMINGS_ACTIVATION);
1591 break;
1592
1594 $ilLog->write(__METHOD__ . ilObjectActivation::TIMINGS_PRESETTING . ' ' . $ref_data['time_target']['timing_type']);
1595 $items->setTimingType(ilObjectActivation::TIMINGS_PRESETTING);
1596 break;
1597 }
1598 $items->update($new_ref_id);
1599 }
1600 }
1601 }
1602}
$source
Definition: linkback.php:22
$location
Definition: buildRTE.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_ADMIN
Base class for course and group participants.
const QP_COMBINATION_OR
const QP_COMBINATION_AND
static _adjustMovedObjectConditions($a_ref_id)
In the moment it is not allowed to create preconditions on objects that are located outside of a cour...
Class ilContainer.
static _allocateCopyId()
Allocate a copy for further entries.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static getInstance()
Get singleton instance.
Parses result XML from lucene search highlight.
static getInstance(ilLuceneQueryParser $qp)
Get singleton instance.
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user's personal desktop
static _lookupId($a_user_str)
Lookup id by login.
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
Class ilObjectActivation.
static getItem($a_ref_id)
Get item data.
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 getTypeByRefId($a_ref_id, $stop_on_error=true)
get object type by reference id
Exception class for ObjectXMLWriter and ObjectXMLParser.
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _lookupObjIdByImportId($a_import_id)
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
SaxParserException thrown by ilSaxParser if property throwException is set.
initAuth($sid)
Init authentication.
__raiseError($a_message, $a_code)
validateReferences($a_action, $a_object_data, $a_target_id=0)
removeDesktopItems($sid, $user_id, $reference_ids)
Remove desktop items for user.
getXMLTree($sid, $ref_id, $types, $user_id)
copyObject($sid, $copy_settings_xml)
copy object in repository $sid session id $settings_xml contains copy wizard settings following ilias...
searchObjects($sid, $types, $key, $combination, $user_id)
getObjIdsByRefIds($sid, $ref_ids)
Returns a array of object ids which match the references id, given by a comma seperated string.
canAddType($type, $target_type, $target_id)
getTreeChilds($sid, $ref_id, $types, $user_id)
addReference($sid, $a_source_id, $a_target_id)
addDesktopItems($sid, $user_id, $reference_ids)
Add desktop items for user.
getObjectByReference($sid, $a_ref_id, $user_id)
static removeItemFromDesktops($a_id)
removes object from all user's desktops @access public
XML Writer for XMLResultSet.
$key
Definition: croninfo.php:18
$target_id
Definition: goto.php:49
$target_type
Definition: goto.php:48
$user
Definition: migrateto20.php:57
$row
$ret
Definition: parser.php:6
$type
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18