ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjPortfolioBase.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "Services/Object/classes/class.ilObject2.php";
5
14abstract class ilObjPortfolioBase extends ilObject2
15{
16
20 public function __construct($a_id = 0, $a_reference = true)
21 {
22 global $DIC;
23 parent::__construct($a_id, $a_reference);
24
25 $this->db = $DIC->database();
26 }
27
28 protected $online; // [bool]
29 protected $comments; // [bool]
30 protected $bg_color; // [string]
31 protected $font_color; // [string]
32 protected $img; // [string]
33 protected $ppic; // [string]
34 protected $style; // [bool]
35
36
37 //
38 // PROPERTIES
39 //
40
46 public function setOnline($a_value)
47 {
48 $this->online = (bool) $a_value;
49 }
50
56 public function isOnline()
57 {
58 return $this->online;
59 }
60
66 public static function lookupOnline($a_id)
67 {
68 global $DIC;
69
70 $ilDB = $DIC->database();
71
72 $set = $ilDB->query("SELECT is_online" .
73 " FROM usr_portfolio" .
74 " WHERE id = " . $ilDB->quote($a_id, "integer"));
75 $row = $ilDB->fetchAssoc($set);
76 return (bool) $row["is_online"];
77 }
78
84 public function setPublicComments($a_value)
85 {
86 $this->comments = (bool) $a_value;
87 }
88
94 public function hasPublicComments()
95 {
96 return $this->comments;
97 }
98
104 public function hasProfilePicture()
105 {
106 return $this->ppic;
107 }
108
114 public function setProfilePicture($a_status)
115 {
116 $this->ppic = (bool) $a_status;
117 }
118
124 public function getBackgroundColor()
125 {
126 if (!$this->bg_color) {
127 $this->bg_color = "ffffff";
128 }
129 return $this->bg_color;
130 }
131
137 public function setBackgroundColor($a_value)
138 {
139 $this->bg_color = (string) $a_value;
140 }
141
147 public function getFontColor()
148 {
149 if (!$this->font_color) {
150 $this->font_color = "505050";
151 }
152 return $this->font_color;
153 }
154
160 public function setFontColor($a_value)
161 {
162 $this->font_color = (string) $a_value;
163 }
164
170 public function getImage()
171 {
172 return $this->img;
173 }
174
180 public function setImage($a_value)
181 {
182 $this->img = (string) $a_value;
183 }
184
190 public function getStyleSheetId()
191 {
192 return (int) $this->style;
193 }
194
200 public function setStyleSheetId($a_style)
201 {
202 $this->style = (int) $a_style;
203 }
204
205
206 //
207 // CRUD
208 //
209
210 protected function doRead()
211 {
213
214 $set = $ilDB->query("SELECT * FROM usr_portfolio" .
215 " WHERE id = " . $ilDB->quote($this->id, "integer"));
216 $row = $ilDB->fetchAssoc($set);
217
218 $this->setOnline((bool) $row["is_online"]);
219 $this->setProfilePicture((bool) $row["ppic"]);
220 $this->setBackgroundColor($row["bg_color"]);
221 $this->setFontColor($row["font_color"]);
222 $this->setImage($row["img"]);
223
224 // #14661
225 include_once("./Services/Notes/classes/class.ilNote.php");
226 $this->setPublicComments(ilNote::commentsActivated($this->id, 0, $this->getType()));
227
228 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
230
231 $this->doReadCustom($row);
232 }
233
234 protected function doReadCustom(array $a_row)
235 {
236 }
237
238 protected function doCreate()
239 {
241
242 $ilDB->manipulate("INSERT INTO usr_portfolio (id,is_online)" .
243 " VALUES (" . $ilDB->quote($this->id, "integer") . "," .
244 $ilDB->quote(0, "integer") . ")");
245 }
246
247 protected function doUpdate()
248 {
250
251 $fields = array(
252 "is_online" => array("integer", $this->isOnline()),
253 "ppic" => array("integer", $this->hasProfilePicture()),
254 "bg_color" => array("text", $this->getBackgroundColor()),
255 "font_color" => array("text", $this->getFontcolor()),
256 "img" => array("text", $this->getImage())
257 );
258 $this->doUpdateCustom($fields);
259
260 // #14661
261 include_once("./Services/Notes/classes/class.ilNote.php");
262 ilNote::activateComments($this->id, 0, $this->getType(), $this->hasPublicComments());
263
264 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
266
267 $ilDB->update(
268 "usr_portfolio",
269 $fields,
270 array("id"=>array("integer", $this->id))
271 );
272 }
273
274 protected function doUpdateCustom(array &$a_fields)
275 {
276 }
277
278 protected function doDelete()
279 {
281
282 $this->deleteAllPages();
283 $this->deleteImage();
284
285 $ilDB->manipulate("DELETE FROM usr_portfolio" .
286 " WHERE id = " . $ilDB->quote($this->id, "integer"));
287 }
288
289 abstract protected function deleteAllPages();
290
291
292 //
293 // IMAGES
294 //
295
301 public function getImageFullPath($a_as_thumb = false)
302 {
303 if ($this->img) {
304 $path = $this->initStorage($this->id);
305 if (!$a_as_thumb) {
306 return $path . $this->img;
307 } else {
308 return $path . "thb_" . $this->img;
309 }
310 }
311 }
312
316 public function deleteImage()
317 {
318 if ($this->id) {
319 include_once "Modules/Portfolio/classes/class.ilFSStoragePortfolio.php";
320 $storage = new ilFSStoragePortfolio($this->id);
321 $storage->delete();
322
323 $this->setImage(null);
324 }
325 }
326
334 public static function initStorage($a_id, $a_subdir = null)
335 {
336 include_once "Modules/Portfolio/classes/class.ilFSStoragePortfolio.php";
337 $storage = new ilFSStoragePortfolio($a_id);
338 $storage->create();
339
340 $path = $storage->getAbsolutePath() . "/";
341
342 if ($a_subdir) {
343 $path .= $a_subdir . "/";
344
345 if (!is_dir($path)) {
346 mkdir($path);
347 }
348 }
349
350 return $path;
351 }
352
359 public function uploadImage(array $a_upload)
360 {
361 if (!$this->id) {
362 return false;
363 }
364
365 $this->deleteImage();
366
367 // #10074
368 $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
369
370 $path = $this->initStorage($this->id);
371 $original = "org_" . $this->id . "_" . $clean_name;
372 $thumb = "thb_" . $this->id . "_" . $clean_name;
373 $processed = $this->id . "_" . $clean_name;
374
375 if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path . $original)) {
376 chmod($path . $original, 0770);
377
378 $prfa_set = new ilSetting("prfa");
379 /* as banner height should overflow, we only handle width
380 $dimensions = $prfa_set->get("banner_width")."x".
381 $prfa_set->get("banner_height");
382 */
383 $dimensions = $prfa_set->get("banner_width");
384
385 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
386 // taking only frame [0] to avoid problems with animated gifs
387 $original_file = ilUtil::escapeShellArg($path . $original);
388 $thumb_file = ilUtil::escapeShellArg($path . $thumb);
389 $processed_file = ilUtil::escapeShellArg($path . $processed);
390 ilUtil::execConvert($original_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
391 ilUtil::execConvert($original_file . "[0] -geometry " . $dimensions . " -quality 100 JPEG:" . $processed_file);
392
393 $this->setImage($processed);
394
395 return true;
396 }
397 return false;
398 }
399
400
401 //
402 // TRANSMOGRIFIER
403 //
404
411 protected static function cloneBasics(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target)
412 {
413 // copy portfolio properties
414 $a_target->setPublicComments($a_source->hasPublicComments());
415 $a_target->setProfilePicture($a_source->hasProfilePicture());
416 $a_target->setFontColor($a_source->getFontColor());
417 $a_target->setBackgroundColor($a_source->getBackgroundColor());
418 $a_target->setImage($a_source->getImage());
419 $a_target->update();
420
421 // banner/images
422 $source_dir = $a_source->initStorage($a_source->getId());
423 $target_dir = $a_target->initStorage($a_target->getId());
424 ilFSStoragePortfolio::_copyDirectory($source_dir, $target_dir);
425
426 // set/copy stylesheet
427 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
428 $style_id = $a_source->getStyleSheetId();
429 if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) {
430 $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
431 $new_id = $style_obj->ilClone();
432 $a_target->setStyleSheetId($new_id);
433 $a_target->update();
434 }
435 }
436
444 public static function clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe = null)
445 {
446 global $DIC;
447
448 $lng = $DIC->language();
449 $ilUser = $DIC->user();
450
451 $source_id = $a_source->getId();
452 $target_id = $a_target->getId();
453
454 if ($a_source instanceof ilObjPortfolioTemplate &&
455 $a_target instanceof ilObjPortfolio) {
456 $direction = "t2p";
457 } elseif ($a_source instanceof ilObjPortfolio &&
458 $a_target instanceof ilObjPortfolioTemplate) {
459 $direction = "p2t";
460 } else {
461 return;
462 }
463
464 self::cloneBasics($a_source, $a_target);
465
466 // personal skills
467 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
468 $pskills = array_keys(ilPersonalSkill::getSelectedUserSkills($ilUser->getId()));
469
470 // copy pages
471 $blog_count = 0;
472 include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
473 $page_map = array();
474 foreach (ilPortfolioPage::getAllPortfolioPages($source_id) as $page) {
475 $page_id = $page["id"];
476
477 if ($direction == "t2p") {
478 $source_page = new ilPortfolioTemplatePage($page_id);
479 $target_page = new ilPortfolioPage();
480 } else {
481 $source_page = new ilPortfolioPage($page_id);
482 $target_page = new ilPortfolioTemplatePage();
483 }
484 $source_page->setPortfolioId($source_id);
485 $target_page->setPortfolioId($target_id);
486
487 $page_type = $source_page->getType();
488 $page_title = $source_page->getTitle();
489
490
491
492
493 $page_recipe = null;
494 if (is_array($a_recipe)) {
495 $page_recipe = $a_recipe[$page_id];
496 }
497
498 $valid = false;
499 switch ($page_type) {
500 // blog => blog template
502 if ($direction == "p2t") {
504 $page_title = $lng->txt("obj_blog") . " " . (++$blog_count);
505 $valid = true;
506 }
507 break;
508
509 // blog template => blog (needs recipe)
511 if ($direction == "t2p" && is_array($page_recipe)) {
512 $page_type = ilPortfolioPage::TYPE_BLOG;
513 if ($page_recipe[0] == "blog") {
514 switch ($page_recipe[1]) {
515 case "create":
516 $page_title = self::createBlogInPersonalWorkspace($page_recipe[2]);
517 $valid = true;
518 break;
519
520 case "reuse":
521 $page_title = $page_recipe[2];
522 $valid = true;
523 break;
524
525 case "ignore":
526 // do nothing
527 break;
528 }
529 }
530 }
531 break;
532
533 // page editor
534 default:
535 $target_page->setXMLContent($source_page->copyXmlContent(true)); // copy mobs
536 $target_page->buildDom(true);
537
538
539 // parse content / blocks
540
541 if ($direction == "t2p") {
542 $dom = $target_page->getDom();
543 if ($dom instanceof php4DOMDocument) {
544 $dom = $dom->myDOMDocument;
545 }
546
547 // update profile/consultation hours user id
548 self::updateDomNodes($dom, "//PageContent/Profile", "User", $ilUser->getId());
549 self::updateDomNodes($dom, "//PageContent/ConsultationHours", "User", $ilUser->getId());
550 self::updateDomNodes($dom, "//PageContent/MyCourses", "User", $ilUser->getId());
551
552 // skills
553 $xpath = new DOMXPath($dom);
554 $nodes = $xpath->query("//PageContent/Skills");
555 foreach ($nodes as $node) {
556 $skill_id = $node->getAttribute("Id");
557
558 // existing personal skills
559 if (in_array($skill_id, $pskills)) {
560 $node->setAttribute("User", $ilUser->getId());
561 }
562 // new skill
563 elseif (in_array($skill_id, $a_recipe["skills"])) {
564 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
565 ilPersonalSkill::addPersonalSkill($ilUser->getId(), $skill_id);
566
567 $node->setAttribute("User", $ilUser->getId());
568 }
569 // remove skill
570 else {
571 $page_element = $node->parentNode;
572 $page_element->parentNode->removeChild($page_element);
573 }
574 }
575 }
576
577 $valid = true;
578 break;
579 }
580
581 if ($valid) {
582 // #12038 - update xml from dom
583 $target_page->setXMLContent($target_page->getXMLFromDom());
584
585 $target_page->setType($page_type);
586 $target_page->setTitle($page_title);
587 $target_page->create();
588
589 if ($page_type == ilPortfolioPage::TYPE_PAGE) {
590 $target_page->update(); // handle mob usages!
591 }
592 $page_map[$source_page->getId()] = $target_page->getId();
593 }
594 }
595
596 ilPortfolioPage::updateInternalLinks($page_map, $a_target);
597 }
598
599 protected static function updateDomNodes($a_dom, $a_xpath, $a_attr_id, $a_attr_value)
600 {
601 $xpath_temp = new DOMXPath($a_dom);
602 $nodes = $xpath_temp->query($a_xpath);
603 foreach ($nodes as $node) {
604 $node->setAttribute($a_attr_id, $a_attr_value);
605 }
606 }
607
608 protected static function createBlogInPersonalWorkspace($a_title)
609 {
610 global $DIC;
611
612 $ilUser = $DIC->user();
613
614 static $ws_access = null;
615
616 include_once "Modules/Blog/classes/class.ilObjBlog.php";
617 $blog = new ilObjBlog();
618 $blog->setType("blog");
619 $blog->setTitle($a_title);
620 $blog->create();
621
622 if (!$ws_access) {
623 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
624 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
625 $tree = new ilWorkspaceTree($ilUser->getId());
626
627 // #13235
628 if (!$tree->getRootId()) {
629 $tree->createTreeForUser($ilUser->getId());
630 }
631
632 $ws_access = new ilWorkspaceAccessHandler($tree);
633 }
634
635 $tree = $ws_access->getTree();
636 $node_id = $tree->insertObject($tree->getRootId(), $blog->getId());
637 $ws_access->setPermissions($tree->getRootId(), $node_id);
638
639 return $blog->getId();
640 }
641
647 public function fixLinksOnTitleChange($a_title_changes)
648 {
649 foreach (ilPortfolioPage::getAllPortfolioPages($this->getId()) as $port_page) {
650 if ($this->getType() == "prtt") {
651 $page = new ilPortfolioTemplatePage($port_page["id"]);
652 } else {
653 $page = new ilPortfolioPage($port_page["id"]);
654 }
655 if ($page->renameLinksOnTitleChange($a_title_changes)) {
656 $page->update(true, true);
657 }
658 }
659 }
660}
An exception for terminatinating execution or to throw for unit testing.
static _copyDirectory($a_source, $a_target)
Copy directory and all contents.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type)
Are comments activated for object?
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
Class ilObjBlog.
deleteImage()
remove existing file
setPublicComments($a_value)
Set public comments status.
doUpdateCustom(array &$a_fields)
getStyleSheetId()
Get style sheet id.
setOnline($a_value)
Set online status.
static cloneBasics(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target)
Clone basic settings.
getBackgroundColor()
Get background color.
hasProfilePicture()
Get profile picture status.
uploadImage(array $a_upload)
Upload new image file.
setBackgroundColor($a_value)
Set background color.
static createBlogInPersonalWorkspace($a_title)
__construct($a_id=0, $a_reference=true)
Constructor.
setStyleSheetId($a_style)
Set style sheet id.
static updateDomNodes($a_dom, $a_xpath, $a_attr_id, $a_attr_value)
static lookupOnline($a_id)
Is online?
hasPublicComments()
Active public comments?
setImage($a_value)
Set banner image.
setProfilePicture($a_status)
Toggle profile picture status.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
fixLinksOnTitleChange($a_title_changes)
Fix internal portfolio links.
setFontColor($a_value)
Set font color.
static clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe=null)
Build template from portfolio and vice versa.
getImageFullPath($a_as_thumb=false)
Get banner image incl.
static _lookupStandard($a_id)
Lookup standard flag.
static lookupObjectStyle($a_obj_id)
Lookup object style.
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
Class ilObject2 This is an intermediate progress of ilObject class.
getType()
get object type @access public
update()
update object in db
getId()
get object id @access public
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getSelectedUserSkills($a_user_id)
Get personal selected user skills.
static addPersonalSkill($a_user_id, $a_skill_node_id)
Add personal skill.
Page for user portfolio.
static getAllPortfolioPages($a_portfolio_id)
Get pages of portfolio.
static updateInternalLinks($a_copied_nodes, ilObjPortfolioBase $a_target_obj)
Update internal links, after multiple pages have been copied.
Page for portfolio template.
ILIAS Setting Class.
static escapeShellArg($a_arg)
static execConvert($args)
execute convert command
Access handler for personal workspace.
Tree handler for personal workspace.
$valid
$target_id
Definition: goto.php:49
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18