Skip to content

Commit

Permalink
portfolio: separate with/out template creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Sep 28, 2023
1 parent 21a47ea commit 480b4fe
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
89 changes: 85 additions & 4 deletions Modules/Portfolio/classes/class.ilObjPortfolioGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,29 @@ public function create(): void
if ($this->port_request->getCopyFormProcess() && isset($forms[self::CFORM_CLONE])) {
$forms = array(self::CFORM_CLONE => $forms[self::CFORM_CLONE]);
}
$tpl->setContent($this->getCreateInfoMessage() . $this->getCreationFormsHTML($forms));
$tpl->setContent($this->getCreationFormsHTML($forms));
}
}

public function createFromTemplate(): void
{
$tpl = $this->tpl;
$ilErr = $this->error;

$new_type = $this->port_request->getNewType();

// add new object to custom parent container
$this->ctrl->saveParameter($this, "crtptrefid");
// use forced callback after object creation
$this->ctrl->saveParameter($this, "crtcb");

if (!$this->checkPermissionBool("create", "", $new_type)) {
$ilErr->raiseError($this->lng->txt("permission_denied"), $ilErr->MESSAGE);
} else {
$this->lng->loadLanguageModule($new_type);
$this->ctrl->setParameter($this, "new_type", $new_type);
$form = $this->initCreateFromTemplateForm();
$tpl->setContent($form->getHTML());
}
}

Expand Down Expand Up @@ -370,6 +392,7 @@ protected function initCreateForm(string $new_type): ilPropertyFormGUI
$ti->setRequired(true);
$form->addItem($ti);

/*
$main = new ilRadioGroupInputGUI($this->lng->txt("prtf_creation_mode"), "mode");
$main->setValue("mode_scratch");
$form->addItem($main);
Expand Down Expand Up @@ -457,7 +480,7 @@ protected function initCreateForm(string $new_type): ilPropertyFormGUI
$tmpl->setValue($template_id);
$main->setValue("mode_tmpl");
}
}
}*/


$form->setTitle($this->lng->txt("prtf_create_portfolio"));
Expand All @@ -467,24 +490,82 @@ protected function initCreateForm(string $new_type): ilPropertyFormGUI
return $form;
}

protected function initCreateFromTemplateForm(): ilPropertyFormGUI
{
$ilSetting = $this->settings;

$this->ctrl->setParameter($this, "new_type", $this->getType());

$form = new ilPropertyFormGUI();
$form->setFormAction($this->ctrl->getFormAction($this));

// title
$ti = new ilTextInputGUI($this->lng->txt("title"), "title");
$ti->setSize(min(40, ilObject::TITLE_LENGTH));
$ti->setMaxLength(ilObject::TITLE_LENGTH);
$ti->setRequired(true);
$form->addItem($ti);

// portfolio templates
$templates = ilObjPortfolioTemplate::getAvailablePortfolioTemplates();
if (!count($templates)) {
$opt_tmpl->setDisabled(true);
} else {
$tmpl = new ilSelectInputGUI($this->lng->txt("obj_prtt"), "prtt");
$tmpl->setRequired(true);
$tmpl->setOptions(array("" => $this->lng->txt("please_select")) + $templates);
$form->addItem($tmpl);

// incoming from repository
$template_id = $this->port_request->getPortfolioTemplateId();
if ($template_id > 0) {
$tmpl->setValue($template_id);
}
}

$form->setTitle($this->lng->txt("prtf_create_portfolio"));
$form->addCommandButton("saveFromTemplate", $this->lng->txt("create"));
$form->addCommandButton("toRepository", $this->lng->txt("cancel"));

return $form;
}

public function save(): void
{
$form = $this->initCreateForm("prtf");
// trigger portfolio template "import" process
/*
if ($form->checkInput() && $form->getInput("mode") == "mode_tmpl") {
$this->createFromTemplateDirect(
$form->getInput("title"),
$this->port_request->getPortfolioTemplate()
);
return;
}
}*/

parent::save();
}

public function saveFromTemplate(): void
{
$form = $this->initCreateFromTemplateForm();
// trigger portfolio template "import" process
if ($form->checkInput()) {
$this->createFromTemplateDirect(
$form->getInput("title"),
$this->port_request->getPortfolioTemplate()
);
return;
} else {
$form->setValuesByPost();
$this->tpl->setContent($form->getHTML());
}
}

protected function afterSave(ilObject $new_object): void
{
// create 1st page / blog
/*
$page = $this->getPageInstance(null, $new_object->getId());
if ($this->port_request->getPageType() === "page") {
$page->setType(ilPortfolioPage::TYPE_PAGE);
Expand All @@ -500,7 +581,7 @@ protected function afterSave(ilObject $new_object): void
$page->setType(ilPortfolioPage::TYPE_BLOG);
$page->setTitle($this->port_request->getBlogTitle());
}
$page->create();
$page->create();*/

$this->tpl->setOnScreenMessage('success', $this->lng->txt("prtf_portfolio_created"), true);
$this->ctrl->setParameter($this, "prt_id", $new_object->getId());
Expand Down
7 changes: 7 additions & 0 deletions Modules/Portfolio/classes/class.ilPortfolioRepositoryGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ protected function show(): void
$button->setCaption("prtf_add_portfolio");
$button->setUrl($ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "create"));
$ilToolbar->addButtonInstance($button);
$templates = ilObjPortfolioTemplate::getAvailablePortfolioTemplates();
if (count($templates) > 0) {
$button = ilLinkButton::getInstance();
$button->setCaption("prtf_add_portfolio_from_template");
$button->setUrl($ilCtrl->getLinkTargetByClass("ilObjPortfolioGUI", "createFromTemplate"));
$ilToolbar->addButtonInstance($button);
}
$portfolio_list = $this->getPortfolioList();

$tpl->setContent($portfolio_list);
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12892,6 +12892,7 @@ prtf#:#prtf_add_new_blog#:#Neues Blog hinzufügen
prtf#:#prtf_add_new_blog_info#:#Das neue Blog wird Ihren persönlichen Ressourcen hinzugefügt.
prtf#:#prtf_add_page#:#Seite hinzufügen
prtf#:#prtf_add_portfolio#:#Portfolio hinzufügen
prtf#:#prtf_add_portfolio_from_template#:#Portfolio aus Vorlage hinzufügen
prtf#:#prtf_all_pages#:#Gesamtes Portfolio
prtf#:#prtf_allow_html#:#HTML/Javascript erlauben
prtf#:#prtf_allow_html_info#:#Benutzer können HTML oder Javascript in Ihren Portfolio-Seiten verwenden. Dies kann zu Sicherheitsproblemen führen.
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12892,6 +12892,7 @@ prtf#:#prtf_add_new_blog#:#Add New Blog
prtf#:#prtf_add_new_blog_info#:#The new blog will be added to your personal resources.
prtf#:#prtf_add_page#:#Add Page
prtf#:#prtf_add_portfolio#:#Add Portfolio
prtf#:#prtf_add_portfolio_from_template#:#Add Portfolio From Template
prtf#:#prtf_all_pages#:#All Pages
prtf#:#prtf_allow_html#:#Allow HTML/Javascript
prtf#:#prtf_allow_html_info#:#Enables users to include HTML and/or Javascript in their portfolio pages. This can lead to security issues.
Expand Down

0 comments on commit 480b4fe

Please sign in to comment.