ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjContentPage.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6use ILIAS\Refinery\Factory as Refinery;
8
13{
15 protected $styleId = 0;
17 protected $objTrans;
20
24 public function __construct($a_id = 0, $a_reference = true)
25 {
26 global $DIC;
27
28 parent::__construct($a_id, $a_reference);
30 $this->initPageMetricsService($DIC->refinery());
31 }
32
33 private function initTranslationService() : void
34 {
35 if ($this->getId() > 0 && null === $this->objTrans) {
36 $this->objTrans = ilObjectTranslation::getInstance($this->getId());
37 }
38 }
39
43 private function initPageMetricsService(ILIAS\Refinery\Factory $refinery) : void
44 {
45 $this->pageMetricsService = new PageMetricsService(
46 new PageMetricsRepositoryImp($this->db),
47 $refinery
48 );
49 }
50
55 {
56 return $this->objTrans;
57 }
58
62 protected function initType()
63 {
64 $this->type = self::OBJ_TYPE;
65 }
66
70 public function getStyleSheetId() : int
71 {
72 return (int) $this->styleId;
73 }
74
78 public function setStyleSheetId(int $styleId)
79 {
80 $this->styleId = $styleId;
81 }
82
86 public function writeStyleSheetId(int $styleId) : void
87 {
88 $this->db->manipulateF(
89 'UPDATE content_object SET stylesheet = %s WHERE id = %s',
90 ['integer', 'integer'],
91 [(int) $styleId, $this->getId()]
92 );
93
94 $this->setStyleSheetId($styleId);
95 }
96
100 protected function doCloneObject($new_obj, $a_target_id, $a_copy_id = null)
101 {
103 parent::doCloneObject($new_obj, $a_target_id, $a_copy_id);
104
106 $ot->copy($new_obj->getId());
107
108 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
109 $translations = ilContentPagePage::lookupTranslations($this->getType(), $this->getId());
110 foreach ($translations as $language) {
111 $originalPageObject = new ilContentPagePage($this->getId(), 0, $language);
112 $copiedXML = $originalPageObject->copyXmlContent();
113
114 $duplicatePageObject = new ilContentPagePage();
115 $duplicatePageObject->setId($new_obj->getId());
116 $duplicatePageObject->setParentId($new_obj->getId());
117 $duplicatePageObject->setLanguage($language);
118 $duplicatePageObject->setXMLContent($copiedXML);
119 $duplicatePageObject->createFromXML();
120
121 $this->pageMetricsService->store(
123 (int) $new_obj->getId(),
124 $duplicatePageObject->getLanguage()
125 )
126 );
127 }
128 }
129
130 $styleId = $this->getStyleSheetId();
133 if ($style) {
134 $new_id = $style->ilClone();
135 $new_obj->setStyleSheetId($new_id);
136 $new_obj->update();
137 }
138 }
139
141 $new_obj->getId(),
144 $this->getId(),
146 true
147 )
148 );
149
150 $lpSettings = new ilLPObjSettings($this->getId());
151 $lpSettings->cloneSettings($new_obj->getId());
152 }
153
157 protected function doRead()
158 {
159 parent::doRead();
160
161 $this->initTranslationService();
162
163 $res = $this->db->queryF(
164 'SELECT * FROM content_page_data WHERE content_page_id = %s',
165 ['integer'],
166 [$this->getId()]
167 );
168
169 while ($data = $this->db->fetchAssoc($res)) {
170 $this->setStyleSheetId((int) $data['stylesheet']);
171 }
172 }
173
177 protected function doCreate()
178 {
179 parent::doCreate();
180
181 $this->initTranslationService();
182
183 $this->db->manipulateF(
184 '
185 INSERT INTO content_page_data
186 (
187 content_page_id,
188 stylesheet
189 )
190 VALUES(%s, %s)',
191 ['integer', 'integer'],
192 [$this->getId(), 0]
193 );
194 }
195
196
200 protected function doUpdate()
201 {
202 parent::doUpdate();
203
204 $this->initTranslationService();
205
206 $trans = $this->getObjectTranslation();
207 $trans->setDefaultTitle($this->getTitle());
208 $trans->setDefaultDescription($this->getLongDescription());
209 $trans->save();
210
211 $this->db->manipulateF(
212 '
213 UPDATE content_page_data
214 SET
215 stylesheet = %s
216 WHERE content_page_id = %s',
217 ['integer', 'integer'],
218 [$this->getStyleSheetId(), $this->getId()]
219 );
220 }
221
225 protected function doDelete()
226 {
227 parent::doDelete();
228
229 if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
230 $originalPageObject = new ilContentPagePage($this->getId());
231 $originalPageObject->delete();
232 }
233
234 $this->initTranslationService();
235 $this->objTrans->delete();
236
237 $this->db->manipulateF(
238 'DELETE FROM content_page_metrics WHERE content_page_id = %s',
239 ['integer'],
240 [$this->getId()]
241 );
242
243 $this->db->manipulateF(
244 'DELETE FROM content_page_data WHERE content_page_id = %s',
245 ['integer'],
246 [$this->getId()]
247 );
248 }
249
253 public function getPageObjIds() : array
254 {
255 $pageObjIds = [];
256
257 $sql = "SELECT DISTINCT page_id FROM page_object WHERE parent_id = %s AND parent_type = %s";
258 $res = $this->db->queryF(
259 $sql,
260 ['integer', 'text'],
261 [$this->getId(), $this->getType()]
262 );
263
264 while ($row = $this->db->fetchAssoc($res)) {
265 $pageObjIds[] = $row['page_id'];
266 }
267
268 return $pageObjIds;
269 }
270
274 public function trackProgress(int $usrId) : void
275 {
277 $this->getType(),
278 $this->getRefId(),
279 $this->getId(),
280 $usrId
281 );
282
283 $lp = ilObjectLP::getInstance($this->getId());
284 if ($lp->isActive() && ((int) $lp->getCurrentMode() === ilLPObjSettings::LP_MODE_CONTENT_VISITED)) {
285 $current_status = (int) ilLPStatus::_lookupStatus($this->getId(), $usrId, false);
286 if ($current_status !== ilLPStatus::LP_STATUS_COMPLETED_NUM) {
288 $this->getId(),
289 $usrId
290 );
291 }
292 }
293 }
294}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
static _recordReadEvent( $a_type, $a_ref_id, $obj_id, $usr_id, $isCatchupWriteEvents=true, $a_ext_rc=false, $a_ext_time=false)
Records a read event and catches up with write events.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
Class ilContentPagePage.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
const LP_STATUS_COMPLETED_NUM
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
Class ilObjContentPage.
writeStyleSheetId(int $styleId)
__construct($a_id=0, $a_reference=true)
@inheritDoc
setStyleSheetId(int $styleId)
initPageMetricsService(ILIAS\Refinery\Factory $refinery)
static _lookupStandard($a_id)
Lookup standard flag.
Class ilObject2 This is an intermediate progress of ilObject class.
getRefId()
get reference id @access public
getLongDescription()
get object long description (stored in object_description)
getType()
get object type @access public
getTitle()
get object title @access public
doCloneObject($new_obj, $a_target_id, $a_copy_id=null)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstance($a_obj_id)
Class handles translation mode for an object.
static getInstance($a_obj_id)
Get instance.
getId()
get object id @access public
static lookupTranslations($a_parent_type, $a_id)
Lookup translations.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
global $DIC
Definition: goto.php:24
Interface ilContentPageObjectConstants.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23