ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilContainer.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\News\Service as News;
20 
28 class ilContainer extends ilObject
29 {
30  protected News $news;
31  protected \ILIAS\Style\Content\DomainService $content_style_domain;
32  // container view constants
33  public const VIEW_SESSIONS = 0;
34  public const VIEW_OBJECTIVE = 1;
35  public const VIEW_TIMING = 2;
36  public const VIEW_ARCHIVE = 3;
37  public const VIEW_SIMPLE = 4;
38  public const VIEW_BY_TYPE = 5;
39  public const VIEW_INHERIT = 6;
40 
41  public const VIEW_DEFAULT = self::VIEW_BY_TYPE;
42 
43  public const SORT_TITLE = 0;
44  public const SORT_MANUAL = 1;
45  public const SORT_ACTIVATION = 2;
46  public const SORT_INHERIT = 3;
47  public const SORT_CREATION = 4;
48 
49  public const SORT_DIRECTION_ASC = 0;
50  public const SORT_DIRECTION_DESC = 1;
51 
52  public const SORT_NEW_ITEMS_POSITION_TOP = 0;
54 
55  public const SORT_NEW_ITEMS_ORDER_TITLE = 0;
58 
59  public const TILE_NORMAL = 0;
60  public const TILE_SMALL = 1;
61  public const TILE_LARGE = 2;
62  public const TILE_EXTRA_LARGE = 3;
63  public const TILE_FULL = 4;
64 
65  public static bool $data_preloaded = false;
66  protected \ILIAS\Container\InternalDomainService $domain;
67 
70  protected ilObjUser $user;
71  public array $items = [];
73  protected int $order_type = 0;
74  protected bool $hiddenfilesfound = false;
75  protected bool $news_timeline = false;
76  protected bool $news_timeline_auto_entries = false;
77  protected ilSetting $setting;
78  protected ?ilObjectTranslation $obj_trans = null;
79  protected int $style_id = 0;
80  protected bool $news_timeline_landing_page = false;
81  protected bool $news_block_activated = false;
82  protected bool $use_news = false;
84 
85  protected ?array $type_grps = null;
86 
87  public function __construct(int $a_id = 0, bool $a_reference = true)
88  {
90  global $DIC;
91 
92  $this->db = $DIC->database();
93  $this->log = $DIC["ilLog"];
94  $this->access = $DIC->access();
95  $this->error = $DIC["ilErr"];
96  $this->rbacsystem = $DIC->rbac()->system();
97  $this->tree = $DIC->repositoryTree();
98  $this->user = $DIC->user();
99  $this->obj_definition = $DIC["objDefinition"];
100  $this->news = $DIC->news();
101 
102 
103  $this->setting = $DIC["ilSetting"];
104  parent::__construct($a_id, $a_reference);
105 
106  if ($this->getId() > 0) {
107  $this->obj_trans = ilObjectTranslation::getInstance($this->getId());
108  }
109  $this->recommended_content_manager = new ilRecommendedContentManager();
110  $this->content_style_domain = $DIC->contentStyle()->domain();
111  $this->domain = $DIC->container()->internal()->domain();
112  }
113 
117  public function getTileSizes(): array
118  {
119  $lng = $this->lng;
120  return [
121  self::TILE_SMALL => $lng->txt("cont_tile_size_1"),
122  self::TILE_NORMAL => $lng->txt("cont_tile_size_0"),
123  self::TILE_LARGE => $lng->txt("cont_tile_size_2"),
124  self::TILE_EXTRA_LARGE => $lng->txt("cont_tile_size_3"),
125  self::TILE_FULL => $lng->txt("cont_tile_size_4")
126  ];
127  }
128 
130  {
131  return $this->obj_trans;
132  }
133 
134  public function setObjectTranslation(?ilObjectTranslation $obj_trans): void
135  {
136  $this->obj_trans = $obj_trans;
137  }
138 
139  // <webspace_dir>/container_data.
140  public function createContainerDirectory(): void
141  {
142  $webspace_dir = ilFileUtils::getWebspaceDir();
143  $cont_dir = $webspace_dir . "/container_data";
144  if (!is_dir($cont_dir)) {
145  ilFileUtils::makeDir($cont_dir);
146  }
147  $obj_dir = $cont_dir . "/obj_" . $this->getId();
148  if (!is_dir($obj_dir)) {
149  ilFileUtils::makeDir($obj_dir);
150  }
151  }
152 
153  public function getContainerDirectory(): string
154  {
155  return self::_getContainerDirectory($this->getId());
156  }
157 
158  public static function _getContainerDirectory(int $a_id): string
159  {
160  return ilFileUtils::getWebspaceDir() . "/container_data/obj_" . $a_id;
161  }
162 
163  // Set Found hidden files (set by getSubItems).
164  public function setHiddenFilesFound(bool $a_hiddenfilesfound): void
165  {
166  $this->hiddenfilesfound = $a_hiddenfilesfound;
167  }
168 
169  public function getHiddenFilesFound(): bool
170  {
172  }
173 
174  public function getStyleSheetId(): int
175  {
176  return $this->style_id;
177  }
178 
179  public function setStyleSheetId(int $a_style_id): void
180  {
181  $this->style_id = $a_style_id;
182  }
183 
184  public function setNewsTimeline(bool $a_val): void
185  {
186  $this->news_timeline = $a_val;
187  }
188 
189  public function getNewsTimeline(): bool
190  {
191  return $this->news_timeline;
192  }
193 
194  public function setNewsTimelineAutoEntries(bool $a_val): void
195  {
196  $this->news_timeline_auto_entries = $a_val;
197  }
198 
199  public function getNewsTimelineAutoEntries(): bool
200  {
202  }
203 
204  public function setNewsTimelineLandingPage(bool $a_val): void
205  {
206  $this->news_timeline_landing_page = $a_val;
207  }
208 
209  public function getNewsTimelineLandingPage(): bool
210  {
212  }
213 
214  public function isNewsTimelineEffective(): bool
215  {
216  if (!$this->news->isGloballyActivated()) {
217  return false;
218  }
219  if ($this->getUseNews() && $this->getNewsTimeline()) {
220  return true;
221  }
222  return false;
223  }
224 
225  public function isNewsTimelineLandingPageEffective(): bool
226  {
227  if ($this->getUseNews() && $this->getNewsTimeline() && $this->getNewsTimelineLandingPage()) {
228  return true;
229  }
230  return false;
231  }
232 
233 
234  public function setNewsBlockActivated(bool $a_val): void
235  {
236  $this->news_block_activated = $a_val;
237  }
238 
239  public function getNewsBlockActivated(): bool
240  {
242  }
243 
244  public function setUseNews(bool $a_val): void
245  {
246  $this->use_news = $a_val;
247  }
248 
249  public function getUseNews(): bool
250  {
251  return $this->use_news;
252  }
253 
254  public static function _lookupContainerSetting(
255  int $a_id,
256  string $a_keyword,
257  string $a_default_value = null
258  ): string {
259  global $DIC;
260 
261  $ilDB = $DIC->database();
262 
263  $q = "SELECT value FROM container_settings WHERE " .
264  " id = " . $ilDB->quote($a_id, 'integer') . " AND " .
265  " keyword = " . $ilDB->quote($a_keyword, 'text');
266  $set = $ilDB->query($q);
267  $rec = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
268 
269  if (isset($rec['value'])) {
270  return $rec["value"];
271  }
272 
273  return $a_default_value ?? '';
274  }
275 
276  public static function _hasContainerSetting(
277  int $a_id,
278  string $a_keyword
279  ): string {
280  global $DIC;
281 
282  $ilDB = $DIC->database();
283 
284  $q = "SELECT value FROM container_settings WHERE " .
285  " id = " . $ilDB->quote($a_id, 'integer') . " AND " .
286  " keyword = " . $ilDB->quote($a_keyword, 'text');
287  $set = $ilDB->query($q);
288  $rec = $set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
289 
290  return (bool) $rec;
291  }
292 
293  public static function _writeContainerSetting(
294  int $a_id,
295  string $a_keyword,
296  string $a_value
297  ): void {
298  global $DIC;
299 
300  $ilDB = $DIC->database();
301 
302  $query = "DELETE FROM container_settings WHERE " .
303  "id = " . $ilDB->quote($a_id, 'integer') . " " .
304  "AND keyword = " . $ilDB->quote($a_keyword, 'text');
305  $ilDB->manipulate($query);
306 
308  $log->debug("Write container setting, id: " . $a_id . ", keyword: " . $a_keyword . ", value: " . $a_value);
309 
310  $query = "INSERT INTO container_settings (id, keyword, value) VALUES (" .
311  $ilDB->quote($a_id, 'integer') . ", " .
312  $ilDB->quote($a_keyword, 'text') . ", " .
313  $ilDB->quote($a_value, 'text') .
314  ")";
315 
316  $ilDB->manipulate($query);
317  }
318 
323  public static function _getContainerSettings(int $a_id): array
324  {
325  global $DIC;
326 
327  $ilDB = $DIC->database();
328 
329  $res = [];
330 
331  $sql = "SELECT keyword, value FROM container_settings WHERE " .
332  " id = " . $ilDB->quote($a_id, 'integer');
333  $set = $ilDB->query($sql);
334  while ($row = $ilDB->fetchAssoc($set)) {
335  $res[$row["keyword"]] = $row["value"];
336  }
337 
338  return $res;
339  }
340 
341  public static function _deleteContainerSettings(
342  int $a_id,
343  string $a_keyword = "",
344  bool $a_keyword_like = false
345  ): void {
346  global $DIC;
347 
348  $ilDB = $DIC->database();
349 
350  if (!$a_id) {
351  return;
352  }
353 
354  $sql = "DELETE FROM container_settings WHERE " .
355  " id = " . $ilDB->quote($a_id, 'integer');
356  if ($a_keyword !== "") {
357  if (!$a_keyword_like) {
358  $sql .= " AND keyword = " . $ilDB->quote($a_keyword, "text");
359  } else {
360  $sql .= " AND " . $ilDB->like("keyword", "text", $a_keyword);
361  }
362  }
363  $ilDB->manipulate($sql);
364  }
365 
366  public static function _exportContainerSettings(
367  ilXmlWriter $a_xml,
368  int $a_obj_id
369  ): void {
370  // container settings
371  $settings = self::_getContainerSettings($a_obj_id);
372  if (count($settings)) {
373  $a_xml->xmlStartTag("ContainerSettings");
374 
375  foreach ($settings as $keyword => $value) {
376  // :TODO: proper custom icon export/import
377  if (
378  stripos($keyword, "icon") !== false
379  && $keyword !== 'hide_header_icon_and_title'
380  ) {
381  continue;
382  }
383 
384  $a_xml->xmlStartTag(
385  'ContainerSetting',
386  [
387  'id' => $keyword,
388  ]
389  );
390 
391  $a_xml->xmlData((string) $value);
392  $a_xml->xmlEndTag("ContainerSetting");
393  }
394 
395  $a_xml->xmlEndTag("ContainerSettings");
396  }
397  }
398 
407  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
408  {
410  $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
411 
413 
414  // translations
415  $ot = ilObjectTranslation::getInstance($this->getId());
416  $ot->setDefaultTitle($new_obj->getTitle()); // get possible "- COPY" extension
417  $ot->copy($new_obj->getId());
418  $ot2 = ilObjectTranslation::getInstance($new_obj->getId());
419  $ot2->read();
420  $new_obj->setObjectTranslation($ot2);
421  if ($ot2->getDefaultDescription() !== "") {
422  $new_obj->setDescription($ot2->getDefaultDescription());
423  }
424  $log->debug("**1**" . count($new_obj->getObjectTranslation()->getLanguages()));
425  $log->debug("ilContainer: cloning translations from " . $this->getId() . " to " .
426  $new_obj->getId());
427 
428  #18624 - copy all sorting settings
429  ilContainerSortingSettings::_cloneSettings($this->getId(), $new_obj->getId());
430 
431  // copy content page
433  "cont",
434  $this->getId()
435  )) {
436  $orig_page = new ilContainerPage($this->getId());
437  $orig_page->copy($new_obj->getId(), "cont", $new_obj->getId());
438  }
439 
440  // #20614 - copy style
441  $this->content_style_domain->styleForRefId($this->getRefId())->cloneTo($new_obj->getId());
442 
443  // #10271 - copy start objects page
445  "cstr",
446  $this->getId()
447  )) {
448  $orig_page = new ilContainerStartObjectsPage($this->getId());
449  $orig_page->copy($new_obj->getId(), "cstr", $new_obj->getId());
450  }
451 
452  // #10271
453  foreach (self::_getContainerSettings($this->getId()) as $keyword => $value) {
454  self::_writeContainerSetting($new_obj->getId(), (string) $keyword, (string) $value);
455  }
456 
457  $new_obj->setNewsTimeline($this->getNewsTimeline());
458  $new_obj->setNewsBlockActivated($this->getNewsBlockActivated());
459  $new_obj->setUseNews($this->getUseNews());
460  $new_obj->setNewsTimelineAutoEntries($this->getNewsTimelineAutoEntries());
461  $new_obj->setNewsTimelineLandingPage($this->getNewsTimelineLandingPage());
462  ilBlockSetting::cloneSettingsOfBlock("news", $this->getId(), $new_obj->getId());
463  $mom_noti = new ilMembershipNotifications($this->getRefId());
464  $mom_noti->cloneSettings($new_obj->getRefId());
465 
466  // clone filter fields
467  $container_filter_service = new ilContainerFilterService();
468  $container_filter_service->cloneFilterFields($this->getRefId(), $new_obj->getRefId());
469 
470  return $new_obj;
471  }
472 
481  public function cloneDependencies(int $target_id, int $copy_id): bool
482  {
483  $ilLog = $this->log;
484 
485  parent::cloneDependencies($target_id, $copy_id);
486 
487  ilContainerSorting::_getInstance($this->getId())->cloneSorting($target_id, $copy_id);
488 
489  // fix internal links to other objects
490  self::fixInternalLinksAfterCopy($target_id, $copy_id, $this->getRefId());
491 
492  // fix item group references in page content
494 
495  $olp = ilObjectLP::getInstance($this->getId());
496  $collection = $olp->getCollectionInstance();
497  if ($collection) {
498  $collection->cloneCollection($target_id, $copy_id);
499  }
500 
501  return true;
502  }
503 
515  public function cloneAllObject(
516  string $session_id,
517  string $client_id,
518  string $new_type,
519  int $ref_id,
520  int $clone_source,
521  array $options,
522  bool $soap_call = false,
523  int $a_submode = 1
524  ): array {
525  $ilLog = $this->log;
526  $ilUser = $this->user;
527 
528  // Save wizard options
530  $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
531  $wizard_options->saveOwner($ilUser->getId());
532  $wizard_options->saveRoot($clone_source);
533 
534  // add entry for source container
535  $wizard_options->initContainer($clone_source, $ref_id);
536 
537  foreach ($options as $source_id => $option) {
538  $wizard_options->addEntry($source_id, $option);
539  }
540  $wizard_options->read();
541  $wizard_options->storeTree($clone_source);
542 
543  if ($a_submode === ilObjectCopyGUI::SUBMODE_CONTENT_ONLY) {
544  ilLoggerFactory::getLogger('obj')->info('Copy content only...');
545  ilLoggerFactory::getLogger('obj')->debug('Added mapping, source ID: ' . $clone_source . ', target ID: ' . $ref_id);
546  $wizard_options->read();
547  $wizard_options->dropFirstNode();
548  $wizard_options->appendMapping($clone_source, $ref_id);
549  }
550 
551 
552  #print_r($options);
553  // Duplicate session to avoid logout problems with backgrounded SOAP calls
554  $new_session_id = ilSession::_duplicate($session_id);
555  // Start cloning process using soap call
556  $soap_client = new ilSoapClient();
557  $soap_client->setResponseTimeout($soap_client->getResponseTimeout());
558  $soap_client->enableWSDL(true);
559 
560  $ilLog->write(__METHOD__ . ': Trying to call Soap client...');
561  if ($soap_client->init()) {
562  ilLoggerFactory::getLogger('obj')->info('Calling soap clone method');
563  $res = $soap_client->call('ilClone', [$new_session_id . '::' . $client_id, $copy_id]);
564  } else {
565  ilLoggerFactory::getLogger('obj')->warning('SOAP clone call failed. Calling clone method manually');
566  $wizard_options->disableSOAP();
567  $wizard_options->read();
568  $res = ilSoapFunctions::ilClone($new_session_id . '::' . $client_id, $copy_id);
569  }
570  return [
571  'copy_id' => $copy_id,
572  'ref_id' => (int) $res
573  ];
574  }
575 
581  public function delete(): bool
582  {
583  // always call parent delete function first!!
584  if (!parent::delete()) {
585  return false;
586  }
587  // delete translations
588  $this->obj_trans->delete();
589 
590  return true;
591  }
592 
593  public function getViewMode(): int
594  {
595  return self::VIEW_BY_TYPE;
596  }
597 
598  public function getOrderType(): int
599  {
600  return $this->order_type ?: self::SORT_TITLE;
601  }
602 
603  public function setOrderType(int $a_value): void
604  {
605  $this->order_type = $a_value;
606  }
607 
608  public function isClassificationFilterActive(): bool
609  {
610  // apply container classification filters
611  $classification = $this->domain->classification($this->getRefId());
612  foreach (ilClassificationProvider::getValidProviders($this->getRefId(), $this->getId(), $this->getType()) as $class_provider) {
613  $id = get_class($class_provider);
614  $current = $classification->getSelectionOfProvider($id);
615  if ($current) {
616  return true;
617  }
618  }
619  return false;
620  }
621 
626  public function filteredSubtree(): bool
627  {
628  if ($this->isClassificationFilterActive() && in_array($this->getType(), ["grp", "crs"])) {
629  return true;
630  }
631  return false;
632  }
633 
637  protected function getInitialSubitems(): array
638  {
639  $tree = $this->tree;
640  if ($this->filteredSubtree()) {
641  $objects = $tree->getSubTree($tree->getNodeData($this->getRefId()));
642  } else {
643  $objects = $tree->getChilds($this->getRefId(), "title");
644  }
645  return $objects;
646  }
647 
651  public function getSubItems(
652  bool $a_admin_panel_enabled = false,
653  bool $a_include_side_block = false,
654  int $a_get_single = 0,
655  ilContainerUserFilter $container_user_filter = null
656  ): array {
657  $objDefinition = $this->obj_definition;
658 
659  // Caching
660  if (
661  isset($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
662  is_array($this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]) &&
663  !$a_get_single
664  ) {
665  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
666  }
667 
668  $objects = $this->getInitialSubitems();
669  $objects = $this->applyContainerUserFilter($objects, $container_user_filter);
670  $objects = self::getCompleteDescriptions($objects);
671 
672  // apply container classification filters
673  $classification = $this->domain->classification($this->getRefId());
674  foreach (ilClassificationProvider::getValidProviders($this->getRefId(), $this->getId(), $this->getType()) as $class_provider) {
675  $id = get_class($class_provider);
676  $current = $classification->getSelectionOfProvider($id);
677  if ($current) {
678  $class_provider->setSelection($current);
679  $filtered = $class_provider->getFilteredObjects();
680  $objects = array_filter($objects, static function (array $i) use ($filtered): bool {
681  return (is_array($filtered) && in_array($i["obj_id"], $filtered));
682  });
683  }
684  }
685 
686  $found = false;
687  $all_ref_ids = [];
688 
689  $preloader = null;
690  if (!self::$data_preloaded) {
692  }
693 
694  $sort = ilContainerSorting::_getInstance($this->getId());
695 
696  // TODO: check this
697  // get items attached to a session
698 
699  $classification_filter_active = $this->isClassificationFilterActive();
700  foreach ($objects as $key => $object) {
701  // see #41377, this ensures session materials to be preloaded
702  if (!self::$data_preloaded) {
703  if ($object["type"] === "sess") {
704  $ev_items = ilObjectActivation::getItemsByEvent((int) $object["obj_id"]);
705  foreach ($ev_items as $ev_item) {
706  $preloader->addItem((int) $ev_item["obj_id"], $ev_item["type"], $ev_item["ref_id"]);
707  }
708  }
709  }
710  if ($a_get_single > 0 && $object["child"] != $a_get_single) {
711  continue;
712  }
713 
714  // hide object types in devmode
715  if ($object["type"] === "adm" || $object["type"] === "rolf" || $objDefinition->getDevMode($object["type"])) {
716  continue;
717  }
718 
719  // remove inactive plugins
720  if ($objDefinition->isInactivePlugin($object["type"])) {
721  continue;
722  }
723  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
724  if (in_array(
725  $object['type'],
726  ['file', 'fold', 'cat'],
727  true
728  ) && ilObjFileAccess::_isFileHidden((string) $object['title'])) {
729  $this->setHiddenFilesFound(true);
730  if (!$a_admin_panel_enabled) {
731  continue;
732  }
733  }
734  // END WebDAV: Don't display hidden Files, Folders and Categories
735 
736  if (!self::$data_preloaded) {
737  $preloader->addItem((int) $object["obj_id"], $object["type"], $object["child"]);
738  }
739 
740  // filter side block items
741  if (!$a_include_side_block && $objDefinition->isSideBlock($object['type'])) {
742  continue;
743  }
744 
745  $all_ref_ids[] = (int) $object["child"];
746  }
747 
748  // data preloader
749  if (!self::$data_preloaded) {
750  $preloader->preload();
751  unset($preloader);
752 
753  self::$data_preloaded = true;
754  }
755 
756  foreach ($objects as $key => $object) {
757  // see above, objects were filtered
758  if (!in_array($object["child"], $all_ref_ids)) {
759  continue;
760  }
761 
762  // group object type groups together (e.g. learning resources)
763  $type = $objDefinition->getGroupOfObj($object["type"]);
764  if ($type == "") {
765  $type = $object["type"];
766  }
767 
768  // this will add activation properties
769  $this->addAdditionalSubItemInformation($object);
770 
771  $this->items[$type][$key] = $object;
772 
773  $this->items["_all"][$key] = $object;
774  if ($object["type"] !== "sess") {
775  $this->items["_non_sess"][$key] = $object;
776  }
777  }
778  $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block]
779  = $sort->sortItems($this->items);
780 
781  return $this->items[(int) $a_admin_panel_enabled][(int) $a_include_side_block];
782  }
783 
787  public function gotItems(): bool
788  {
789  if (isset($this->items["_all"]) && is_array($this->items["_all"]) && count($this->items["_all"]) > 0) {
790  return true;
791  }
792  return false;
793  }
794 
799  public function addAdditionalSubItemInformation(array &$object): void
800  {
801  }
802 
803  // Get grouped repository object types.
804  public function getGroupedObjTypes(): array
805  {
806  $objDefinition = $this->obj_definition;
807 
808  if (empty($this->type_grps)) {
809  $this->type_grps = $objDefinition::getGroupedRepositoryObjectTypes($this->getType());
810  }
811  return $this->type_grps;
812  }
813 
814  public function enablePageEditing(): bool
815  {
817 
818  // @todo: this will need a more general approach
819  if ($ilSetting->get("enable_cat_page_edit")) {
820  return true;
821  }
822  return false;
823  }
824 
825  public function create(): int
826  {
827  global $DIC;
828 
829  $lng = $DIC->language();
830 
831  $ret = parent::create();
832 
833  // set translation object, since we have an object id now
834  $this->obj_trans = ilObjectTranslation::getInstance($this->getId());
835 
836  // add default translation
837  $this->addTranslation(
838  $this->getTitle(),
839  $this->getDescription(),
841  '1'
842  );
843 
844  if (($this->getStyleSheetId()) > 0) {
845  //ilObjStyleSheet::writeStyleUsage($this->getId(), $this->getStyleSheetId());
846  }
847 
849  $log->debug("Create Container, id: " . $this->getId());
850 
851  self::_writeContainerSetting($this->getId(), "news_timeline", (string) ((int) $this->getNewsTimeline()));
852  self::_writeContainerSetting($this->getId(), "news_timeline_incl_auto", (string) ((int) $this->getNewsTimelineAutoEntries()));
853  self::_writeContainerSetting($this->getId(), "news_timeline_landing_page", (string) ((int) $this->getNewsTimelineLandingPage()));
854  self::_writeContainerSetting($this->getId(), ilObjectServiceSettingsGUI::NEWS_VISIBILITY, (string) ((int) $this->getNewsBlockActivated()));
855  self::_writeContainerSetting($this->getId(), ilObjectServiceSettingsGUI::USE_NEWS, (string) ((int) $this->getUseNews()));
856 
857  return $ret;
858  }
859 
860  public function putInTree(int $parent_ref_id): void
861  {
862  parent::putInTree($parent_ref_id);
863 
864  // copy title, icon actions visibilities
865  if (self::_lookupContainerSetting(ilObject::_lookupObjId($parent_ref_id), "hide_header_icon_and_title")) {
866  self::_writeContainerSetting($this->getId(), "hide_header_icon_and_title", '1');
867  }
868  if (self::_lookupContainerSetting(ilObject::_lookupObjId($parent_ref_id), "hide_top_actions")) {
869  self::_writeContainerSetting($this->getId(), "hide_top_actions", '1');
870  }
871  }
872 
873  public function update(): bool
874  {
875  $ret = parent::update();
876 
878  $log->debug("**5**" . count($this->getObjectTranslation()->getLanguages()));
879 
880  $trans = $this->getObjectTranslation();
881  $trans->setDefaultTitle($this->getTitle());
882  $trans->setDefaultDescription($this->getLongDescription());
883  $trans->save();
884 
886  $log->debug(":::::::::::::::::::::::::::");
887  $log->logStack(10);
888 
889  //ilObjStyleSheet::writeStyleUsage($this->getId(), $this->getStyleSheetId());
890 
892  $log->debug("Update Container, id: " . $this->getId());
893 
894  self::_writeContainerSetting($this->getId(), "news_timeline", (string) ((int) $this->getNewsTimeline()));
895  self::_writeContainerSetting($this->getId(), "news_timeline_incl_auto", (string) (int) $this->getNewsTimelineAutoEntries());
896  self::_writeContainerSetting($this->getId(), "news_timeline_landing_page", (string) ((int) ($this->getNewsTimelineLandingPage())));
897  self::_writeContainerSetting($this->getId(), ilObjectServiceSettingsGUI::NEWS_VISIBILITY, (string) ((int) $this->getNewsBlockActivated()));
898  self::_writeContainerSetting($this->getId(), ilObjectServiceSettingsGUI::USE_NEWS, (string) ((int) $this->getUseNews()));
899 
900  return $ret;
901  }
902 
903  public function read(): void
904  {
905  parent::read();
906 
908 
909  //$this->setStyleSheetId(ilObjStyleSheet::lookupObjectStyle($this->getId()));
910 
911  $this->readContainerSettings();
912  $this->obj_trans = ilObjectTranslation::getInstance($this->getId());
913  }
914 
915  public function readContainerSettings(): void
916  {
917  $this->setNewsTimeline((bool) self::_lookupContainerSetting($this->getId(), "news_timeline"));
918  $this->setNewsTimelineAutoEntries((bool) self::_lookupContainerSetting($this->getId(), "news_timeline_incl_auto"));
919  $this->setNewsTimelineLandingPage((bool) self::_lookupContainerSetting($this->getId(), "news_timeline_landing_page"));
920  $this->setNewsBlockActivated((bool) self::_lookupContainerSetting(
921  $this->getId(),
923  $this->setting->get('block_activated_news', '1')
924  ));
925  $this->setUseNews((bool) self::_lookupContainerSetting($this->getId(), ilObjectServiceSettingsGUI::USE_NEWS, '1') &&
926  $this->news->isGloballyActivated());
927  }
928 
929 
934  public static function getCompleteDescriptions(array $objects): array
935  {
936  global $DIC;
937 
938  $ilSetting = $DIC->settings();
939  $ilObjDataCache = $DIC["ilObjDataCache"];
940 
941  // using long descriptions?
942  $short_desc = $ilSetting->get("rep_shorten_description");
943  $short_desc_max_length = $ilSetting->get("rep_shorten_description_length");
944  if (!$short_desc || (int) $short_desc_max_length !== ilObject::DESC_LENGTH) {
945  // using (part of) shortened description
946  if ($short_desc && $short_desc_max_length && $short_desc_max_length < ilObject::DESC_LENGTH) {
947  foreach ($objects as $key => $object) {
948  $objects[$key]["description"] = ilStr::shortenTextExtended(
949  $object["description"],
950  (int) $short_desc_max_length,
951  true
952  );
953  }
954  }
955  // using (part of) long description
956  else {
957  $obj_ids = [];
958  foreach ($objects as $key => $object) {
959  $obj_ids[] = $object["obj_id"];
960  }
961  if (count($obj_ids)) {
963  foreach ($objects as $key => $object) {
964  // #12166 - keep translation, ignore long description
965  if ($ilObjDataCache->isTranslatedDescription((int) $object["obj_id"])) {
966  $long_desc[$object["obj_id"]] = $object["description"];
967  }
968  if ($short_desc && $short_desc_max_length) {
969  $long_desc[$object["obj_id"]] = ilStr::shortenTextExtended(
970  $long_desc[$object["obj_id"]] ?? '',
971  (int) $short_desc_max_length,
972  true
973  );
974  }
975  $objects[$key]["description"] = $long_desc[$object["obj_id"]] ?? '';
976  }
977  }
978  }
979  }
980  return $objects;
981  }
982 
983  protected static function fixInternalLinksAfterCopy(
984  int $a_target_id,
985  int $a_copy_id,
986  int $a_source_ref_id
987  ): void {
988  global $DIC;
989 
991  $obj_definition = $DIC["objDefinition"];
992 
993  $obj_id = ilObject::_lookupObjId($a_target_id);
994  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
995  $mapping = $cwo->getMappings();
996 
997  if (ilContainerPage::_exists("cont", $obj_id)) {
998  $pg = new ilContainerPage($obj_id);
999  $pg->handleRepositoryLinksOnCopy($mapping, $a_source_ref_id);
1000  $pg->update(true, true);
1001  }
1002 
1003  foreach ($mapping as $old_ref_id => $new_ref_id) {
1004  if (!is_numeric($old_ref_id) || !is_numeric($new_ref_id)) {
1005  continue;
1006  }
1007 
1008  $type = ilObject::_lookupType($new_ref_id, true);
1009  $class = 'il' . $obj_definition->getClassName($type) . 'PageCollector';
1010  $loc = $obj_definition->getLocation($type);
1011  $file = $loc . '/class.' . $class . '.php';
1012 
1013  if (is_file($file)) {
1015  $coll = new $class();
1016  foreach ($coll->getAllPageIds(ilObject::_lookupObjId($new_ref_id)) as $page_id) {
1017  if (ilPageObject::_exists($page_id['parent_type'], $page_id['id'], $page_id['lang'])) {
1019  $page = ilPageObjectFactory::getInstance($page_id['parent_type'], $page_id['id'], 0, $page_id['lang']);
1020  $page->handleRepositoryLinksOnCopy($mapping, $a_source_ref_id);
1021  $page->update(true, true);
1022  }
1023  }
1024  }
1025  }
1026  }
1027 
1028  // Remove all translations of container
1029  public function removeTranslations(): void
1030  {
1031  $this->obj_trans->delete();
1032  }
1033 
1034  public function deleteTranslation(string $a_lang): void
1035  {
1036  $this->obj_trans->removeLanguage($a_lang);
1037  $this->obj_trans->save();
1038  }
1039 
1040  public function addTranslation(
1041  string $a_title,
1042  string $a_desc,
1043  string $a_lang,
1044  string $a_lang_default
1045  ): void {
1046  if (empty($a_title)) {
1047  $a_title = "NO TITLE";
1048  }
1049 
1050  $this->obj_trans->addLanguage($a_lang, $a_title, $a_desc, (bool) $a_lang_default, true);
1051  $this->obj_trans->save();
1052  }
1053 
1054  protected function applyContainerUserFilter(
1055  array $objects,
1056  ilContainerUserFilter $container_user_filter = null
1057  ): array {
1058  $filter = $this->domain->content()->filter(
1059  $objects,
1060  $container_user_filter,
1061  !self::_lookupContainerSetting($this->getId(), "filter_show_empty", false)
1062  );
1063  return $filter->apply();
1064  }
1065 }
setStyleSheetId(int $a_style_id)
static getWebspaceDir(string $mode="filesystem")
get webspace directory
$res
Definition: ltiservices.php:69
static _duplicate(string $a_session_id)
Duplicate session.
string $type
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
const SORT_NEW_ITEMS_POSITION_TOP
static getLogger(string $a_component_id)
Get component logger.
ILIAS Container InternalDomainService $domain
setHiddenFilesFound(bool $a_hiddenfilesfound)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
ilObjectTranslation $obj_trans
logStack(?int $level=null, string $message='', array $context=[])
static getItemsByEvent(int $event_id)
Get session material / event items.
addTranslation(string $a_title, string $a_desc, string $a_lang, string $a_lang_default)
static ilClone(string $sid, int $copy_identifier)
ilAccessHandler $access
getDefaultLanguage()
Return default language.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlData(string $data, bool $encode=true, bool $escape=true)
Writes data.
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
const DESC_LENGTH
filteredSubtree()
Note grp/crs currently allow to filter in their whole subtrees Catetories only their direct childs...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilTree $tree
putInTree(int $parent_ref_id)
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
ilObjectDefinition $obj_definition
setNewsBlockActivated(bool $a_val)
setOrderType(int $a_value)
addAdditionalSubItemInformation(array &$object)
Add additional information to sub item, e.g.
applyContainerUserFilter(array $objects, ilContainerUserFilter $container_user_filter=null)
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupObjId(int $ref_id)
ilRbacSystem $rbacsystem
xmlEndTag(string $tag)
Writes an endtag.
cloneDependencies(int $target_id, int $copy_id)
Clone object dependencies (container sorting)
setNewsTimelineLandingPage(bool $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLongDescriptions(array $obj_ids)
const SORT_NEW_ITEMS_POSITION_BOTTOM
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isNewsTimelineLandingPageEffective()
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
const SORT_NEW_ITEMS_ORDER_CREATION
ilLanguage $lng
static getInstance(int $obj_id)
global $DIC
Definition: shib_login.php:25
getClassName(string $obj_name)
static _hasContainerSetting(int $a_id, string $a_keyword)
deleteTranslation(string $a_lang)
static _allocateCopyId()
Allocate a copy for further entries.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
bool $news_timeline_landing_page
static _getContainerDirectory(int $a_id)
static cloneSettingsOfBlock(string $block_type, int $block_id, int $new_block_id)
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
setNewsTimeline(bool $a_val)
static fixContainerItemGroupRefsAfterCloning(ilContainer $a_source_container, int $a_copy_id)
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
cloneAllObject(string $session_id, string $client_id, string $new_type, int $ref_id, int $clone_source, array $options, bool $soap_call=false, int $a_submode=1)
const SORT_NEW_ITEMS_ORDER_ACTIVATION
string $long_desc
$classification
bool $news_timeline_auto_entries
setUseNews(bool $a_val)
global $ilSetting
Definition: privfeed.php:32
getSubItems(bool $a_admin_panel_enabled=false, bool $a_include_side_block=false, int $a_get_single=0, ilContainerUserFilter $container_user_filter=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
const SORT_DIRECTION_DESC
ilRecommendedContentManager $recommended_content_manager
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
static _getInstance(int $a_obj_id)
static _cloneSettings(int $a_old_id, int $a_new_id)
$q
Definition: shib_logout.php:18
getLongDescription()
get object long description (stored in object_description)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
$client_id
Definition: ltiauth.php:67
ilLogger $log
setNewsTimelineAutoEntries(bool $a_val)
static _getInstance(int $a_copy_id)
const SORT_DIRECTION_ASC
setObjectTranslation(?ilObjectTranslation $obj_trans)
debug(string $message, array $context=[])
ILIAS Style Content DomainService $content_style_domain
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
bool $news_block_activated
static _lookupType(int $id, bool $reference=false)
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)
const SORT_NEW_ITEMS_ORDER_TITLE
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getCompleteDescriptions(array $objects)
overwrites description fields to long or short description in an assoc array keys needed (obj_id and ...
ilSetting $setting
static _getContainerSettings(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
static _deleteContainerSettings(int $a_id, string $a_keyword="", bool $a_keyword_like=false)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static bool $data_preloaded