ILIAS  release_8 Revision v8.24
class.ilObjContentPage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
27{
28 protected int $styleId = 0;
29 protected ?ilObjectTranslation $objTrans = null;
32
33 public function __construct(int $a_id = 0, bool $a_reference = true)
34 {
35 global $DIC;
36
37 parent::__construct($a_id, $a_reference);
39 $this->initPageMetricsService($DIC->refinery());
40 $this->content_style_domain = $DIC->contentStyle()
41 ->domain();
42 }
43
44 private function initTranslationService(): void
45 {
46 if (null === $this->objTrans && $this->getId() > 0) {
47 $this->objTrans = ilObjectTranslation::getInstance($this->getId());
48 }
49 }
50
51 private function initPageMetricsService(ILIAS\Refinery\Factory $refinery): void
52 {
53 $this->pageMetricsService = new PageMetricsService(
54 new PageMetricsRepositoryImp($this->db),
56 );
57 }
58
60 {
61 return $this->objTrans;
62 }
63
64 protected function initType(): void
65 {
66 $this->type = self::OBJ_TYPE;
67 }
68
69 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
70 {
71 assert($new_obj instanceof ilObjContentPage);
72 parent::doCloneObject($new_obj, $a_target_id, $a_copy_id);
73
75 $ot->copy($new_obj->getId());
76
77 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
78 $translations = ilContentPagePage::lookupTranslations($this->getType(), $this->getId());
79 foreach ($translations as $language) {
80 $originalPageObject = new ilContentPagePage($this->getId(), 0, $language);
81 $copiedXML = $originalPageObject->copyXmlContent();
82
83 $duplicatePageObject = new ilContentPagePage();
84 $duplicatePageObject->setId($new_obj->getId());
85 $duplicatePageObject->setParentId($new_obj->getId());
86 $duplicatePageObject->setLanguage($language);
87 $duplicatePageObject->setXMLContent($copiedXML);
88 $duplicatePageObject->createFromXML();
89
90 $this->pageMetricsService->store(
92 $new_obj->getId(),
93 $duplicatePageObject->getLanguage()
94 )
95 );
96 }
97 }
98
99 $style = $this->content_style_domain->styleForObjId($this->getId());
100 $style->cloneTo($new_obj->getId());
101
103 $new_obj->getId(),
106 $this->getId(),
108 '1'
109 ))
110 );
111
112 $lpSettings = new ilLPObjSettings($this->getId());
113 $lpSettings->cloneSettings($new_obj->getId());
114
115 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
116 //copy online status if object is not the root copy object
117 if (!$cwo->isRootNode($this->getRefId())) {
118 $new_obj->setOfflineStatus($this->getOfflineStatus());
119 } else {
120 $new_obj->setOfflineStatus(true);
121 }
122 $new_obj->update();
123 }
124
125 protected function doRead(): void
126 {
127 parent::doRead();
128
129 $this->initTranslationService();
130 }
131
132 protected function doCreate(bool $clone_mode = false): void
133 {
134 parent::doCreate($clone_mode);
135
136 $this->initTranslationService();
137
138 $this->db->manipulateF(
139 'INSERT INTO content_page_data (content_page_id, stylesheet ) VALUES(%s, %s)',
140 ['integer', 'integer'],
141 [$this->getId(), 0]
142 );
143
144 $this->setOfflineStatus(true);
145 $this->update();
146 }
147
148 protected function doUpdate(): void
149 {
150 parent::doUpdate();
151
152 $this->initTranslationService();
153
154 $trans = $this->getObjectTranslation();
155 $trans->setDefaultTitle($this->getTitle());
156 $trans->setDefaultDescription($this->getLongDescription());
157 $trans->save();
158 }
159
160 protected function doDelete(): void
161 {
162 parent::doDelete();
163
164 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
165 $originalPageObject = new ilContentPagePage($this->getId());
166 $originalPageObject->delete();
167 }
168
169 $this->initTranslationService();
170 $this->objTrans->delete();
171
172 $this->db->manipulateF(
173 'DELETE FROM content_page_metrics WHERE content_page_id = %s',
174 ['integer'],
175 [$this->getId()]
176 );
177
178 $this->db->manipulateF(
179 'DELETE FROM content_page_data WHERE content_page_id = %s',
180 ['integer'],
181 [$this->getId()]
182 );
183 }
184
188 public function getPageObjIds(): array
189 {
190 $pageObjIds = [];
191
192 $sql = 'SELECT DISTINCT page_id FROM page_object WHERE parent_id = %s AND parent_type = %s';
193 $res = $this->db->queryF(
194 $sql,
195 ['integer', 'text'],
196 [$this->getId(), $this->getType()]
197 );
198
199 while ($row = $this->db->fetchAssoc($res)) {
200 $pageObjIds[] = (int) $row['page_id'];
201 }
202
203 return $pageObjIds;
204 }
205
206 public function trackProgress(int $usrId): void
207 {
209 $usrId,
210 $this->getId(),
211 $this->getRefId(),
212 $this->getType()
213 );
214 }
215}
Facade for consumer domain interface.
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _getInstance(int $a_copy_id)
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')
DomainService $content_style_domain
__construct(int $a_id=0, bool $a_reference=true)
Constructor.
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
ilObjectTranslation $objTrans
doCreate(bool $clone_mode=false)
PageMetricsService $pageMetricsService
initPageMetricsService(ILIAS\Refinery\Factory $refinery)
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 getInstance(int $obj_id)
getLongDescription()
get object long description (stored in object_description)
setOfflineStatus(bool $status)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static lookupTranslations(string $a_parent_type, int $a_id)
Lookup translations.
global $DIC
Definition: feed.php:28
Interface ilContentPageObjectConstants.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
Class ChatMainBarProvider \MainMenu\Provider.