ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PageManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Wiki\Page;
22
25
30{
32 protected \ILIAS\Wiki\Wiki\DomainService $wiki_domain;
34 protected int $wiki_ref_id;
35 protected \ilObjWiki $wiki;
36 protected int $ref_id;
38
39 public function __construct(
44 int $ref_id
45 ) {
46 $this->wiki_ref_id = $ref_id;
47 $this->data_service = $data_service;
48 $this->page_repo = $page_repo;
49 $this->wiki_domain = $wiki_domain;
50 $this->page_domain = $page_domain;
51 $this->wiki = $this->wiki_domain->object($ref_id);
52 }
53
54 public function getWikiId(): int
55 {
56 return $this->wiki_domain->getObjId($this->wiki_ref_id);
57 }
58
59 public function createWikiPage(
60 string $title,
61 int $wpg_id = 0,
62 string $lang = "-",
63 int $template_page = 0
64 ): int {
65 if ($lang === "") {
66 $lang = "-";
67 }
68 // todo check if $wpg_id is given if lang is set
69 // todo check if $wpg_id is not given if lang is not set
70 // todo check if $wpg_id belongs to wiki, if given
71 // todo check if page (id/lang) does not exist already
72 // todo check if title is not empty
73
74 // check if template has to be used
75 if ($template_page === 0) {
76 if (!$this->wiki->getEmptyPageTemplate()) {
77 $wt = new \ilWikiPageTemplate($this->getWikiId());
78 $ts = $wt->getAllInfo(\ilWikiPageTemplate::TYPE_NEW_PAGES, $lang);
79 if (count($ts) === 1) {
80 $t = current($ts);
81 $template_page = (int) $t["wpage_id"];
82 }
83 }
84 }
85
86 // master language
87 if ($lang === "-") {
88 $page = new \ilWikiPage(0);
89 $page->setWikiId($this->getWikiId());
90 $page->setWikiRefId($this->wiki_ref_id);
91 $page->setTitle(\ilWikiUtil::makeDbTitle($title));
92 if ($this->wiki->getRatingPages() && $this->wiki->getRatingForNewPages()) {
93 $page->setRating(true);
94 }
95 // needed for notification
96 $page->create();
97 } else {
98 $orig_page = $this->page_domain->getWikiPage($this->wiki_ref_id, $wpg_id, 0, "-");
99 $orig_page->copyPageToTranslation($lang);
100
101 $page = $this->page_domain->getWikiPage($this->wiki_ref_id, $wpg_id, 0, $lang);
102 $page->setTitle(\ilWikiUtil::makeDbTitle($title));
103 $page->update();
104 }
105
106 // copy template into new page
107 if ($template_page > 0) {
108 $t_page = $this->page_domain->getWikiPage($this->wiki_ref_id, $template_page, 0, $lang);
109 $t_page->copy(
110 $page->getId(),
111 $page->getParentType(),
112 $page->getParentId(),
113 false,
114 0,
115 true
116 );
117
118 // #15718
119 if ($lang === "-") {
121 0,
122 $this->getWikiId(),
123 $this->getWikiId(),
124 "wpg",
125 $template_page,
126 $page->getId()
127 );
128 }
129 }
130 return $page->getId();
131 }
132
136 public function getWikiPages(string $lang = "-"): \Iterator
137 {
138 return $this->page_repo->getWikiPages(
139 $this->getWikiId(),
140 $lang
141 );
142 }
143
147 public function getInfoOfSelected(array $ids, string $lang = "-"): \Iterator
148 {
149 return $this->page_repo->getInfoOfSelected(
150 $this->getWikiId(),
151 $ids,
152 $lang
153 );
154 }
155
159 public function getMasterPagesWithoutTranslation(string $trans): \Iterator
160 {
161 return $this->page_repo->getMasterPagesWithoutTranslation(
162 $this->getWikiId(),
163 $trans
164 );
165 }
166
170 public function getAllPagesInfo(): \Iterator
171 {
172 return $this->page_repo->getAllPagesInfo(
173 $this->getWikiId()
174 );
175 }
176
180 public function getRecentChanges(): \Iterator
181 {
182 return $this->page_repo->getRecentChanges(
183 $this->getWikiId()
184 );
185 }
186
190 public function getNewPages(): \Iterator
191 {
192 return $this->page_repo->getNewPages(
193 $this->getWikiId()
194 );
195 }
196
200 public function getPopularPages(): \Iterator
201 {
202 return $this->page_repo->getPopularPages(
203 $this->getWikiId()
204 );
205 }
206
210 public function getLanguages(int $wpg_id): array
211 {
212 return $this->page_repo->getLanguages($wpg_id);
213 }
214
218 public function getOrphanedPages(): \Iterator
219 {
220 $starting_page_id = $this->wiki_domain->getStartingPageId($this->wiki_ref_id);
221 foreach ($this->getAllPagesInfo() as $pi) {
222 // find wiki page sources that link to page
223 $sources = \ilInternalLink::_getSourcesOfTarget("wpg", $pi->getId(), 0);
224 $ids = [];
225 foreach ($sources as $source) {
226 if ($source["type"] === "wpg:pg") {
227 $ids[] = $source["id"];
228 }
229 }
230
231 // cross check existence of sources in il_wiki_page
232 if (count($ids) === 0 || !$this->page_repo->doesAtLeastOnePageExist($this->getWikiId(), $ids)) {
233 continue;
234 }
235
236 if ($pi->getId() !== $starting_page_id) {
237 yield $pi;
238 }
239 }
240 }
241
242 public function getPageIdForTitle(
243 string $title,
244 string $lang = "-"
245 ): ?int {
246 return $this->page_repo->getPageIdForTitle(
247 $this->getWikiId(),
248 $title,
249 $lang
250 );
251 }
252
253 public function getPermaLink(int $id, string $lang = "-"): string
254 {
255 $lang = (!in_array($lang, ["", "-"]))
256 ? "_" . $lang
257 : "";
258 return \ilLink::_getStaticLink(
259 null,
260 "wiki",
261 true,
262 "wpage_" . $id . "_" . $this->wiki_ref_id . $lang
263 );
264 }
265
266 public function getPermaLinkByTitle(string $title, string $lang = "-"): string
267 {
268 $id = $this->getPageIdForTitle($title, $lang);
269 if (!is_null($id)) {
270 return $this->getPermaLink($id, $lang);
271 }
272 return \ilLink::_getStaticLink(
273 $this->wiki_ref_id,
274 "wiki"
275 );
276 }
277
278 public function exists(int $id, string $lang = "-"): bool
279 {
280 return $this->page_repo->exists($id, $lang);
281 }
282
283 public function existsByTitle(
284 string $title,
285 string $lang = "-"
286 ): bool {
287 return $this->page_repo->existsByTitle($this->getWikiId(), $title, $lang);
288 }
289
290 public function getTitle(int $id, string $lang = "-"): string
291 {
292 return $this->page_repo->getTitle($id, $lang);
293 }
294
295 public function belongsToWiki(
296 int $id
297 ): bool {
298 return $this->page_repo->getWikiIdByPageId($id) === $this->getWikiId();
299 }
300
301}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Repository internal data service.
Repository internal repo service.
getPermaLinkByTitle(string $title, string $lang="-")
PageDBRepository $page_repo
Definition: PageManager.php:33
getWikiPages(string $lang="-")
getMasterPagesWithoutTranslation(string $trans)
getPermaLink(int $id, string $lang="-")
__construct(InternalDataService $data_service, PageDBRepository $page_repo, \ILIAS\Wiki\Wiki\DomainService $wiki_domain, DomainService $page_domain, int $ref_id)
Definition: PageManager.php:39
existsByTitle(string $title, string $lang="-")
ILIAS Wiki Wiki DomainService $wiki_domain
Definition: PageManager.php:32
InternalDataService $data_service
Definition: PageManager.php:37
exists(int $id, string $lang="-")
getPageIdForTitle(string $title, string $lang="-")
createWikiPage(string $title, int $wpg_id=0, string $lang="-", int $template_page=0)
Definition: PageManager.php:59
getTitle(int $id, string $lang="-")
getInfoOfSelected(array $ids, string $lang="-")
static _cloneValues(int $copy_id, int $a_source_id, int $a_target_id, ?string $a_sub_type=null, ?int $a_source_sub_id=null, ?int $a_target_sub_id=null)
Clone Advanced Meta Data.
static makeDbTitle(string $a_par)
return['delivery_method'=> 'php',]
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.
if(!file_exists('../ilias.ini.php'))
$lang
Definition: xapiexit.php:25