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