ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 {
31  protected \ilLanguage $lng;
32  protected \ilObjPortfolio $portfolio;
33  protected ?array $selected_pages = null;
34  protected bool $include_signature;
36  protected \ilObjUser $user;
37  protected \ilCtrl $ctrl;
38 
39  public function __construct(
40  \ilLanguage $lng,
41  \ilCtrl $ctrl,
42  \ilObjPortfolio $portfolio,
43  bool $include_signature = false,
44  array $selected_pages = null,
45  bool $include_declaration = false
46  ) {
47  global $DIC;
48 
49  $this->lng = $lng;
50  $this->ctrl = $ctrl;
51  $this->portfolio = $portfolio;
52  $this->selected_pages = $selected_pages;
53  $this->include_signature = $include_signature;
54  $this->include_declaration = $include_declaration;
55  $this->port_request = $DIC->portfolio()
56  ->internal()
57  ->gui()
58  ->standardRequest();
59  }
60 
61  public function withDeclarationOfAuthorship(
63  \ilObjUser $user
64  ): self {
65  $c = clone $this;
66  $c->declaration_of_authorship = $decl;
67  $c->user = $user;
68  return $c;
69  }
70 
71  public function getSelectionForm(): ?ilPropertyFormGUI
72  {
73  $lng = $this->lng;
74  $ilCtrl = $this->ctrl;
75 
76  $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
77 
78 
79  $form = new \ilPropertyFormGUI();
80 
81  // declaration of authorship
82  if ($this->declaration_of_authorship &&
83  $this->declaration_of_authorship->getForUser($this->user) !== "") {
84  $cb = new \ilCheckboxInputGUI($this->lng->txt("prtf_decl_authorship"), "decl_author");
85  $cb->setInfo($this->declaration_of_authorship->getForUser($this->user));
86  $form->addItem($cb);
87  }
88 
89  // signature
90  $cb = new \ilCheckboxInputGUI($this->lng->txt("prtf_signature"), "signature");
91  $cb->setInfo($this->lng->txt("prtf_signature_info"));
92  $form->addItem($cb);
93 
94 
95  // selection type
96  $radg = new \ilRadioGroupInputGUI($lng->txt("prtf_print_selection"), "sel_type");
97  $radg->setValue("all_pages");
98  $op2 = new \ilRadioOption($lng->txt("prtf_all_pages"), "all_pages");
99  $radg->addOption($op2);
100  $op3 = new \ilRadioOption($lng->txt("prtf_selected_pages"), "selection");
101  $radg->addOption($op3);
102 
103  $nl = new \ilNestedListInputGUI("", "obj_id");
104  $op3->addSubItem($nl);
105 
106  foreach ($pages as $p) {
107  if ($p["type"] != \ilPortfolioPage::TYPE_BLOG) {
108  $nl->addListNode(
109  $p["id"],
110  $p["title"],
111  0,
112  false,
113  false,
114  \ilUtil::getImagePath("icon_pg.svg"),
115  $lng->txt("page")
116  );
117  } else {
118  $nl->addListNode(
119  $p["id"],
120  $lng->txt("obj_blog") . ": " . \ilObject::_lookupTitle($p["title"]),
121  0,
122  false,
123  false,
124  \ilUtil::getImagePath("icon_blog.svg"),
125  $lng->txt("obj_blog")
126  );
127  $pages2 = \ilBlogPosting::getAllPostings($p["title"]);
128  foreach ($pages2 as $p2) {
129  $nl->addListNode(
130  "b" . $p2["id"],
131  $p2["title"],
132  $p["id"],
133  false,
134  false,
135  \ilUtil::getImagePath("icon_pg.svg"),
136  $lng->txt("page")
137  );
138  }
139  }
140  }
141 
142  $form->addItem($radg);
143 
144  $form->addCommandButton("showPrintView", $lng->txt("exp_show_print_view"));
145 
146  $form->setTitle($lng->txt("prtf_print_options"));
147  $form->setFormAction(
148  $ilCtrl->getFormActionByClass(
149  "ilObjPortfolioGUI",
150  "showPrintView"
151  )
152  );
153 
154  return $form;
155  }
156 
157  public function getTemplateInjectors(): array
158  {
159  $resource_collector = new COPage\ResourcesCollector(
161  new \ilPortfolioPage()
162  );
163  $resource_injector = new COPage\ResourcesInjector($resource_collector);
164 
165  return [
166  function ($tpl) use ($resource_injector) {
167  $resource_injector->inject($tpl);
168  }
169  ];
170  }
171 
172  public function getPages(): array
173  {
174  $lng = $this->lng;
175  $portfolio = $this->portfolio;
176 
178  $portfolio->getId()
179  );
180 
181  $print_pages = [];
182 
183  // cover page
184  $cover_tpl = new \ilTemplate(
185  "tpl.prtf_cover.html",
186  true,
187  true,
188  "Modules/Portfolio"
189  );
190  foreach ($pages as $page) {
191  if ($page["type"] != \ilPortfolioPage::TYPE_BLOG) {
192  if (is_array($this->selected_pages) &&
193  !in_array($page["id"], $this->selected_pages)) {
194  continue;
195  }
196  $cover_tpl->setCurrentBlock("content_item");
197  $cover_tpl->setVariable("ITEM_TITLE", $page["title"]);
198  } else {
199  $cover_tpl->setCurrentBlock("content_item");
200  $cover_tpl->setVariable("ITEM_TITLE", $lng->txt("obj_blog") . ": " . \ilObject::_lookupTitle($page["title"]));
201  }
202  $cover_tpl->parseCurrentBlock();
203  }
204 
205  if ($this->include_signature) {
206  $cover_tpl->setCurrentBlock("signature");
207  $cover_tpl->setVariable("TXT_SIGNATURE", $lng->txt("prtf_signature_date"));
208  $cover_tpl->parseCurrentBlock();
209  }
210 
211  if (!is_null($this->declaration_of_authorship) && $this->include_declaration) {
212  $cover_tpl->setCurrentBlock("decl_author");
213  $cover_tpl->setVariable(
214  "TXT_DECL_AUTHOR",
215  nl2br($this->declaration_of_authorship->getForUser($this->user))
216  );
217  $cover_tpl->parseCurrentBlock();
218  }
219 
220  $cover_tpl->setVariable("PORTFOLIO_TITLE", $this->portfolio->getTitle());
221  $cover_tpl->setVariable("PORTFOLIO_ICON", \ilUtil::getImagePath("icon_prtf.svg"));
222 
223  $cover_tpl->setVariable("TXT_AUTHOR", $lng->txt("prtf_author"));
224  $cover_tpl->setVariable("TXT_LINK", $lng->txt("prtf_link"));
225  $cover_tpl->setVariable("TXT_DATE", $lng->txt("prtf_date_of_print"));
226 
227  $author = \ilObjUser::_lookupName($this->portfolio->getOwner());
228  $author_str = $author["firstname"] . " " . $author["lastname"];
229  $cover_tpl->setVariable("AUTHOR", $author_str);
230 
231  $href = \ilLink::_getStaticLink($this->portfolio->getId(), "prtf");
232  $cover_tpl->setVariable("LINK", $href);
233 
235  $date_str = \ilDatePresentation::formatDate(new \ilDate(date("Y-m-d"), IL_CAL_DATE));
236  $cover_tpl->setVariable("DATE", $date_str);
237 
238  $print_pages[] = $cover_tpl->get();
239 
240  $page_head_tpl = new \ilTemplate("tpl.prtf_page_head.html", true, true, "Modules/Portfolio");
241  $page_head_tpl->setVariable("AUTHOR", $author_str);
242  $page_head_tpl->setVariable("DATE", $date_str);
243  $page_head_str = $page_head_tpl->get();
244 
245  foreach ($pages as $page) {
246  if ($page["type"] != \ilPortfolioPage::TYPE_BLOG) {
247  if (is_array($this->selected_pages) &&
248  !in_array($page["id"], $this->selected_pages)) {
249  continue;
250  }
251 
252  $page_gui = new \ilPortfolioPageGUI($this->portfolio->getId(), $page["id"]);
253  $page_gui->setOutputMode($this->getOutputMode());
254  $page_gui->setPresentationTitle($page["title"]);
255  $html = $this->ctrl->getHTML($page_gui);
256  $print_pages[] = $page_head_str . $html;
257  } else {
258  $pages2 = \ilBlogPosting::getAllPostings($page["title"]);
259  foreach ($pages2 as $p2) {
260  if ($this->port_request->getPrintSelectedType() === "selection" &&
261  (!in_array("b" . $p2["id"], $this->port_request->getObjIds()))) {
262  continue;
263  }
264  $page_gui = new \ilBlogPostingGUI(0, null, $p2["id"]);
265  $page_gui->setFileDownloadLink("#");
266  $page_gui->setFullscreenLink("#");
267  $page_gui->setSourcecodeDownloadScript("#");
268  $page_gui->setOutputMode($this->getOutputMode());
269  $print_pages[] = $page_head_str . $page_gui->showPage(\ilObject::_lookupTitle($page["title"]) . ": " . $page_gui->getBlogPosting()->getTitle());
270  }
271  }
272  }
273 
274  return $print_pages;
275  }
276 }
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
$c
Definition: cli.php:38
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...
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)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
static setUseRelativeDates(bool $a_status)
set use relative dates