ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPortfolioPage.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  public const TYPE_PAGE = 1;
27 
28  protected int $portfolio_id;
29  protected int $type = 1;
30  protected string $title;
31  protected int $order_nr;
32 
33  public function afterConstructor(): void
34  {
35  global $DIC;
36  $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
37  }
38 
39  public function getParentType(): string
40  {
41  return "prtf";
42  }
43 
44  public function setPortfolioId(int $a_val): void
45  {
46  $this->portfolio_id = $a_val;
47  }
48 
49  public function getPortfolioId(): int
50  {
51  return $this->portfolio_id;
52  }
53 
57  public function setType(int $a_val): void
58  {
59  $this->type = $a_val;
60  }
61 
62  public function getType(): int
63  {
64  return $this->type;
65  }
66 
67  public function setTitle(string $a_title): void
68  {
69  $this->title = $a_title;
70  }
71 
72  public function getTitle(): string
73  {
74  $lng = $this->lng;
75 
76  // because of migration of extended user profiles
77  if ($this->title === "###-") {
78  return $lng->txt("profile");
79  }
80 
81  return $this->title;
82  }
83 
84  public function setOrderNr(int $a_val): void
85  {
86  $this->order_nr = $a_val;
87  }
88 
89  public function getOrderNr(): int
90  {
91  return $this->order_nr;
92  }
93 
94  public static function lookupMaxOrderNr(
95  int $a_portfolio_id
96  ): int {
97  global $DIC;
98 
99  $ilDB = $DIC->database();
100 
101  $set = $ilDB->query("SELECT MAX(order_nr) m FROM usr_portfolio_page" .
102  " WHERE portfolio_id = " . $ilDB->quote($a_portfolio_id, "integer"));
103  $rec = $ilDB->fetchAssoc($set);
104  return (int) $rec["m"];
105  }
106 
107  protected function getPropertiesForDB(): array
108  {
109  $fields = array(
110  "portfolio_id" => array("integer", $this->portfolio_id),
111  "type" => array("integer", $this->getType()),
112  "title" => array("text", $this->getTitle()),
113  "order_nr" => array("integer", $this->getOrderNr())
114  );
115 
116  return $fields;
117  }
118 
119  public function create(bool $a_import = false): void
120  {
121  $ilDB = $this->db;
122 
123  if (!$a_import) {
124  $this->setOrderNr(self::lookupMaxOrderNr($this->portfolio_id) + 10);
125  }
126 
127  $id = $ilDB->nextId("usr_portfolio_page");
128  $this->setId($id);
129 
130  $fields = $this->getPropertiesForDB();
131  $fields["id"] = array("integer", $id);
132 
133  $ilDB->insert("usr_portfolio_page", $fields);
134 
135  if (!$a_import) {
136  parent::create($a_import);
137  // $this->saveInternalLinks($this->getDomDoc());
138  }
139  }
140 
141  public function update(
142  bool $a_validate = true,
143  bool $a_no_history = false
144  ) {
145  $ilDB = $this->db;
146 
147  $id = $this->getId();
148  if ($id) {
149  $fields = $this->getPropertiesForDB();
150  $ilDB->update(
151  "usr_portfolio_page",
152  $fields,
153  array("id" => array("integer", $id))
154  );
155 
156  return parent::update($a_validate, $a_no_history);
157  }
158  return false;
159  }
160 
161  public function read(): void
162  {
163  $ilDB = $this->db;
164 
165  $query = "SELECT * FROM usr_portfolio_page" .
166  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
167  $set = $ilDB->query($query);
168  $rec = $ilDB->fetchAssoc($set);
169 
170  $this->setPortfolioId($rec["portfolio_id"]);
171  $this->setType($rec["type"]);
172  $this->setTitle($rec["title"]);
173  $this->setOrderNr($rec["order_nr"]);
174 
175  // get co page
176  parent::read();
177  }
178 
179  public function delete(): void
180  {
181  $ilDB = $this->db;
182 
183  $id = $this->getId();
184  if ($id) {
185  // delete internal links information to this page
187 
188  // delete record of table usr_portfolio_page
189  $query = "DELETE FROM usr_portfolio_page" .
190  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
191  $ilDB->manipulate($query);
192 
193  // delete co page
194  parent::delete();
195  }
196  }
197 
198  protected static function lookupProperty(
199  int $a_id,
200  string $a_prop
201  ): string {
202  global $DIC;
203 
204  $ilDB = $DIC->database();
205 
206  $set = $ilDB->query("SELECT " . $a_prop .
207  " FROM usr_portfolio_page" .
208  " WHERE id = " . $ilDB->quote($a_id, "integer"));
209  $rec = $ilDB->fetchAssoc($set);
210  return (string) ($rec[$a_prop] ?? "");
211  }
212 
213  public static function lookupTitle(int $a_page_id): string
214  {
215  return self::lookupProperty($a_page_id, "title");
216  }
217 
218  public static function lookupType($a_page_id): int
219  {
220  return (int) self::lookupProperty($a_page_id, "type");
221  }
222 
226  public static function getAllPortfolioPages(
227  int $a_portfolio_id
228  ): array {
229  global $DIC;
230 
231  $ilDB = $DIC->database();
232  $lng = $DIC->language();
233 
234  $set = $ilDB->query("SELECT * FROM usr_portfolio_page" .
235  " WHERE portfolio_id = " . $ilDB->quote($a_portfolio_id, "integer") .
236  " ORDER BY order_nr");
237  $pages = array();
238  while ($rec = $ilDB->fetchAssoc($set)) {
239  // because of migration of extended user profiles
240  if ($rec["title"] == "###-") {
241  $rec["title"] = $lng->txt("profile");
242  }
243 
244  $pages[] = $rec;
245  }
246  return $pages;
247  }
248 
249  public static function fixOrdering(
250  int $a_portfolio_id
251  ): void {
252  global $DIC;
253 
254  $ilDB = $DIC->database();
255 
256  $pages = self::getAllPortfolioPages($a_portfolio_id);
257  $cnt = 10;
258  foreach ($pages as $p) {
259  $ilDB->manipulate(
260  "UPDATE usr_portfolio_page SET " .
261  " order_nr = " . $ilDB->quote($cnt, "integer") .
262  " WHERE id = " . $ilDB->quote($p["id"], "integer")
263  );
264  $cnt += 10;
265  }
266  }
267 
271  public static function findPortfolioForPage(int $a_page_id): int
272  {
273  return (int) self::lookupProperty($a_page_id, "portfolio_id");
274  }
275 
279  public static function getGotoForPortfolioPageTarget(
280  int $a_target,
281  bool $a_offline = false
282  ): string {
283  global $DIC;
284 
285  $pid = self::findPortfolioForPage($a_target);
286  $type = ilObject::_lookupType($pid);
287  if ($type === "prtt") {
288  $ctrl = $DIC->ctrl();
289  $ctrl->setParameterByClass("ilobjportfoliotemplategui", "user_page", $a_target);
290  $href = $ctrl->getLinkTargetByClass(array(
291  "ilRepositoryGUI",
292  "ilObjPortfolioTemplateGUI"
293  ), "preview", "", false, true);
294  } else {
295  if (!$a_offline) {
296  $href = "./goto.php?client_id=" . CLIENT_ID . "&amp;target=prtf_" . $pid . "_" . $a_target;
297  } else {
298  $href = "prtf_" . $a_target . ".html";
299  }
300  }
301  return $href;
302  }
303 
307  public static function updateInternalLinks(
308  array $a_copied_nodes,
309  ilObjPortfolioBase $a_target_obj
310  ): void {
311  $all_fixes = array();
312  $tpg = null;
313 
314  foreach ($a_copied_nodes as $original_id => $copied_id) {
315  $pid = self::findPortfolioForPage((int) $copied_id);
316 
317  //
318  // 1. Outgoing links from the copied page.
319  //
320  //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
321  if ($a_target_obj->getType() === "prtf") {
322  $tpg = new ilPortfolioPage($copied_id);
323  }
324  if ($a_target_obj->getType() === "prtt") {
325  $tpg = new ilPortfolioTemplatePage($copied_id);
326  }
327  $tpg->buildDom();
328  $il = $tpg->getInternalLinks();
329  // var_dump($il);
330  $targets = array();
331  foreach ($il as $l) {
332  $targets[] = array(
333  "type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
334  "id" => ilInternalLink::_extractObjIdOfTarget($l["Target"]),
335  "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"])
336  );
337  }
338  $fix = array();
339  foreach ($targets as $target) {
340  if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
341  ($target["type"] == "ppage")) {
342  // first check, whether target is also within the copied set
343  if ($a_copied_nodes[$target["id"]] > 0) {
344  $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
345  }
346  }
347  }
348  // var_dump($fix);
349  // outgoing links to be fixed
350  if (count($fix) > 0) {
351  $t = ilObject::_lookupType($pid);
352  if (is_array($all_fixes[$t . ":" . $copied_id] ?? false)) {
353  $all_fixes[$t . ":" . $copied_id] += $fix;
354  } else {
355  $all_fixes[$t . ":" . $copied_id] = $fix;
356  }
357  }
358  }
359  // var_dump($all_fixes);
360  foreach ($all_fixes as $pg => $fixes) {
361  $pg = explode(":", $pg);
362  $page = ilPageObjectFactory::getInstance($pg[0], $pg[1]);
363  if ($page->moveIntLinks($fixes)) {
364  $page->update(true, true);
365  }
366  }
367  }
368 
369 
370  public function renameLinksOnTitleChange(
371  array $a_title_changes
372  ): bool {
373  $this->buildDom();
374 
375  $changed = false;
376 
377  // resolve normal internal links
378  $path = "//IntLink";
379  $nodes = $this->dom_util->path($this->getDomDoc(), $path);
380  foreach ($nodes as $node) {
381  $target = $node->getAttribute("Target");
382  $type = $node->getAttribute("Type");
383  $obj_id = ilInternalLink::_extractObjIdOfTarget($target);
384  if (isset($a_title_changes[$obj_id]) && is_int(strpos($target, "__"))) {
385  if ($type == "PortfolioPage") {
386  if ($this->dom_util->getContent($node) == $a_title_changes[$obj_id]["old"]) {
387  $this->dom_util->setContent($node, $a_title_changes[$obj_id]["new"]);
388  $changed = true;
389  }
390  }
391  }
392  }
393 
394  return $changed;
395  }
396 }
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
static lookupProperty(int $a_id, string $a_prop)
buildDom(bool $a_force=false)
const IL_INST_ID
Definition: constants.php:40
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
update(bool $a_validate=true, bool $a_no_history=false)
getDomDoc()
Get dom doc (DOMDocument)
static lookupType($a_page_id)
$path
Definition: ltiservices.php:29
create(bool $a_import=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
renameLinksOnTitleChange(array $a_title_changes)
static lookupMaxOrderNr(int $a_portfolio_id)
static updateInternalLinks(array $a_copied_nodes, ilObjPortfolioBase $a_target_obj)
Update internal links, after multiple pages have been copied.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: shib_login.php:22
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...
static getGotoForPortfolioPageTarget(int $a_target, bool $a_offline=false)
Get goto href for portfolio page id.
static lookupTitle(int $a_page_id)
ilDBInterface $db
static findPortfolioForPage(int $a_page_id)
Get portfolio id of page id.
setTitle(string $a_title)
static fixOrdering(int $a_portfolio_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.