ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ResourcesCollector.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\COPage;
20
22
27{
29 protected string $output_mode = "";
30 protected array $js_files = [];
31 protected array $css_files = [];
32 protected array $onload_code = [];
33
39 public function __construct(
40 string $output_mode,
41 ?\ilPageObject $pg = null
42 ) {
43 global $DIC;
44
45 // workaround (note that pcquestion currently checks for page config, if self assessment is enabled
46 if (is_null($pg)) {
47 $pg = new \ilLMPage();
48 }
49 if ($pg->getXMLContent() === "") {
50 $pg->setXMLContent("<PageObject></PageObject>");
51 }
52 $this->output_mode = $output_mode;
53 $this->pc_definition = $DIC
54 ->copage()
55 ->internal()
56 ->domain()
57 ->pc()
58 ->definition();
59 $this->init($pg);
60 }
61
62 protected function init(\ilPageObject $pg): void
63 {
64 // basic files must be copied of offline version as well
65 // (for all other modes they are included automatically)
66 if ($this->output_mode == \ilPageObjectGUI::OFFLINE) {
67 $this->js_files[] = \iljQueryUtil::getLocaljQueryPath();
68 $this->js_files[] = 'assets/js/Basic.js';
69 $this->js_files[] = 'assets/js/mathjax_config.js';
70 $this->js_files[] = 'node_modules/mathjax/es5/tex-chtml-full.js';
71 }
72
73 $this->js_files[] = "components/ILIAS/COPage/js/ilCOPagePres.js";
74
75 // for all page components...
76 $defs = $this->pc_definition->getPCDefinitions();
77 $pg->buildDom();
78 foreach ($defs as $def) {
79 $pc_class = $def["pc_class"];
81 $pc_obj = new $pc_class($pg);
82
83 // javascript files
84 $js_files = $pc_obj->getJavascriptFiles($this->output_mode);
85 foreach ($js_files as $js) {
86 if (!in_array($js, $this->js_files)) {
87 $this->js_files[] = $js;
88 }
89 }
90
91 // css files
92 $css_files = $pc_obj->getCssFiles($this->output_mode);
93 foreach ($css_files as $css) {
94 if (!in_array($css, $this->css_files)) {
95 $this->css_files[] = $css;
96 }
97 }
98
99 // onload code
100 $onload_code = $pc_obj->getOnloadCode($this->output_mode);
101 foreach ($onload_code as $code) {
102 $this->onload_code[] = $code;
103 }
104 }
105 }
106
107 public function getJavascriptFiles(): array
108 {
109 return $this->js_files;
110 }
111
112 public function getCssFiles(): array
113 {
114 return $this->css_files;
115 }
116
117 public function getOnloadCode(): array
118 {
119 return $this->onload_code;
120 }
121}
Collects all js/css/onload resources necessary for page rendering.
__construct(string $output_mode, ?\ilPageObject $pg=null)
Constructor, currently has a dependency to ilPageObject due to historic reasons, this should be remov...
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
Definition: COPage.php:25
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
buildDom(bool $a_force=false)
static getLocaljQueryPath()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26