protected function doCloneObject($new_obj, $a_target_id, $a_copy_id = null)
 {
     self::cloneBasics($this, $new_obj);
     // copy pages
     include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
     foreach (ilPortfolioPage::getAllPages($this->getId()) as $page) {
         // see ilObjWiki::cloneObject();
         $page = new ilPortfolioTemplatePage($page["id"]);
         $new_page = new ilPortfolioTemplatePage();
         $new_page->setPortfolioId($new_obj->getId());
         $new_page->setTitle($page->getTitle());
         $new_page->setType($page->getType());
         $new_page->setOrderNr($page->getOrderNr());
         $new_page->create();
         $page->copy($new_page->getId(), "", 0, true);
     }
 }
 /**
  * Build template from portfolio and vice versa
  * 
  * @param ilObjPortfolioBase $a_source
  * @param ilObjPortfolioBase $a_target
  * @param array $a_recipe
  */
 public static function clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe = null)
 {
     global $lng, $ilUser;
     $source_id = $a_source->getId();
     $target_id = $a_target->getId();
     if ($a_source instanceof ilObjPortfolioTemplate && $a_target instanceof ilObjPortfolio) {
         $direction = "t2p";
     } else {
         if ($a_source instanceof ilObjPortfolio && $a_target instanceof ilObjPortfolioTemplate) {
             $direction = "p2t";
         } else {
             return;
         }
     }
     // copy portfolio properties
     $a_target->setPublicComments($a_source->hasPublicComments());
     $a_target->setProfilePicture($a_source->hasProfilePicture());
     $a_target->setFontColor($a_source->getFontColor());
     $a_target->setBackgroundColor($a_source->getBackgroundColor());
     $a_target->setImage($a_source->getImage());
     $a_target->update();
     // banner/images
     $source_dir = $a_source->initStorage($source_id);
     $target_dir = $a_target->initStorage($target_id);
     ilFSStoragePortfolio::_copyDirectory($source_dir, $target_dir);
     // set/copy stylesheet
     include_once "./Services/Style/classes/class.ilObjStyleSheet.php";
     $style_id = $a_source->getStyleSheetId();
     if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) {
         $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
         $new_id = $style_obj->ilClone();
         $a_target->setStyleSheetId($new_id);
         $a_target->update();
     }
     // copy pages
     $blog_count = 0;
     include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
     foreach (ilPortfolioPage::getAllPages($source_id) as $page) {
         $page_id = $page["id"];
         if ($direction == "t2p") {
             $source_page = new ilPortfolioTemplatePage($page_id);
             $target_page = new ilPortfolioPage();
         } else {
             $source_page = new ilPortfolioPage($page_id);
             $target_page = new ilPortfolioTemplatePage();
         }
         $source_page->setPortfolioId($source_id);
         $target_page->setPortfolioId($target_id);
         $page_type = $source_page->getType();
         $page_title = $source_page->getTitle();
         $page_recipe = null;
         if (is_array($a_recipe)) {
             $page_recipe = $a_recipe[$page_id];
         }
         $valid = false;
         switch ($page_type) {
             // blog => blog template
             case ilPortfolioTemplatePage::TYPE_BLOG:
                 if ($direction == "p2t") {
                     $page_type = ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE;
                     $page_title = $lng->txt("obj_blog") . " " . ++$blog_count;
                     $valid = true;
                 }
                 break;
                 // blog template => blog (needs recipe)
             // blog template => blog (needs recipe)
             case ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE:
                 if ($direction == "t2p" && is_array($page_recipe)) {
                     $page_type = ilPortfolioPage::TYPE_BLOG;
                     if ($page_recipe[0] == "blog") {
                         switch ($page_recipe[1]) {
                             case "create":
                                 $page_title = self::createBlogInPersonalWorkspace($page_recipe[2]);
                                 $valid = true;
                                 break;
                             case "reuse":
                                 $page_title = $page_recipe[2];
                                 $valid = true;
                                 break;
                             case "ignore":
                                 // do nothing
                                 break;
                         }
                     }
                 }
                 break;
                 // page editor
             // page editor
             default:
                 $target_page->setXMLContent($source_page->copyXmlContent(true));
                 // copy mobs
                 $target_page->buildDom(true);
                 // parse content / blocks
                 $dom = $target_page->getDom();
                 if ($dom instanceof php4DOMDocument) {
                     $dom = $dom->myDOMDocument;
                 }
                 if ($direction == "t2p") {
                     // update profile/consultation hours user id
                     self::updateDomNodes($dom, "//PageContent/Profile", "User", $ilUser->getId());
                     self::updateDomNodes($dom, "//PageContent/ConsultationHours", "User", $ilUser->getId());
                 }
                 // :TODO: skills
                 $valid = true;
                 break;
         }
         if ($valid) {
             // #12038 - update xml from dom
             $target_page->setXMLContent($target_page->getXMLFromDom());
             $target_page->setType($page_type);
             $target_page->setTitle($page_title);
             $target_page->create();
             if ($page_type == ilPortfolioPage::TYPE_PAGE) {
                 $target_page->update();
                 // handle mob usages!
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case "prtt":
             include_once "./Modules/Portfolio/classes/class.ilObjPortfolioTemplate.php";
             // container copy
             if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjPortfolioTemplate();
                 $newObj->create();
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->setPublicComments($a_rec["Comments"]);
             $newObj->setBackgroundColor($a_rec["BgColor"]);
             $newObj->setFontColor($a_rec["FontColor"]);
             $newObj->setProfilePicture($a_rec["Ppic"]);
             $newObj->setImage($a_rec["Img"]);
             $newObj->update();
             // handle image(s)
             if ($a_rec["Img"]) {
                 $dir = str_replace("..", "", $a_rec["Dir"]);
                 if ($dir != "" && $this->getImportDirectory() != "") {
                     $source_dir = $this->getImportDirectory() . "/" . $dir;
                     $target_dir = ilObjPortfolioTemplate::initStorage($newObj->getId());
                     ilUtil::rCopy($source_dir, $target_dir);
                 }
             }
             $a_mapping->addMapping("Modules/Portfolio", "prtt", $a_rec["Id"], $newObj->getId());
             break;
         case "portfolio_page":
             $prtt_id = (int) $a_mapping->getMapping("Modules/Portfolio", "prtt", $a_rec["PortfolioId"]);
             if ($prtt_id) {
                 include_once "./Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
                 $newObj = new ilPortfolioTemplatePage();
                 $newObj->setPortfolioId($prtt_id);
                 $newObj->setTitle($a_rec["Title"]);
                 $newObj->setType($a_rec["Type"]);
                 $newObj->setOrderNr($a_rec["OrderNr"]);
                 $newObj->create(true);
                 $a_mapping->addMapping("Services/COPage", "pg", "prtt:" . $a_rec["Id"], "prtt:" . $newObj->getId());
             }
             break;
     }
 }
Exemplo n.º 4
0
 /**
  * Build template from portfolio and vice versa
  * 
  * @param ilObjPortfolioBase $a_source
  * @param ilObjPortfolioBase $a_target
  * @param array $a_recipe
  */
 public static function clonePagesAndSettings(ilObjPortfolioBase $a_source, ilObjPortfolioBase $a_target, array $a_recipe = null)
 {
     global $lng, $ilUser;
     $source_id = $a_source->getId();
     $target_id = $a_target->getId();
     if ($a_source instanceof ilObjPortfolioTemplate && $a_target instanceof ilObjPortfolio) {
         $direction = "t2p";
     } else {
         if ($a_source instanceof ilObjPortfolio && $a_target instanceof ilObjPortfolioTemplate) {
             $direction = "p2t";
         } else {
             return;
         }
     }
     self::cloneBasics($a_source, $a_target);
     // personal skills
     include_once "Services/Skill/classes/class.ilPersonalSkill.php";
     $pskills = array_keys(ilPersonalSkill::getSelectedUserSkills($ilUser->getId()));
     // copy pages
     $blog_count = 0;
     include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php";
     foreach (ilPortfolioPage::getAllPages($source_id) as $page) {
         $page_id = $page["id"];
         if ($direction == "t2p") {
             $source_page = new ilPortfolioTemplatePage($page_id);
             $target_page = new ilPortfolioPage();
         } else {
             $source_page = new ilPortfolioPage($page_id);
             $target_page = new ilPortfolioTemplatePage();
         }
         $source_page->setPortfolioId($source_id);
         $target_page->setPortfolioId($target_id);
         $page_type = $source_page->getType();
         $page_title = $source_page->getTitle();
         $page_recipe = null;
         if (is_array($a_recipe)) {
             $page_recipe = $a_recipe[$page_id];
         }
         $valid = false;
         switch ($page_type) {
             // blog => blog template
             case ilPortfolioTemplatePage::TYPE_BLOG:
                 if ($direction == "p2t") {
                     $page_type = ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE;
                     $page_title = $lng->txt("obj_blog") . " " . ++$blog_count;
                     $valid = true;
                 }
                 break;
                 // blog template => blog (needs recipe)
             // blog template => blog (needs recipe)
             case ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE:
                 if ($direction == "t2p" && is_array($page_recipe)) {
                     $page_type = ilPortfolioPage::TYPE_BLOG;
                     if ($page_recipe[0] == "blog") {
                         switch ($page_recipe[1]) {
                             case "create":
                                 $page_title = self::createBlogInPersonalWorkspace($page_recipe[2]);
                                 $valid = true;
                                 break;
                             case "reuse":
                                 $page_title = $page_recipe[2];
                                 $valid = true;
                                 break;
                             case "ignore":
                                 // do nothing
                                 break;
                         }
                     }
                 }
                 break;
                 // page editor
             // page editor
             default:
                 $target_page->setXMLContent($source_page->copyXmlContent(true));
                 // copy mobs
                 $target_page->buildDom(true);
                 // parse content / blocks
                 if ($direction == "t2p") {
                     $dom = $target_page->getDom();
                     if ($dom instanceof php4DOMDocument) {
                         $dom = $dom->myDOMDocument;
                     }
                     // update profile/consultation hours user id
                     self::updateDomNodes($dom, "//PageContent/Profile", "User", $ilUser->getId());
                     self::updateDomNodes($dom, "//PageContent/ConsultationHours", "User", $ilUser->getId());
                     self::updateDomNodes($dom, "//PageContent/MyCourses", "User", $ilUser->getId());
                     // skills
                     $xpath = new DOMXPath($dom);
                     $nodes = $xpath->query("//PageContent/Skills");
                     foreach ($nodes as $node) {
                         $skill_id = $node->getAttribute("Id");
                         // existing personal skills
                         if (in_array($skill_id, $pskills)) {
                             $node->setAttribute("User", $ilUser->getId());
                         } else {
                             if (in_array($skill_id, $a_recipe["skills"])) {
                                 include_once "Services/Skill/classes/class.ilPersonalSkill.php";
                                 ilPersonalSkill::addPersonalSkill($ilUser->getId(), $skill_id);
                                 $node->setAttribute("User", $ilUser->getId());
                             } else {
                                 $page_element = $node->parentNode;
                                 $page_element->parentNode->removeChild($page_element);
                             }
                         }
                     }
                 }
                 $valid = true;
                 break;
         }
         if ($valid) {
             // #12038 - update xml from dom
             $target_page->setXMLContent($target_page->getXMLFromDom());
             $target_page->setType($page_type);
             $target_page->setTitle($page_title);
             $target_page->create();
             if ($page_type == ilPortfolioPage::TYPE_PAGE) {
                 $target_page->update();
                 // handle mob usages!
             }
         }
     }
 }