ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjContentPage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
29{
30 protected ?Translations $objTrans = null;
33
34 public function __construct(int $a_id = 0, bool $a_reference = true)
35 {
36 global $DIC;
37
38 parent::__construct($a_id, $a_reference);
40 $this->initPageMetricsService($DIC->refinery());
41 $this->content_style_domain = $DIC->contentStyle()
42 ->domain();
43 }
44
45 private function initTranslationService(): void
46 {
47 if (null === $this->objTrans && $this->getId() > 0) {
48 $this->objTrans = $this->getObjectProperties()->getPropertyTranslations();
49 }
50 }
51
52 private function initPageMetricsService(ILIAS\Refinery\Factory $refinery): void
53 {
54 $this->pageMetricsService = new PageMetricsService(
55 new PageMetricsRepositoryImp($this->db),
57 );
58 }
59
61 {
62 return $this->objTrans;
63 }
64
65 protected function initType(): void
66 {
67 $this->type = self::OBJ_TYPE;
68 }
69
70 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
71 {
72 assert($new_obj instanceof ilObjContentPage);
73 parent::doCloneObject($new_obj, $a_target_id, $a_copy_id);
74 $this->cloneMetaData($new_obj);
75
76 $new_obj->getObjectProperties()->storePropertyTranslations(
77 $this->objTrans->copy($new_obj->getId())
78 );
79
80 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
81 $translations = ilContentPagePage::lookupTranslations($this->getType(), $this->getId());
82 foreach ($translations as $language) {
83 $originalPageObject = new ilContentPagePage($this->getId(), 0, $language);
84 $copiedXML = $originalPageObject->copyXmlContent();
85
86 $duplicatePageObject = new ilContentPagePage();
87 $duplicatePageObject->setId($new_obj->getId());
88 $duplicatePageObject->setParentId($new_obj->getId());
89 $duplicatePageObject->setLanguage($language);
90 $duplicatePageObject->setXMLContent($copiedXML);
91 $duplicatePageObject->createFromXML();
92
93 $this->pageMetricsService->store(
95 $new_obj->getId(),
96 $duplicatePageObject->getLanguage()
97 )
98 );
99 }
100 }
101
102 $style = $this->content_style_domain->styleForObjId($this->getId());
103 $style->cloneTo($new_obj->getId());
104
106 $new_obj->getId(),
109 $this->getId(),
111 '1'
112 ))
113 );
114
115 $lpSettings = new ilLPObjSettings($this->getId());
116 $lpSettings->cloneSettings($new_obj->getId());
117
118 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
119 //copy online status if object is not the root copy object
120 if (!$cwo->isRootNode($this->getRefId())) {
121 $new_obj->setOfflineStatus($this->getOfflineStatus());
122 } else {
123 $new_obj->setOfflineStatus(true);
124 }
125 $new_obj->update();
126 }
127
128 protected function doRead(): void
129 {
130 parent::doRead();
131
132 $this->initTranslationService();
133 }
134
135 protected function doCreate(bool $clone_mode = false): void
136 {
137 parent::doCreate($clone_mode);
138
139 $this->initTranslationService();
140
141 $this->db->manipulateF(
142 'INSERT INTO content_page_data (content_page_id, stylesheet ) VALUES(%s, %s)',
143 ['integer', 'integer'],
144 [$this->getId(), 0]
145 );
146
147 $this->getObjectProperties()->withPropertyIsOnline(
148 $this->getObjectProperties()->getPropertyIsOnline()->withOffline()
149 )->storeCoreProperties();
150
151 $this->getObjectProperties()->storePropertyTranslations(
152 $this->getObjectProperties()->getPropertyTranslations()->withLanguage(
153 new Language(
154 $this->lng->getDefaultLanguage(),
155 $this->getTitle(),
156 $this->getLongDescription(),
157 true
158 )
159 )
160 );
161
162 $this->createMetaData();
163 }
164
165 protected function doUpdate(): void
166 {
167 parent::doUpdate();
168
169 $this->getObjectProperties()->storePropertyTranslations(
170 $this->getObjectProperties()->getPropertyTranslations()
171 ->withDefaultTitle($this->getTitle())
172 ->withDefaultDescription($this->getLongDescription())
173 );
174
175 $this->updateMetaData();
176 }
177
178 protected function doDelete(): void
179 {
180 parent::doDelete();
181
182 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
183 $originalPageObject = new ilContentPagePage($this->getId());
184 $originalPageObject->delete();
185 }
186
187 $this->db->manipulateF(
188 'DELETE FROM content_page_metrics WHERE content_page_id = %s',
189 ['integer'],
190 [$this->getId()]
191 );
192
193 $this->db->manipulateF(
194 'DELETE FROM content_page_data WHERE content_page_id = %s',
195 ['integer'],
196 [$this->getId()]
197 );
198 }
199
203 public function getPageObjIds(): array
204 {
205 $pageObjIds = [];
206
207 $sql = 'SELECT DISTINCT page_id FROM page_object WHERE parent_id = %s AND parent_type = %s';
208 $res = $this->db->queryF(
209 $sql,
210 ['integer', 'text'],
211 [$this->getId(), $this->getType()]
212 );
213
214 while ($row = $this->db->fetchAssoc($res)) {
215 $pageObjIds[] = (int) $row['page_id'];
216 }
217
218 return $pageObjIds;
219 }
220
221 public function trackProgress(int $usrId): void
222 {
224 $usrId,
225 $this->getId(),
226 $this->getRefId(),
227 $this->getType()
228 );
229 }
230}
Class handles translation mode for an object.
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)
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...
cloneMetaData(ilObject $target_obj)
Copy meta data.
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.
Interface ilContentPageObjectConstants.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26