1<?php 2 3declare(strict_types=1); 4 5use ILIAS\UI\Renderer; 6use ILIAS\UI\Component\Component; 7use ILIAS\UI\Component\Listing\Workflow\Workflow; 8 9/** 10 * Class ilKioskPageRenderer 11 */ 12class ilKioskPageRenderer 13{ 14 public function __construct( 15 ilTemplate $il_global_template, 16 Renderer $ui_renderer, 17 ilTemplate $kiosk_template, 18 ilLSTOCGUI $toc_gui, 19 ilLSLocatorGUI $loc_gui, 20 string $window_base_title 21 ) { 22 $this->il_tpl = $il_global_template; 23 $this->ui_renderer = $ui_renderer; 24 $this->tpl = $kiosk_template; 25 $this->toc_gui = $toc_gui; 26 $this->loc_gui = $loc_gui; 27 $this->window_base_title = $window_base_title; 28 } 29 30 public function render( 31 string $lso_title, 32 LSControlBuilder $control_builder, 33 string $obj_title, 34 Component $icon, 35 array $content, 36 Workflow $curriculum 37 ) : string { 38 $this->tpl->setVariable( 39 "HTML_PAGE_TITLE", 40 $this->window_base_title . ' - ' . $lso_title 41 ); 42 43 $this->tpl->setVariable( 44 "TOPBAR_CONTROLS", 45 $this->ui_renderer->render($control_builder->getExitControl()) 46 ); 47 48 $this->tpl->setVariable("TOPBAR_TITLE", $lso_title); 49 50 $this->tpl->setVariable( 51 "OBJECT_ICON", 52 $this->ui_renderer->render($icon) 53 ); 54 $this->tpl->setVariable("OBJECT_TITLE", $obj_title); 55 56 $this->tpl->setVariable( 57 "PLAYER_NAVIGATION", 58 $this->ui_renderer->render([ 59 $control_builder->getPreviousControl(), 60 $control_builder->getNextControl() 61 ]) 62 ); 63 64 $controls = $control_builder->getControls(); 65 66 //ensure done control is first element 67 if ($control_builder->getDoneControl()) { 68 array_unshift($controls, $control_builder->getDoneControl()); 69 } 70 //also shift start control up front - this is for legacy-views only! 71 if ($control_builder->getStartControl()) { 72 array_unshift($controls, $control_builder->getStartControl()); 73 $this->tpl->setVariable("JS_INLINE", $control_builder->getAdditionalJS()); 74 } 75 76 77 //TODO: insert toggles 78 79 $this->tpl->setVariable( 80 "OBJ_NAVIGATION", 81 $this->ui_renderer->render($controls) 82 ); 83 84 85 $this->tpl->setVariable( 86 "VIEW_MODES", 87 $this->ui_renderer->render($control_builder->getModeControls()) 88 ); 89 90 if ($control_builder->getLocator()) { 91 $this->tpl->setVariable( 92 'LOCATOR', 93 $this->ui_renderer->render( 94 $this->loc_gui 95 ->withItems($control_builder->getLocator()->getItems()) 96 ->getComponent() 97 ) 98 ); 99 } 100 101 $this->tpl->setVariable( 102 'CONTENT', 103 $this->ui_renderer->render($content) 104 ); 105 $this->tpl->setVariable( 106 'CURRICULUM', 107 $this->ui_renderer->render($curriculum) 108 ); 109 110 if ($control_builder->getToc()) { 111 $this->tpl->touchBlock("sidebar_space"); 112 $this->tpl->setVariable( 113 "SIDEBAR", 114 $this->toc_gui 115 ->withStructure($control_builder->getToc()->toJSON()) 116 ->getHTML() 117 ); 118 } else { 119 $this->tpl->touchBlock("sidebar_disabled"); 120 } 121 122 $tpl = $this->setHeaderVars($this->tpl); 123 return $tpl->get(); 124 } 125 126 protected function setHeaderVars(ilTemplate $tpl) 127 { 128 $this->initIlTemplate(); 129 $js_files = $this->getJsFiles(); 130 $js_olc = $this->getOnLoadCode(); 131 $css_files = $this->getCSSFiles(); 132 $css_inline = $this->getInlineCSS(); 133 134 foreach ($js_files as $js_file) { 135 $tpl->setCurrentBlock("js_file"); 136 $tpl->setVariable("JS_FILE", $js_file); 137 $tpl->parseCurrentBlock(); 138 } 139 140 foreach ($css_files as $css_file) { 141 $tpl->setCurrentBlock("css_file"); 142 $tpl->setVariable("CSS_FILE", $css_file); 143 $tpl->parseCurrentBlock(); 144 } 145 146 $tpl->setVariable("CSS_INLINE", implode(PHP_EOL, $css_inline)); 147 $tpl->setVariable("OLCODE", $js_olc); 148 149 return $tpl; 150 } 151 152 protected function initIlTemplate() 153 { 154 iljQueryUtil::initjQuery($this->il_tpl); 155 ilUIFramework::init($this->il_tpl); 156 } 157 158 protected function getJsFiles() 159 { 160 $js_files = $this->il_tpl->js_files_batch; 161 $sorted = [ 162 [],[],[],[] 163 ]; 164 foreach ($js_files as $file => $order) { 165 $order = min($order, 3); 166 $sorted[$order][] = $file; 167 } 168 $js_files = array_merge($sorted[0], $sorted[1], $sorted[2], $sorted[3]); 169 $js_files = array_filter( 170 $js_files, 171 function ($js_file) { 172 return strpos($js_file, 'Services/FileUpload/js') === false; 173 } 174 ); 175 return $js_files; 176 } 177 178 protected function getOnLoadCode() 179 { 180 $olc = ''; 181 if ($this->il_tpl->on_load_code) { 182 foreach ($this->il_tpl->on_load_code as $key => $value) { 183 $olc .= implode(PHP_EOL, $value); 184 } 185 } 186 return $olc; 187 } 188 189 protected function getCSSFiles() 190 { 191 foreach ($this->il_tpl->css_files as $il_css_file) { 192 $css_files[] = $il_css_file['file']; 193 } 194 foreach ($this->il_tpl->css_files as $il_css_file) { 195 if (!in_array($il_css_file['file'], $css_files)) { 196 $css_files[] = $il_css_file['file']; 197 } 198 } 199 $css_files[] = \ilUtil::getStyleSheetLocation("filesystem", "delos.css"); 200 $css_files[] = \ilUtil::getStyleSheetLocation(); 201 $css_files[] = \ilUtil::getNewContentStyleSheetLocation(); 202 203 return $css_files; 204 } 205 protected function getInlineCSS() 206 { 207 return $this->il_tpl->inline_css; 208 } 209} 210