ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ResourcesCollector.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\COPage;
20
27{
28 protected $pc_definition;
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[] = \iljQueryUtil::getLocaljQueryUIPath();
69 $this->js_files[] = 'assets/js/Basic.js';
70 $this->js_files[] = 'assets/js/mathjax_config.js';
71 $this->js_files[] = 'node_modules/mathjax/es5/tex-chtml-full.js';
72 }
73
74 $this->js_files[] = "components/ILIAS/COPage/js/ilCOPagePres.js";
75
76 // for all page components...
77 $defs = $this->pc_definition->getPCDefinitions();
78 $pg->buildDom();
79 foreach ($defs as $def) {
80 $pc_class = $def["pc_class"];
82 $pc_obj = new $pc_class($pg);
83
84 // javascript files
85 $js_files = $pc_obj->getJavascriptFiles($this->output_mode);
86 foreach ($js_files as $js) {
87 if (!in_array($js, $this->js_files)) {
88 $this->js_files[] = $js;
89 }
90 }
91
92 // css files
93 $css_files = $pc_obj->getCssFiles($this->output_mode);
94 foreach ($css_files as $css) {
95 if (!in_array($css, $this->css_files)) {
96 $this->css_files[] = $css;
97 }
98 }
99
100 // onload code
101 $onload_code = $pc_obj->getOnloadCode($this->output_mode);
102 foreach ($onload_code as $code) {
103 $this->onload_code[] = $code;
104 }
105 }
106 }
107
108 public function getJavascriptFiles(): array
109 {
110 return $this->js_files;
111 }
112
113 public function getCssFiles(): array
114 {
115 return $this->css_files;
116 }
117
118 public function getOnloadCode(): array
119 {
120 return $this->onload_code;
121 }
122}
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 getLocaljQueryUIPath()
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