ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjPortfolioBase.php
Go to the documentation of this file.
1<?php
2
24abstract class ilObjPortfolioBase extends ilObject2
25{
26 protected \ILIAS\Notes\Service $notes;
28 protected bool $comments = false;
29 protected string $bg_color = "";
30 protected string $font_color = "";
31 protected string $img = "";
32 protected string $ppic = "";
33 protected bool $style = false;
34
35 public function __construct(
36 int $a_id = 0,
37 bool $a_reference = true
38 ) {
39 global $DIC;
40
41 $this->notes = $DIC->notes();
42
43 parent::__construct($a_id, $a_reference);
44
45 $this->setting = $DIC->settings();
46
47 $this->db = $DIC->database();
48 }
49
50
51 //
52 // PROPERTIES
53 //
54
55 /*
56 public function setOnline(bool $a_value): void
57 {
58 $this->online = $a_value;
59 }*/
60
61
62 public function setPublicComments(bool $a_value): void
63 {
64 $this->comments = $a_value;
65 }
66
67 public function hasPublicComments(): bool
68 {
69 return $this->comments;
70 }
71
72 public function hasProfilePicture(): bool
73 {
74 return $this->ppic;
75 }
76
77 public function setProfilePicture(bool $a_status): void
78 {
79 $this->ppic = $a_status;
80 }
81
82 public function getBackgroundColor(): string
83 {
84 if (!$this->bg_color) {
85 $this->bg_color = "ffffff";
86 }
87 return $this->bg_color;
88 }
89
93 public function setBackgroundColor(string $a_value): void
94 {
95 $this->bg_color = $a_value;
96 }
97
98 public function getFontColor(): string
99 {
100 if (!$this->font_color) {
101 $this->font_color = "505050";
102 }
103 return $this->font_color;
104 }
105
106 public function setFontColor(string $a_value): void
107 {
108 $this->font_color = $a_value;
109 }
110
111 //
112 // CRUD
113 //
114
115 protected function doRead(): void
116 {
118
119 $set = $ilDB->query("SELECT * FROM usr_portfolio" .
120 " WHERE id = " . $ilDB->quote($this->id, "integer"));
121 $row = $ilDB->fetchAssoc($set);
122
123 $this->setProfilePicture((bool) $row["ppic"]);
124 $this->setBackgroundColor((string) $row["bg_color"]);
125 $this->setFontColor((string) $row["font_color"]);
126
127 // #14661
128 $this->setPublicComments($this->notes->domain()->commentsActive($this->id));
129
130 $this->doReadCustom($row);
131 }
132
136 protected function doReadCustom(array $a_row): void
137 {
138 }
139
140 protected function doCreate(bool $clone_mode = false): void
141 {
143
144 $ilDB->manipulate("INSERT INTO usr_portfolio (id)" .
145 " VALUES (" . $ilDB->quote($this->id, "integer") . ")");
146 }
147
148 protected function doUpdate(): void
149 {
151
152 $fields = array(
153 "ppic" => array("integer", $this->hasProfilePicture()),
154 "bg_color" => array("text", $this->getBackgroundColor()),
155 "font_color" => array("text", $this->getFontColor())
156 );
157 $this->doUpdateCustom($fields);
158
159 // #14661
160 $this->notes->domain()->activateComments($this->id, $this->hasPublicComments());
161
162 $ilDB->update(
163 "usr_portfolio",
164 $fields,
165 array("id" => array("integer", $this->id))
166 );
167 }
168
172 protected function doUpdateCustom(array &$a_fields): void
173 {
174 }
175
176 protected function doDelete(): void
177 {
179
180 $this->deleteAllPages();
181
182 $ilDB->manipulate("DELETE FROM usr_portfolio" .
183 " WHERE id = " . $ilDB->quote($this->id, "integer"));
184 }
185
186 abstract protected function deleteAllPages(): void;
187
188
189 //
190 // TRANSMOGRIFIER
191 //
192
199 protected static function cloneBasics(
200 ilObjPortfolioBase $a_source,
201 ilObjPortfolioBase $a_target
202 ): void {
203 global $DIC;
204
205 // copy portfolio properties
206 $a_target->setPublicComments($a_source->hasPublicComments());
207 $a_target->setProfilePicture($a_source->hasProfilePicture());
208 $a_target->setFontColor($a_source->getFontColor());
209 $a_target->setBackgroundColor($a_source->getBackgroundColor());
210 $a_target->update();
211
212 // container settings
213 foreach (ilContainer::_getContainerSettings($a_source->getId()) as $keyword => $value) {
214 ilContainer::_writeContainerSetting($a_target->getId(), $keyword, $value);
215 }
216
217 // style
218 $content_style_domain = $DIC
219 ->contentStyle()
220 ->domain()
221 ->styleForObjId($a_source->getId());
222 $content_style_domain->cloneTo($a_target->getId());
223 }
224
228 public static function clonePagesAndSettings(
229 ilObjPortfolioBase $a_source,
230 ilObjPortfolioBase $a_target,
231 ?array $a_recipe = null,
232 bool $copy_all = false
233 ): void {
234 global $DIC;
235
236 $lng = $DIC->language();
237 $ilUser = $DIC->user();
238 $skill_personal_service = $DIC->skills()->personal();
239
240 $source_id = $a_source->getId();
241 $target_id = $a_target->getId();
242
243 if ($a_source instanceof ilObjPortfolioTemplate &&
244 $a_target instanceof ilObjPortfolio) {
245 $direction = "t2p";
246 } elseif ($a_source instanceof ilObjPortfolio &&
247 $a_target instanceof ilObjPortfolioTemplate) {
248 $direction = "p2t";
249 } else {
250 return;
251 }
252
253 self::cloneBasics($a_source, $a_target);
254
255 // copy advanced metadata
257 ilAdvancedMDValues::_cloneValues($copy_id, $a_source->getId(), $a_target->getId());
258
259 // copy selection of global optional sets
261 $a_target->getId(),
262 'pfpg',
264 );
265
266 // fix metadata record type assignment
267 // e.g. if portfolio is created from template
268 // we need to change this from prtt to prtf
270 ilObject::_lookupType($a_source->getId()),
271 $a_target->getId(),
272 "pfpg",
273 false
274 ) as $rec) {
275 /*
276 * BT 35494: reset assignement of the newly cloned local records,
277 * and only append what's needed to global ones
278 */
279 $target_type = ilObject::_lookupType($a_target->getId());
280 if ($rec->getParentObject() == $a_target->getId()) {
281 $rec->setAssignedObjectTypes(
282 [[
283 "obj_type" => $target_type,
284 "sub_type" => "pfpg",
285 "optional" => 0
286 ]
287 ]
288 );
289 } elseif (!$rec->isAssignedObjectType($target_type, 'pfpg')) {
290 $rec->appendAssignedObjectType(
291 $target_type,
292 "pfpg"
293 );
294 }
295 $rec->update();
296 }
297
298 // personal skills
299 $pskills = array_keys($skill_personal_service->getSelectedUserSkills($ilUser->getId()));
300
301 // copy pages
302 $page_map = array();
303 foreach (ilPortfolioPage::getAllPortfolioPages($source_id) as $page) {
304 $page_id = $page["id"];
305
306 if ($direction === "t2p") {
307 $source_page = new ilPortfolioTemplatePage($page_id);
308 $target_page = new ilPortfolioPage();
309 } else {
310 $source_page = new ilPortfolioPage($page_id);
311 $target_page = new ilPortfolioTemplatePage();
312 }
313 $source_page->setPortfolioId($source_id);
314 $target_page->setPortfolioId($target_id);
315
316 $page_type = $source_page->getType();
317 $page_title = $source_page->getTitle();
318
319
320
321
322 $page_recipe = null;
323 if (isset($a_recipe)) {
324 $page_recipe = $a_recipe[$page_id] ?? null;
325 }
326
327 $valid = false;
328 switch ($page_type) {
329 // page editor
330 default:
331 $target_page->setXMLContent(
332 $source_page->copyXmlContent(
333 true,
334 $a_target->getId(),
335 $copy_id
336 )
337 );
338 $target_page->buildDom(true);
339
340 // parse content / blocks
341
342 if ($direction === "t2p") {
343 $dom = $target_page->getDomDoc();
344
345 // update profile/consultation hours user id
346 self::updateDomNodes($dom, "//PageContent/Profile", "User", $ilUser->getId());
347 self::updateDomNodes($dom, "//PageContent/ConsultationHours", "User", $ilUser->getId());
348 self::updateDomNodes($dom, "//PageContent/MyCourses", "User", $ilUser->getId());
349
350 // skills
351 $xpath = new DOMXPath($dom);
352 $nodes = $xpath->query("//PageContent/Skills");
353 foreach ($nodes as $node) {
354 $skill_id = $node->getAttribute("Id");
355
356 // existing personal skills
357 if (in_array($skill_id, $pskills)) {
358 $node->setAttribute("User", $ilUser->getId());
359 }
360 // new skill
361 elseif ($copy_all || in_array($skill_id, $a_recipe["skills"])) {
362 $skill_personal_service->addPersonalSkill($ilUser->getId(), $skill_id);
363
364 $node->setAttribute("User", $ilUser->getId());
365 }
366 // remove skill
367 else {
368 $page_element = $node->parentNode;
369 $page_element->parentNode->removeChild($page_element);
370 }
371 }
372 }
373
374 $valid = true;
375 break;
376 }
377
378 if ($valid) {
379 // #12038 - update xml from dom
380 $target_page->setXMLContent($target_page->getXMLFromDom());
381
382 $target_page->setType($page_type);
383 $target_page->setTitle($page_title);
384 $target_page->create(false);
385
386 if ($page_type === ilPortfolioPage::TYPE_PAGE) {
387 $target_page->update(); // handle mob usages!
388 }
389 $page_map[$source_page->getId()] = $target_page->getId();
390 }
391 }
392 ilPortfolioPage::updateInternalLinks($page_map, $a_target);
393 }
394
395 protected static function updateDomNodes(
396 DOMDocument $a_dom,
397 string $a_xpath,
398 string $a_attr_id,
399 string $a_attr_value
400 ): void {
401 $xpath_temp = new DOMXPath($a_dom);
402 $nodes = $xpath_temp->query($a_xpath);
403 foreach ($nodes as $node) {
404 $node->setAttribute($a_attr_id, $a_attr_value);
405 }
406 }
407
411 public function fixLinksOnTitleChange(array $a_title_changes): void
412 {
413 foreach (ilPortfolioPage::getAllPortfolioPages($this->getId()) as $port_page) {
414 if ($this->getType() === "prtt") {
415 $page = new ilPortfolioTemplatePage($port_page["id"]);
416 } else {
417 $page = new ilPortfolioPage($port_page["id"]);
418 }
419 if ($page->renameLinksOnTitleChange($a_title_changes)) {
420 $page->update(true, true);
421 }
422 }
423 }
424}
static getObjRecSelection(int $a_obj_id, string $a_sub_type="")
Get repository object record selection.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static saveObjRecSelection(int $a_obj_id, string $a_sub_type="", ?array $a_records=null, bool $a_delete_before=true)
Save repository object record selection.
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 _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _getContainerSettings(int $a_id)
static _allocateCopyId()
Allocate a copy for further entries.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, ?array $a_recipe=null, bool $copy_all=false)
Build template from portfolio and vice versa.
doUpdateCustom(array &$a_fields)
May be overwritte by derived classes.
fixLinksOnTitleChange(array $a_title_changes)
Update internal portfolio links on title change.
setProfilePicture(bool $a_status)
static cloneBasics(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target)
Clone basic settings.
ILIAS Notes Service $notes
static updateDomNodes(DOMDocument $a_dom, string $a_xpath, string $a_attr_id, string $a_attr_value)
setBackgroundColor(string $a_value)
Set background color, e.g.
doReadCustom(array $a_row)
May be overwritten by derived classes.
doCreate(bool $clone_mode=false)
__construct(int $a_id=0, bool $a_reference=true)
Constructor.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
ilDBInterface $db
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
static updateInternalLinks(array $a_copied_nodes, ilObjPortfolioBase $a_target_obj)
Update internal links, after multiple pages have been copied.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Setting Class.
$valid
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26