ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
4 require_once "Services/Object/classes/class.ilObject2.php";
5 
14 abstract class ilObjPortfolioBase extends ilObject2
15 {
16  protected $online; // [bool]
17  protected $comments; // [bool]
18  protected $bg_color; // [string]
19  protected $font_color; // [string]
20  protected $img; // [string]
21  protected $ppic; // [string]
22  protected $style; // [bool]
23 
24 
25  //
26  // PROPERTIES
27  //
28 
34  function setOnline($a_value)
35  {
36  $this->online = (bool)$a_value;
37  }
38 
44  function isOnline()
45  {
46  return $this->online;
47  }
48 
54  public static function lookupOnline($a_id)
55  {
56  global $ilDB;
57 
58  $set = $ilDB->query("SELECT is_online".
59  " FROM usr_portfolio".
60  " WHERE id = ".$ilDB->quote($a_id, "integer"));
61  $row = $ilDB->fetchAssoc($set);
62  return (bool)$row["is_online"];
63  }
64 
70  function setPublicComments($a_value)
71  {
72  $this->comments = (bool)$a_value;
73  }
74 
80  function hasPublicComments()
81  {
82  return $this->comments;
83  }
84 
90  function hasProfilePicture()
91  {
92  return $this->ppic;
93  }
94 
100  function setProfilePicture($a_status)
101  {
102  $this->ppic = (bool)$a_status;
103  }
104 
111  {
112  if(!$this->bg_color)
113  {
114  $this->bg_color = "ffffff";
115  }
116  return $this->bg_color;
117  }
118 
124  function setBackgroundColor($a_value)
125  {
126  $this->bg_color = (string)$a_value;
127  }
128 
134  function getFontColor()
135  {
136  if(!$this->font_color)
137  {
138  $this->font_color = "505050";
139  }
140  return $this->font_color;
141  }
142 
148  function setFontColor($a_value)
149  {
150  $this->font_color = (string)$a_value;
151  }
152 
158  function getImage()
159  {
160  return $this->img;
161  }
162 
168  function setImage($a_value)
169  {
170  $this->img = (string)$a_value;
171  }
172 
178  function getStyleSheetId()
179  {
180  return (int)$this->style;
181  }
182 
188  function setStyleSheetId($a_style)
189  {
190  $this->style = (int)$a_style;
191  }
192 
193 
194  //
195  // CRUD
196  //
197 
198  protected function doRead()
199  {
200  global $ilDB;
201 
202  $set = $ilDB->query("SELECT * FROM usr_portfolio".
203  " WHERE id = ".$ilDB->quote($this->id, "integer"));
204  $row = $ilDB->fetchAssoc($set);
205 
206  $this->setOnline((bool)$row["is_online"]);
207  $this->setProfilePicture((bool)$row["ppic"]);
208  $this->setBackgroundColor($row["bg_color"]);
209  $this->setFontColor($row["font_color"]);
210  $this->setImage($row["img"]);
211 
212  // #14661
213  include_once("./Services/Notes/classes/class.ilNote.php");
214  $this->setPublicComments(ilNote::commentsActivated($this->id, 0, $this->getType()));
215 
216  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
218 
219  $this->doReadCustom($row);
220  }
221 
222  protected function doReadCustom(array $a_row)
223  {
224 
225  }
226 
227  protected function doCreate()
228  {
229  global $ilDB;
230 
231  $ilDB->manipulate("INSERT INTO usr_portfolio (id,is_online)".
232  " VALUES (".$ilDB->quote($this->id, "integer").",".
233  $ilDB->quote(0, "integer").")");
234  }
235 
236  protected function doUpdate()
237  {
238  global $ilDB;
239 
240  $fields = array(
241  "is_online" => array("integer", $this->isOnline()),
242  "ppic" => array("integer", $this->hasProfilePicture()),
243  "bg_color" => array("text", $this->getBackgroundColor()),
244  "font_color" => array("text", $this->getFontcolor()),
245  "img" => array("text", $this->getImage())
246  );
247  $this->doUpdateCustom($fields);
248 
249  // #14661
250  include_once("./Services/Notes/classes/class.ilNote.php");
251  ilNote::activateComments($this->id, 0, $this->getType(), $this->hasPublicComments());
252 
253  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
255 
256  $ilDB->update("usr_portfolio", $fields,
257  array("id"=>array("integer", $this->id)));
258  }
259 
260  protected function doUpdateCustom(array &$a_fields)
261  {
262 
263  }
264 
265  protected function doDelete()
266  {
267  global $ilDB;
268 
269  $this->deleteAllPages();
270  $this->deleteImage();
271 
272  $ilDB->manipulate("DELETE FROM usr_portfolio".
273  " WHERE id = ".$ilDB->quote($this->id, "integer"));
274  }
275 
276  abstract protected function deleteAllPages();
277 
278 
279  //
280  // IMAGES
281  //
282 
288  function getImageFullPath($a_as_thumb = false)
289  {
290  if($this->img)
291  {
292  $path = $this->initStorage($this->id);
293  if(!$a_as_thumb)
294  {
295  return $path.$this->img;
296  }
297  else
298  {
299  return $path."thb_".$this->img;
300  }
301  }
302  }
303 
307  public function deleteImage()
308  {
309  if($this->id)
310  {
311  include_once "Modules/Portfolio/classes/class.ilFSStoragePortfolio.php";
312  $storage = new ilFSStoragePortfolio($this->id);
313  $storage->delete();
314 
315  $this->setImage(null);
316  }
317  }
318 
326  public static function initStorage($a_id, $a_subdir = null)
327  {
328  include_once "Modules/Portfolio/classes/class.ilFSStoragePortfolio.php";
329  $storage = new ilFSStoragePortfolio($a_id);
330  $storage->create();
331 
332  $path = $storage->getAbsolutePath()."/";
333 
334  if($a_subdir)
335  {
336  $path .= $a_subdir."/";
337 
338  if(!is_dir($path))
339  {
340  mkdir($path);
341  }
342  }
343 
344  return $path;
345  }
346 
353  function uploadImage(array $a_upload)
354  {
355  if(!$this->id)
356  {
357  return false;
358  }
359 
360  $this->deleteImage();
361 
362  // #10074
363  $clean_name = preg_replace("/[^a-zA-Z0-9\_\.\-]/", "", $a_upload["name"]);
364 
365  $path = $this->initStorage($this->id);
366  $original = "org_".$this->id."_".$clean_name;
367  $thumb = "thb_".$this->id."_".$clean_name;
368  $processed = $this->id."_".$clean_name;
369 
370  if (ilUtil::moveUploadedFile($a_upload["tmp_name"], $original, $path.$original))
371  {
372  chmod($path.$original, 0770);
373 
374  $prfa_set = new ilSetting("prfa");
375  /* as banner height should overflow, we only handle width
376  $dimensions = $prfa_set->get("banner_width")."x".
377  $prfa_set->get("banner_height");
378  */
379  $dimensions = $prfa_set->get("banner_width");
380 
381  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
382  // taking only frame [0] to avoid problems with animated gifs
383  $original_file = ilUtil::escapeShellArg($path.$original);
384  $thumb_file = ilUtil::escapeShellArg($path.$thumb);
385  $processed_file = ilUtil::escapeShellArg($path.$processed);
386  ilUtil::execConvert($original_file."[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
387  ilUtil::execConvert($original_file."[0] -geometry ".$dimensions." -quality 100 JPEG:".$processed_file);
388 
389  $this->setImage($processed);
390 
391  return true;
392  }
393  return false;
394  }
395 
396 
397  //
398  // TRANSMOGRIFIER
399  //
400 
407  protected static function cloneBasics(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target)
408  {
409  // copy portfolio properties
410  $a_target->setPublicComments($a_source->hasPublicComments());
411  $a_target->setProfilePicture($a_source->hasProfilePicture());
412  $a_target->setFontColor($a_source->getFontColor());
413  $a_target->setBackgroundColor($a_source->getBackgroundColor());
414  $a_target->setImage($a_source->getImage());
415  $a_target->update();
416 
417  // banner/images
418  $source_dir = $a_source->initStorage($a_source->getId());
419  $target_dir = $a_target->initStorage($a_target->getId());
420  ilFSStoragePortfolio::_copyDirectory($source_dir, $target_dir);
421 
422  // set/copy stylesheet
423  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
424  $style_id = $a_source->getStyleSheetId();
425  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
426  {
427  $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
428  $new_id = $style_obj->ilClone();
429  $a_target->setStyleSheetId($new_id);
430  $a_target->update();
431  }
432  }
433 
441  public static function clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe = null)
442  {
443  global $lng, $ilUser;
444 
445  $source_id = $a_source->getId();
446  $target_id = $a_target->getId();
447 
448  if($a_source instanceof ilObjPortfolioTemplate &&
449  $a_target instanceof ilObjPortfolio)
450  {
451  $direction = "t2p";
452  }
453  else if($a_source instanceof ilObjPortfolio &&
454  $a_target instanceof ilObjPortfolioTemplate)
455  {
456  $direction = "p2t";
457  }
458  else
459  {
460  return;
461  }
462 
463  self::cloneBasics($a_source, $a_target);
464 
465  // personal skills
466  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
467  $pskills = array_keys(ilPersonalSkill::getSelectedUserSkills($ilUser->getId()));
468 
469  // copy pages
470  $blog_count = 0;
471  include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
472  foreach(ilPortfolioPage::getAllPages($source_id) as $page)
473  {
474  $page_id = $page["id"];
475 
476  if($direction == "t2p")
477  {
478  $source_page = new ilPortfolioTemplatePage($page_id);
479  $target_page = new ilPortfolioPage();
480  }
481  else
482  {
483  $source_page = new ilPortfolioPage($page_id);
484  $target_page = new ilPortfolioTemplatePage();
485  }
486  $source_page->setPortfolioId($source_id);
487  $target_page->setPortfolioId($target_id);
488 
489  $page_type = $source_page->getType();
490  $page_title = $source_page->getTitle();
491 
492 
493 
494 
495  $page_recipe = null;
496  if(is_array($a_recipe))
497  {
498  $page_recipe = $a_recipe[$page_id];
499  }
500 
501  $valid = false;
502  switch($page_type)
503  {
504  // blog => blog template
506  if($direction == "p2t")
507  {
509  $page_title = $lng->txt("obj_blog")." ".(++$blog_count);
510  $valid = true;
511  }
512  break;
513 
514  // blog template => blog (needs recipe)
516  if($direction == "t2p" && is_array($page_recipe))
517  {
518  $page_type = ilPortfolioPage::TYPE_BLOG;
519  if($page_recipe[0] == "blog")
520  {
521  switch($page_recipe[1])
522  {
523  case "create":
524  $page_title = self::createBlogInPersonalWorkspace($page_recipe[2]);
525  $valid = true;
526  break;
527 
528  case "reuse":
529  $page_title = $page_recipe[2];
530  $valid = true;
531  break;
532 
533  case "ignore":
534  // do nothing
535  break;
536  }
537  }
538  }
539  break;
540 
541  // page editor
542  default:
543  $target_page->setXMLContent($source_page->copyXmlContent(true)); // copy mobs
544  $target_page->buildDom(true);
545 
546 
547  // parse content / blocks
548 
549  if($direction == "t2p")
550  {
551  $dom = $target_page->getDom();
552  if($dom instanceof php4DOMDocument)
553  {
554  $dom = $dom->myDOMDocument;
555  }
556 
557  // update profile/consultation hours user id
558  self::updateDomNodes($dom, "//PageContent/Profile", "User", $ilUser->getId());
559  self::updateDomNodes($dom, "//PageContent/ConsultationHours", "User", $ilUser->getId());
560  self::updateDomNodes($dom, "//PageContent/MyCourses", "User", $ilUser->getId());
561 
562  // skills
563  $xpath = new DOMXPath($dom);
564  $nodes = $xpath->query("//PageContent/Skills");
565  foreach($nodes as $node)
566  {
567  $skill_id = $node->getAttribute("Id");
568 
569  // existing personal skills
570  if(in_array($skill_id, $pskills))
571  {
572  $node->setAttribute("User", $ilUser->getId());
573  }
574  // new skill
575  else if(in_array($skill_id, $a_recipe["skills"]))
576  {
577  include_once "Services/Skill/classes/class.ilPersonalSkill.php";
578  ilPersonalSkill::addPersonalSkill($ilUser->getId(), $skill_id);
579 
580  $node->setAttribute("User", $ilUser->getId());
581  }
582  // remove skill
583  else
584  {
585  $page_element = $node->parentNode;
586  $page_element->parentNode->removeChild($page_element);
587  }
588  }
589  }
590 
591  $valid = true;
592  break;
593  }
594 
595  if($valid)
596  {
597  // #12038 - update xml from dom
598  $target_page->setXMLContent($target_page->getXMLFromDom());
599 
600  $target_page->setType($page_type);
601  $target_page->setTitle($page_title);
602  $target_page->create();
603 
604  if($page_type == ilPortfolioPage::TYPE_PAGE)
605  {
606  $target_page->update(); // handle mob usages!
607  }
608  }
609  }
610  }
611 
612  protected static function updateDomNodes($a_dom, $a_xpath, $a_attr_id, $a_attr_value)
613  {
614  $xpath_temp = new DOMXPath($a_dom);
615  $nodes = $xpath_temp->query($a_xpath);
616  foreach ($nodes as $node)
617  {
618  $node->setAttribute($a_attr_id, $a_attr_value);
619  }
620  }
621 
622  protected static function createBlogInPersonalWorkspace($a_title)
623  {
624  global $ilUser;
625 
626  static $ws_access = null;
627 
628  include_once "Modules/Blog/classes/class.ilObjBlog.php";
629  $blog = new ilObjBlog();
630  $blog->setType("blog");
631  $blog->setTitle($a_title);
632  $blog->create();
633 
634  if(!$ws_access)
635  {
636  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
637  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
638  $tree = new ilWorkspaceTree($ilUser->getId());
639 
640  // #13235
641  if(!$tree->getRootId())
642  {
643  $tree->createTreeForUser($ilUser->getId());
644  }
645 
646  $ws_access = new ilWorkspaceAccessHandler($tree);
647  }
648 
649  $tree = $ws_access->getTree();
650  $node_id = $tree->insertObject($tree->getRootId(), $blog->getId());
651  $ws_access->setPermissions($tree->getRootId(), $node_id);
652 
653  return $blog->getId();
654  }
655 }
656 
657 ?>
ILIAS Setting Class.
static updateDomNodes($a_dom, $a_xpath, $a_attr_id, $a_attr_value)
getStyleSheetId()
Get style sheet id.
setPublicComments($a_value)
Set public comments status.
createTreeForUser($a_user_id)
Create personal workspace tree for user.
getImageFullPath($a_as_thumb=false)
Get banner image incl.
deleteImage()
remove existing file
_copyDirectory($a_source, $a_target)
Copy directory and all contents.
$valid
static initStorage($a_id, $a_subdir=null)
Init file system storage.
setFontColor($a_value)
Set font color.
"color:#CC0000 style
Definition: example_001.php:92
static clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe=null)
Build template from portfolio and vice versa.
Access handler for personal workspace.
$target_id
Definition: goto.php:88
static createBlogInPersonalWorkspace($a_title)
static getSelectedUserSkills($a_user_id)
Get personal selected user skills.
hasProfilePicture()
Get profile picture status.
getBackgroundColor()
Get background color.
addPersonalSkill($a_user_id, $a_skill_node_id)
Add personal skill.
getFontColor()
Get font color.
static lookupObjectStyle($a_obj_id)
Lookup object style.
Tree handler for personal workspace.
setOnline($a_value)
Set online status.
static cloneBasics(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target)
Clone basic settings.
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
uploadImage(array $a_upload)
Upload new image file.
static lookupOnline($a_id)
Is online?
static execConvert($args)
execute convert command
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
Class ilObjBlog.
Page for user portfolio.
Page for portfolio template.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
hasPublicComments()
Active public comments?
getImage()
Get banner image.
static getAllPages($a_portfolio_id)
Get pages of portfolio.
_lookupStandard($a_id)
Lookup standard flag.
setStyleSheetId($a_style)
Set style sheet id.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type)
Are comments activated for object?
global $ilUser
Definition: imgupload.php:15
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
static escapeShellArg($a_arg)
$path
Definition: index.php:22
global $ilDB
setBackgroundColor($a_value)
Set background color.
Class ilObject2 This is an intermediate progress of ilObject class.
doUpdateCustom(array &$a_fields)
setImage($a_value)
Set banner image.
setProfilePicture($a_status)
Toggle profile picture status.