ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
NavigationManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
32 {
33  protected PageManager $pm;
34  protected string $lang;
35  protected string $page_title;
36  protected int $wpg_id;
37  protected \ilObjWiki $wiki;
38  protected bool $initialised = false;
39 
40  public function __construct(
41  PageManager $pm,
42  \ilObjWiki $wiki,
43  int $wpg_id = 0,
44  string $page_title = "",
45  string $lang = "-"
46  ) {
47  $this->pm = $pm;
48  $this->wiki = $wiki;
49  $this->wpg_id = $wpg_id;
50  $this->page_title = trim($page_title);
51  $this->lang = ($lang === "")
52  ? "-"
53  : $lang;
54  }
55 
56  protected function init(): void
57  {
58  if (!$this->initialised) {
59 
60  // if nothing given, use start page
61  if ($this->wpg_id === 0 && $this->page_title === "") {
62  $this->page_title = $this->wiki->getStartPage();
63  }
64 
65  // if no page id given, get page id from requested page title
66  if ($this->wpg_id === 0 && $this->page_title !== "") {
67  $this->wpg_id = (int) $this->pm->getPageIdForTitle($this->page_title, $this->lang);
68  }
69 
70  // check if page exists and belongs to wiki
71  if ($this->wpg_id > 0) {
72  if (!$this->pm->exists($this->wpg_id, $this->lang)) {
73  throw new \ilWikiException("Wiki page does not exist (" .
74  $this->wpg_id . "," . $this->lang . ")");
75  }
76  if (!$this->pm->belongsToWiki($this->wpg_id)) {
77  throw new \ilWikiException("Wiki page does not belong to wiki (" .
78  $this->wpg_id . "," . $this->wiki->getId() . ")");
79  }
80  }
81  $this->initialised = true;
82  }
83  }
84 
85  public function getCurrentPageId(): int
86  {
87  $this->init();
88  return $this->wpg_id;
89  }
90 
91  public function getCurrentPageLanguage(): string
92  {
93  $this->init();
94  return $this->lang;
95  }
96 
97 }
__construct(PageManager $pm, \ilObjWiki $wiki, int $wpg_id=0, string $page_title="", string $lang="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...