ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ResourcesCollector.php
Go to the documentation of this file.
1 <?php
2 
19 namespace 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  }
71 
72  $this->js_files[] = "components/ILIAS/COPage/js/ilCOPagePres.js";
73 
74  // for all page components...
75  $defs = $this->pc_definition->getPCDefinitions();
76  $pg->buildDom();
77  foreach ($defs as $def) {
78  $pc_class = $def["pc_class"];
80  $pc_obj = new $pc_class($pg);
81 
82  // javascript files
83  $js_files = $pc_obj->getJavascriptFiles($this->output_mode);
84  foreach ($js_files as $js) {
85  if (!in_array($js, $this->js_files)) {
86  $this->js_files[] = $js;
87  }
88  }
89 
90  // css files
91  $css_files = $pc_obj->getCssFiles($this->output_mode);
92  foreach ($css_files as $css) {
93  if (!in_array($css, $this->css_files)) {
94  $this->css_files[] = $css;
95  }
96  }
97 
98  // onload code
99  $onload_code = $pc_obj->getOnloadCode($this->output_mode);
100  foreach ($onload_code as $code) {
101  $this->onload_code[] = $code;
102  }
103  }
104  }
105 
106  public function getJavascriptFiles(): array
107  {
108  return $this->js_files;
109  }
110 
111  public function getCssFiles(): array
112  {
113  return $this->css_files;
114  }
115 
116  public function getOnloadCode(): array
117  {
118  return $this->onload_code;
119  }
120 }
__construct(string $output_mode, ?\ilPageObject $pg=null)
Constructor, currently has a dependency to ilPageObject due to historic reasons, this should be remov...
buildDom(bool $a_force=false)
static getLocaljQueryUIPath()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Collects all js/css/onload resources necessary for page rendering.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:22
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: PageLinker.php:19
static getLocaljQueryPath()