/** * @return array */ protected function addSkills() { $user = $this->getUsrObject(); $pskills = array_keys(ilPersonalSkill::getSelectedUserSkills($user->getId())); $skill_ids = array(); $recipe = array(); foreach (ilPortfolioTemplatePage::getAllPages($this->getPortfolioTemplateId()) as $page) { switch ($page['type']) { case ilPortfolioTemplatePage::TYPE_PAGE: $source_page = new ilPortfolioTemplatePage($page['id']); $source_page->buildDom(true); $dom = $source_page->getDom(); if ($dom instanceof php4DOMDocument) { $dom = $dom->myDOMDocument; } $xpath = new DOMXPath($dom); $nodes = $xpath->query('//PageContent/Skills'); foreach ($nodes as $node) { $skill_id = $node->getAttribute('Id'); if (!in_array($skill_id, $pskills)) { $skill_ids[] = $skill_id; } } unset($nodes); unset($xpath); unset($dom); break; } } foreach ($skill_ids as $skill_id) { ilPersonalSkill::addPersonalSkill($user->getId(), $skill_id); } }
protected function initCreatePortfolioFromTemplateForm($a_prtt_id, $a_title) { global $ilSetting, $ilUser; if ((int) $_REQUEST["exc_id"]) { $this->ctrl->setParameter($this, "exc_id", (int) $_REQUEST["exc_id"]); $this->ctrl->setParameter($this, "ass_id", (int) $_REQUEST["ass_id"]); } include_once "Services/Form/classes/class.ilPropertyFormGUI.php"; $form = new ilPropertyFormGUI(); $form->setFormAction($this->ctrl->getFormAction($this)); $tmpl = new ilNonEditableValueGUI($this->lng->txt("obj_prtt")); $tmpl->setValue(ilObject::_lookupTitle($a_prtt_id)); $form->addItem($tmpl); $title = new ilNonEditableValueGUI($this->lng->txt("title"), "pt"); $title->setValue($a_title); $form->addItem($title); // gather user blogs if (!$ilSetting->get('disable_wsp_blogs')) { $blog_options = array(); include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php"; $tree = new ilWorkspaceTree($this->user_id); $root = $tree->readRootId(); if ($root) { $root = $tree->getNodeData($root); foreach ($tree->getSubTree($root, true, "blog") as $node) { $blog_options[$node["obj_id"]] = $node["title"]; } asort($blog_options); } } $has_form_content = false; include_once "Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php"; $check_quota = ilDiskQuotaActivationChecker::_isPersonalWorkspaceActive(); $quota_sum = 0; include_once "Services/Skill/classes/class.ilPersonalSkill.php"; $pskills = array_keys(ilPersonalSkill::getSelectedUserSkills($ilUser->getId())); $skill_ids = array(); include_once "Modules/Portfolio/classes/class.ilPortfolioTemplatePage.php"; foreach (ilPortfolioTemplatePage::getAllPages($a_prtt_id) as $page) { switch ($page["type"]) { case ilPortfolioTemplatePage::TYPE_PAGE: // skills $source_page = new ilPortfolioTemplatePage($page["id"]); $source_page->buildDom(true); $dom = $source_page->getDom(); if ($dom instanceof php4DOMDocument) { $dom = $dom->myDOMDocument; } $xpath = new DOMXPath($dom); $nodes = $xpath->query("//PageContent/Skills"); foreach ($nodes as $node) { $skill_id = $node->getAttribute("Id"); if (!in_array($skill_id, $pskills)) { $skill_ids[] = $skill_id; } } unset($nodes); unset($xpath); unset($dom); if ($check_quota) { $quota_sum += $source_page->getPageDiskSize(); } if (sizeof($skill_ids)) { $has_form_content = true; } break; case ilPortfolioTemplatePage::TYPE_BLOG_TEMPLATE: if (!$ilSetting->get('disable_wsp_blogs')) { $has_form_content = true; $field_id = "blog_" . $page["id"]; $blog = new ilRadioGroupInputGUI($this->lng->txt("obj_blog") . ": " . $page["title"], $field_id); $blog->setRequired(true); $blog->setValue("blog_create"); $form->addItem($blog); $new_blog = new ilRadioOption($this->lng->txt("prtf_template_import_blog_create"), "blog_create"); $blog->addOption($new_blog); $title = new ilTextInputGUI($this->lng->txt("title"), $field_id . "_create_title"); $title->setRequired(true); $new_blog->addSubItem($title); if (sizeof($blog_options)) { $reuse_blog = new ilRadioOption($this->lng->txt("prtf_template_import_blog_reuse"), "blog_resuse"); $blog->addOption($reuse_blog); $obj = new ilSelectInputGUI($this->lng->txt("obj_blog"), $field_id . "_reuse_blog"); $obj->setRequired(true); $obj->setOptions(array("" => $this->lng->txt("please_select")) + $blog_options); $reuse_blog->addSubItem($obj); } $blog->addOption(new ilRadioOption($this->lng->txt("prtf_template_import_blog_ignore"), "blog_ignore")); } break; } } if ($skill_ids) { include_once "Services/Skill/classes/class.ilSkillTreeNode.php"; $skills = new ilCheckboxGroupInputGUI($this->lng->txt("skills"), "skill_ids"); $skills->setInfo($this->lng->txt("prtf_template_import_new_skills")); $skills->setValue($skill_ids); foreach ($skill_ids as $skill_id) { $skills->addOption(new ilCheckboxOption(ilSkillTreeNode::_lookupTitle($skill_id), $skill_id)); } $form->addItem($skills); } if ($quota_sum) { include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php"; if (!ilDiskQuotaHandler::isUploadPossible($quota_sum)) { ilUtil::sendFailure($this->lng->txt("prtf_template_import_quota_failure"), true); $this->ctrl->redirect($this, "create"); } } // no dialog needed, go ahead if (!$has_form_content) { return; } $form->setTitle($this->lng->txt("prtf_creation_mode") . ": " . $this->lng->txt("prtf_creation_mode_template")); $form->addCommandButton("createPortfolioFromTemplateProcess", $this->lng->txt("continue")); $form->addCommandButton("toRepository", $this->lng->txt("cancel")); return $form; }
/** * 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! } } } }
/** * 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! } } } }