ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjContentPage.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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);
38 
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),
55  $refinery
56  );
57  }
58 
60  {
61  $this->initTranslationService();
62 
63  return $this->objTrans;
64  }
65 
66  protected function initType(): void
67  {
68  $this->type = self::OBJ_TYPE;
69  }
70 
71  protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
72  {
73  assert($new_obj instanceof ilObjContentPage);
74  parent::doCloneObject($new_obj, $a_target_id, $a_copy_id);
75  $this->cloneMetaData($new_obj);
76 
78  $ot->copy($new_obj->getId());
79  $new_ot = clone $ot;
80  $new_ot->setObjId($new_obj->getId());
81  $new_obj->objTrans = $new_ot;
82 
83  if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
84  $translations = ilContentPagePage::lookupTranslations($this->getType(), $this->getId());
85  foreach ($translations as $language) {
86  $originalPageObject = new ilContentPagePage($this->getId(), 0, $language);
87  $copiedXML = $originalPageObject->copyXmlContent();
88 
89  $duplicatePageObject = new ilContentPagePage();
90  $duplicatePageObject->setId($new_obj->getId());
91  $duplicatePageObject->setParentId($new_obj->getId());
92  $duplicatePageObject->setLanguage($language);
93  $duplicatePageObject->setXMLContent($copiedXML);
94  $duplicatePageObject->createFromXML();
95 
96  $this->pageMetricsService->store(
98  $new_obj->getId(),
99  $duplicatePageObject->getLanguage()
100  )
101  );
102  }
103  }
104 
105  $style = $this->content_style_domain->styleForObjId($this->getId());
106  $style->cloneTo($new_obj->getId());
107 
109  $new_obj->getId(),
111  (string) ((bool) ilContainer::_lookupContainerSetting(
112  $this->getId(),
114  '1'
115  ))
116  );
117 
118  $lpSettings = new ilLPObjSettings($this->getId());
119  $lpSettings->cloneSettings($new_obj->getId());
120 
121  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
122  //copy online status if object is not the root copy object
123  if (!$cwo->isRootNode($this->getRefId())) {
124  $new_obj->setOfflineStatus($this->getOfflineStatus());
125  } else {
126  $new_obj->setOfflineStatus(true);
127  }
128 
129  $new_obj->update();
130  }
131 
132  protected function doRead(): void
133  {
134  parent::doRead();
135 
136  $this->initTranslationService();
137  }
138 
139  protected function doCreate(bool $clone_mode = false): void
140  {
141  parent::doCreate($clone_mode);
142 
143  $this->initTranslationService();
144 
145  $this->db->manipulateF(
146  'INSERT INTO content_page_data (content_page_id, stylesheet ) VALUES(%s, %s)',
147  ['integer', 'integer'],
148  [$this->getId(), 0]
149  );
150 
151  $this->setOfflineStatus(true);
152  $this->update();
153 
154  $this->createMetaData();
155  }
156 
157  protected function doUpdate(): void
158  {
159  parent::doUpdate();
160 
161  $trans = $this->getObjectTranslation();
162  $trans->setDefaultTitle($this->getTitle());
163  $trans->setDefaultDescription($this->getLongDescription());
164  $trans->save();
165 
166  $this->updateMetaData();
167  }
168 
169  protected function doDelete(): void
170  {
171  parent::doDelete();
172 
173  if (ilContentPagePage::_exists($this->getType(), $this->getId(), '', true)) {
174  $originalPageObject = new ilContentPagePage($this->getId());
175  $originalPageObject->delete();
176  }
177 
178  $this->initTranslationService();
179  $this->objTrans->delete();
180 
181  $this->db->manipulateF(
182  'DELETE FROM content_page_metrics WHERE content_page_id = %s',
183  ['integer'],
184  [$this->getId()]
185  );
186 
187  $this->db->manipulateF(
188  'DELETE FROM content_page_data WHERE content_page_id = %s',
189  ['integer'],
190  [$this->getId()]
191  );
192  }
193 
197  public function getPageObjIds(): array
198  {
199  $pageObjIds = [];
200 
201  $sql = 'SELECT DISTINCT page_id FROM page_object WHERE parent_id = %s AND parent_type = %s';
202  $res = $this->db->queryF(
203  $sql,
204  ['integer', 'text'],
205  [$this->getId(), $this->getType()]
206  );
207 
208  while ($row = $this->db->fetchAssoc($res)) {
209  $pageObjIds[] = (int) $row['page_id'];
210  }
211 
212  return $pageObjIds;
213  }
214 
215  public function trackProgress(int $usrId): void
216  {
218  $usrId,
219  $this->getId(),
220  $this->getRefId(),
221  $this->getType()
222  );
223  }
224 }
DomainService $content_style_domain
$res
Definition: ltiservices.php:69
Facade for consumer domain interface.
cloneMetaData(ilObject $target_obj)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
Interface Observer Contains several chained tasks and infos about them.
initPageMetricsService(ILIAS\Refinery\Factory $refinery)
static lookupTranslations(string $a_parent_type, int $a_id)
Lookup translations.
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
PageMetricsService $pageMetricsService
static _tracProgress(int $a_user_id, int $a_obj_id, int $a_ref_id, string $a_obj_type='')
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static getInstance(int $obj_id)
global $DIC
Definition: shib_login.php:25
setOfflineStatus(bool $status)
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
ilObjectTranslation $objTrans
__construct(Container $dic, ilPlugin $plugin)
doCreate(bool $clone_mode=false)
getLongDescription()
get object long description (stored in object_description)
static _getInstance(int $a_copy_id)
__construct(int $a_id=0, bool $a_reference=true)