ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.PortfolioPrintViewProviderGUI.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\Portfolio;
20 
21 use ILIAS\COPage;
22 use ILIAS\Export;
24 
29 {
30  protected bool $include_declaration = false;
32  protected \ilLanguage $lng;
33  protected \ilObjPortfolio $portfolio;
34  protected ?array $selected_pages = null;
35  protected bool $include_signature;
37  protected \ilObjUser $user;
38  protected \ilCtrl $ctrl;
39 
40  public function __construct(
41  \ilLanguage $lng,
42  \ilCtrl $ctrl,
43  \ilObjPortfolio $portfolio,
44  bool $include_signature = false,
45  array $selected_pages = null,
46  bool $include_declaration = false
47  ) {
48  global $DIC;
49 
50  $this->lng = $lng;
51  $this->ctrl = $ctrl;
52  $this->portfolio = $portfolio;
53  $this->selected_pages = $selected_pages;
54  $this->include_signature = $include_signature;
55  $this->include_declaration = $include_declaration;
56  $this->port_request = $DIC->portfolio()
57  ->internal()
58  ->gui()
59  ->standardRequest();
60  }
61 
62  public function withDeclarationOfAuthorship(
64  \ilObjUser $user
65  ): self {
66  $c = clone $this;
67  $c->declaration_of_authorship = $decl;
68  $c->user = $user;
69  return $c;
70  }
71 
72  public function getSelectionForm(): ?ilPropertyFormGUI
73  {
74  $lng = $this->lng;
75  $ilCtrl = $this->ctrl;
76 
77  $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
78 
79 
80  $form = new \ilPropertyFormGUI();
81 
82  // declaration of authorship
83  if ($this->declaration_of_authorship &&
84  $this->declaration_of_authorship->getForUser($this->user) !== "") {
85  $cb = new \ilCheckboxInputGUI($this->lng->txt("prtf_decl_authorship"), "decl_author");
86  $cb->setInfo($this->declaration_of_authorship->getForUser($this->user));
87  $form->addItem($cb);
88  }
89 
90  // signature
91  $cb = new \ilCheckboxInputGUI($this->lng->txt("prtf_signature"), "signature");
92  $cb->setInfo($this->lng->txt("prtf_signature_info"));
93  $form->addItem($cb);
94 
95 
96  // selection type
97  $radg = new \ilRadioGroupInputGUI($lng->txt("prtf_print_selection"), "sel_type");
98  $radg->setValue("all_pages");
99  $op2 = new \ilRadioOption($lng->txt("prtf_all_pages"), "all_pages");
100  $radg->addOption($op2);
101  $op3 = new \ilRadioOption($lng->txt("prtf_selected_pages"), "selection");
102  $radg->addOption($op3);
103 
104  $nl = new \ilNestedListInputGUI("", "obj_id");
105  $op3->addSubItem($nl);
106 
107  foreach ($pages as $p) {
108  if ($p["type"] != \ilPortfolioPage::TYPE_BLOG) {
109  $nl->addListNode(
110  $p["id"],
111  $p["title"],
112  0,
113  false,
114  false,
115  \ilUtil::getImagePath("standard/icon_pg.svg"),
116  $lng->txt("page")
117  );
118  } else {
119  $nl->addListNode(
120  $p["id"],
121  $lng->txt("obj_blog") . ": " . \ilObject::_lookupTitle($p["title"]),
122  0,
123  false,
124  false,
125  \ilUtil::getImagePath("standard/icon_blog.svg"),
126  $lng->txt("obj_blog")
127  );
128  $pages2 = \ilBlogPosting::getAllPostings($p["title"]);
129  foreach ($pages2 as $p2) {
130  $nl->addListNode(
131  "b" . $p2["id"],
132  $p2["title"],
133  $p["id"],
134  false,
135  false,
136  \ilUtil::getImagePath("standard/icon_pg.svg"),
137  $lng->txt("page")
138  );
139  }
140  }
141  }
142 
143  $form->addItem($radg);
144 
145  $form->addCommandButton("showPrintView", $lng->txt("exp_show_print_view"));
146 
147  $form->setTitle($lng->txt("prtf_print_options"));
148  $form->setFormAction(
149  $ilCtrl->getFormActionByClass(
150  "ilObjPortfolioGUI",
151  "showPrintView"
152  )
153  );
154 
155  return $form;
156  }
157 
158  public function getTemplateInjectors(): array
159  {
160  $page = new \ilPortfolioPage();
161  $page->setEmptyPageXml();
162  $resource_collector = new COPage\ResourcesCollector(
164  $page
165  );
166  $resource_injector = new COPage\ResourcesInjector($resource_collector);
167 
168  return [
169  function ($tpl) use ($resource_injector) {
170  $resource_injector->inject($tpl);
171  }
172  ];
173  }
174 
175  public function getPages(): array
176  {
177  $lng = $this->lng;
178  $portfolio = $this->portfolio;
179 
181  $portfolio->getId()
182  );
183 
184  $print_pages = [];
185 
186  // cover page
187  $cover_tpl = new \ilTemplate(
188  "tpl.prtf_cover.html",
189  true,
190  true,
191  "Modules/Portfolio"
192  );
193  foreach ($pages as $page) {
194  if ($page["type"] != \ilPortfolioPage::TYPE_BLOG) {
195  if (is_array($this->selected_pages) &&
196  !in_array($page["id"], $this->selected_pages)) {
197  continue;
198  }
199  $cover_tpl->setCurrentBlock("content_item");
200  $cover_tpl->setVariable("ITEM_TITLE", $page["title"]);
201  } else {
202  $cover_tpl->setCurrentBlock("content_item");
203  $cover_tpl->setVariable("ITEM_TITLE", $lng->txt("obj_blog") . ": " . \ilObject::_lookupTitle($page["title"]));
204  }
205  $cover_tpl->parseCurrentBlock();
206  }
207 
208  if ($this->include_signature) {
209  $cover_tpl->setCurrentBlock("signature");
210  $cover_tpl->setVariable("TXT_SIGNATURE", $lng->txt("prtf_signature_date"));
211  $cover_tpl->parseCurrentBlock();
212  }
213 
214  if (!is_null($this->declaration_of_authorship) && $this->include_declaration) {
215  $cover_tpl->setCurrentBlock("decl_author");
216  $cover_tpl->setVariable(
217  "TXT_DECL_AUTHOR",
218  nl2br($this->declaration_of_authorship->getForUser($this->user))
219  );
220  $cover_tpl->parseCurrentBlock();
221  }
222 
223  $cover_tpl->setVariable("PORTFOLIO_TITLE", $this->portfolio->getTitle());
224  $cover_tpl->setVariable("PORTFOLIO_ICON", \ilUtil::getImagePath("standard/icon_prtf.svg"));
225 
226  $cover_tpl->setVariable("TXT_AUTHOR", $lng->txt("prtf_author"));
227  $cover_tpl->setVariable("TXT_LINK", $lng->txt("prtf_link"));
228  $cover_tpl->setVariable("TXT_DATE", $lng->txt("prtf_date_of_print"));
229 
230  $author = \ilObjUser::_lookupName($this->portfolio->getOwner());
231  $author_str = $author["firstname"] . " " . $author["lastname"];
232  $cover_tpl->setVariable("AUTHOR", $author_str);
233 
234  $href = \ilLink::_getStaticLink($this->portfolio->getId(), "prtf");
235  $cover_tpl->setVariable("LINK", $href);
236 
238  $date_str = \ilDatePresentation::formatDate(new \ilDate(date("Y-m-d"), IL_CAL_DATE));
239  $cover_tpl->setVariable("DATE", $date_str);
240 
241  $print_pages[] = $cover_tpl->get();
242 
243  $page_head_tpl = new \ilTemplate("tpl.prtf_page_head.html", true, true, "Modules/Portfolio");
244  $page_head_tpl->setVariable("AUTHOR", $author_str);
245  $page_head_tpl->setVariable("DATE", $date_str);
246  $page_head_str = $page_head_tpl->get();
247 
248  foreach ($pages as $page) {
249  if ($page["type"] != \ilPortfolioPage::TYPE_BLOG) {
250  if (is_array($this->selected_pages) &&
251  !in_array($page["id"], $this->selected_pages)) {
252  continue;
253  }
254 
255  $page_gui = new \ilPortfolioPageGUI($this->portfolio->getId(), $page["id"]);
256  $page_gui->setOutputMode($this->getOutputMode());
257  $page_gui->setPresentationTitle($page["title"]);
258  $html = $this->ctrl->getHTML($page_gui);
259  $print_pages[] = $page_head_str . $html;
260  } else {
261  $pages2 = \ilBlogPosting::getAllPostings($page["title"]);
262  foreach ($pages2 as $p2) {
263  if ($this->port_request->getPrintSelectedType() === "selection" &&
264  (!in_array("b" . $p2["id"], $this->port_request->getObjIds()))) {
265  continue;
266  }
267  $page_gui = new \ilBlogPostingGUI(0, null, $p2["id"]);
268  $page_gui->setFileDownloadLink("#");
269  $page_gui->setFullscreenLink("#");
270  $page_gui->setSourcecodeDownloadScript("#");
271  $page_gui->setOutputMode($this->getOutputMode());
272  $print_pages[] = $page_head_str . $page_gui->showPage(\ilObject::_lookupTitle($page["title"]) . ": " . $page_gui->getBlogPosting()->getTitle());
273  }
274  }
275  }
276 
277  return $print_pages;
278  }
279 }
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Injects resources into a template.
static _lookupTitle(int $obj_id)
Collects all js/css/onload resources necessary for page rendering.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: PageLinker.php:19
const IL_CAL_DATE
withDeclarationOfAuthorship(\ilPortfolioDeclarationOfAuthorship $decl, \ilObjUser $user)
getSelectionForm()
form which is featured in the modal form target is modified to open in new window (not yet possible w...
__construct(\ilLanguage $lng, \ilCtrl $ctrl, \ilObjPortfolio $portfolio, bool $include_signature=false, array $selected_pages=null, bool $include_declaration=false)
static setUseRelativeDates(bool $a_status)
set use relative dates