ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.PrintProcessGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Export;
22
23use ILIAS\HTTP;
26
31{
32 protected \ILIAS\GlobalScreen\Services $gs;
33 protected \ilGlobalTemplateInterface $main_tpl;
37 protected array $injectors = [];
38 protected ?string $body_class = null;
39
41 protected UIServices $ui;
42 protected \ilLanguage $lng;
44
53 public function __construct(
58 ?string $body_class = null
59 ) {
60 global $DIC;
61
62 $this->provider = $provider;
63 $this->ui = $ui;
64 $this->lng = $lng;
65 $this->http = $http;
66 $this->body_class = $body_class ?? "ilPrtfPdfBody"; // todo: move this class
67 $this->lng->loadLanguageModule("exp");
68 $this->gs = $DIC->globalScreen();
69 }
70
75 public function setOffline(bool $offline)
76 {
77 $this->provider->setOffline($offline);
78 }
79
80 // injectors are used to add css/js files to the template
81 public function addTemplateInjector(callable $f): void
82 {
83 $this->injectors[] = $f;
84 }
85
86 public function getModalElements(
87 string $selection_action
88 ): \stdClass {
89 $ui = $this->ui;
91
92 $ui->mainTemplate()->addJavaScript("assets/js/Form.js");
93 $modal = $ui->factory()->modal()->roundtrip(
94 $this->lng->txt("exp_print_pdf"),
95 $ui->factory()->legacy()->content('some modal')
96 )->withAsyncRenderUrl($selection_action);
97 $print_button = $ui->factory()->button()->standard(
98 $this->lng->txt("exp_print_pdf"),
99 $modal->getShowSignal()
100 );
101 $elements = new \stdClass();
102 $elements->button = $print_button;
103 $elements->modal = $modal;
104
105 return $elements;
106 }
107
112 public function sendForm(): void
113 {
114 $form = $this->provider->getSelectionForm();
115 $mb = $this->ui->factory()->messageBox()->info($this->lng->txt("exp_print_pdf_info"));
116 $tpl = new \ilTemplate("tpl.print_view_selection.html", true, true, "components/ILIAS/Export/Print");
117 $form->setTarget("print_view");
118 $tpl->setVariable("FORM", $form->getHTML());
119 $tpl->setVariable("ON_SUBMIT_CODE", $this->provider->getOnSubmitCode());
120 $modal = $this->ui->factory()->modal()->roundtrip(
121 $this->lng->txt("exp_print_pdf"),
122 $this->ui->factory()->legacy()->content(
123 $this->ui->renderer()->render($mb) .
124 $tpl->get()
125 )
126 );
127
128 $this->send($this->ui->renderer()->render($modal));
129 }
130
131 public function renderPrintView(int $content_style_id = 0): string
132 {
133 \iljQueryUtil::initjQuery(); // e.g. on survey print screens necessary
134 $pages = $this->provider->getPages();
135 $tpl = new \ilGlobalTemplate(
136 "tpl.print_view.html",
137 true,
138 true,
139 "components/ILIAS/Export/Print"
140 );
141
142 // get all current resources from globalscreen and add them to our template
143 foreach ($this->gs->layout()->meta()->getJs()->getItemsInOrderOfDelivery() as $js) {
144 $path = explode("?", $js->getContent());
145 $file = $path[0];
146 $tpl->addJavaScript($file, $js->addVersionNumber());
147 }
148 foreach ($this->gs->layout()->meta()->getOnLoadCode()->getItemsInOrderOfDelivery() as $code) {
149 $tpl->addOnLoadCode($code->getContent());
150 }
151
152 //\iljQueryUtil::initjQuery($tpl);
153
154 foreach ($this->provider->getTemplateInjectors() as $f) {
155 $f($tpl);
156 }
157
158 $tpl->setBodyClass($this->body_class);
159 $tpl->addCss(\ilUtil::getStyleSheetLocation("filesystem"));
160 $tpl->addCss(
162 $content_style_id,
163 false
164 )
165 );
168
169 $pb = ($this->provider->autoPageBreak())
170 ? '<div style="page-break-after:always;"></div>'
171 : "";
172
173 $content = implode(
174 $pb,
175 $pages
176 );
177
178 $content = '<div class="ilInvisibleBorder">' . $content . '</div>';
179 $tpl->addOnLoadCode("il.Util.print();");
180
181 $tpl->setVariable("CONTENT", $content);
182 return $tpl->printToString();
183 }
184
188 public function sendPrintView(int $content_style_id = 0): void
189 {
190 $this->send($this->renderPrintView($content_style_id));
191 }
192
198 protected function send(string $output)
199 {
200 $this->http->saveResponse($this->http->response()->withBody(
201 Streams::ofString($output)
202 ));
203 $this->http->sendResponse();
204 $this->http->close();
205 }
206}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
mainTemplate()
Get the ILIAS main template.
Definition: UIServices.php:54
factory()
Get the factory that crafts UI components.
Definition: UIServices.php:36
__construct(PrintViewProvider $provider, \ILIAS\HTTP\Services $http, UIServices $ui, \ilLanguage $lng, ?string $body_class=null)
PrintViewGUI constructor.
ilGlobalTemplateInterface $main_tpl
ILIAS GlobalScreen Services $gs
getModalElements(string $selection_action)
sendPrintView(int $content_style_id=0)
renderPrintView(int $content_style_id=0)
setOffline(bool $offline)
Set output mode.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
Class Services.
Definition: Services.php:38
language handling
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:100