Skip to content

Commit

Permalink
copage: employing page templates i
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Sep 30, 2023
1 parent 70f90e1 commit 02341ed
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions Modules/LearningModule/classes/class.ilLMPageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function init(): void
if ($mset->get("mep_activate_pages")) {
$this->setEnablePCType("ContentInclude", true);
}
$this->setLayoutTemplateType(ilPageLayout::MODULE_LM);
}

/**
Expand Down
75 changes: 75 additions & 0 deletions Services/COPage/PC/LayoutTemplate/class.ilPCLayoutTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

/**
* Layout templates are not existing in the page. Once they are inserted into a page
* all content elements of the template are inserted instead.
*
* @author Alexander Killing <[email protected]>
*/
class ilPCLayoutTemplate extends ilPageContent
{
public function init(): void
{
$this->setType("lay");
}

public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, int $a_tmpl): void
{
$source_page = ilPageObjectFactory::getInstance("stys", $a_tmpl);
$source_page->buildDom();
$source_page->addHierIDs();
$hier_ids = $source_page->getHierIds();

$copy_ids = array();
foreach ($hier_ids as $hier_id) {
// move top level nodes only
if (!is_int(strpos($hier_id, "_"))) {
if ($hier_id != "pg") {
$copy_ids[] = $hier_id;
}
}
}
arsort($copy_ids);

foreach ($copy_ids as $copy_id) {
$source_content = $source_page->getContentObject($copy_id);

$source_node = $source_content->getNode();
$clone_node = $source_node->clone_node(true);
$clone_node->unlink_node($clone_node);

// insert cloned node at target
$source_content->setNode($clone_node);
$this->getPage()->insertContent($source_content, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);

$xpath = new DOMXpath($this->getPage()->getDomDoc());
if ($clone_node->get_attribute("PCID") != "") {
$clone_node->set_attribute("PCID", "");
}
$els = $xpath->query(".//*[@PCID]", $clone_node->myDOMNode);
foreach ($els as $el) {
$el->setAttribute("PCID", "");
}
}

$this->getPage()->update();
}
}
129 changes: 129 additions & 0 deletions Services/COPage/PC/LayoutTemplate/class.ilPCLayoutTemplateGUI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

/**
* @ilCtrl_isCalledBy ilPCLayoutTemplateGUI: ilPageEditorGUI
*/
class ilPCLayoutTemplateGUI extends ilPageContentGUI
{
public function __construct(
ilPageObject $a_pg_obj,
?ilPageContent $a_content_obj,
string $a_hier_id,
string $a_pc_id = ""
) {
global $DIC;

$this->tpl = $DIC["tpl"];
$this->ctrl = $DIC->ctrl();
$this->lng = $DIC->language();
parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
}

/**
* Execute command
*/
public function executeCommand(): void
{
// get next class that processes or forwards current command
$next_class = $this->ctrl->getNextClass($this);

// get current command
$cmd = $this->ctrl->getCmd();

switch ($next_class) {
default:
$this->$cmd();
break;
}
}

/**
* Insert content template
*/
public function insert(): void
{
$tpl = $this->tpl;

$this->displayValidationError();
$form = $this->initForm();
$tpl->setContent($form->getHTML());
}

/**
* Init creation from
*/
public function initForm(): ilPropertyFormGUI
{
$ilCtrl = $this->ctrl;
$lng = $this->lng;

// edit form
$form = new ilPropertyFormGUI();
$form->setFormAction($ilCtrl->getFormAction($this));
$form->setTitle($this->lng->txt("cont_ed_insert_lay"));

$config = $this->getPage()->getPageConfig();
$templates = ilPageLayout::activeLayouts($config->getLayoutTemplateType());
if ($templates) {
$use_template = new ilRadioGroupInputGUI($this->lng->txt("cont_layout"), "tmpl");
$use_template->setRequired(true);
$form->addItem($use_template);

foreach ($templates as $templ) {
$templ->readObject();
$opt = new ilRadioOption($templ->getTitle() . $templ->getPreview(), (string) $templ->getId());
$use_template->addOption($opt);
}
}

$form->addCommandButton("create_templ", $lng->txt("insert"));
$form->addCommandButton("cancelCreate", $lng->txt("cancel"));

return $form;
}

/**
* Insert the template
*/
public function create(): void
{
$tpl = $this->tpl;

$form = $this->initForm();
if ($form->checkInput()) {
$this->content_obj = new ilPCLayoutTemplate($this->getPage());
$this->content_obj->create(
$this->pg_obj,
$this->hier_id,
$this->pc_id,
(int) $form->getInput("tmpl")
);
$this->updated = $this->pg_obj->update();
if ($this->updated === true) {
$this->ctrl->returnToParent($this, "jump" . $this->hier_id);
return;
}
}
$this->displayValidationError();
$form->setValuesByPost();
$tpl->setContent($form->getHTML());
}
}
17 changes: 17 additions & 0 deletions Services/COPage/classes/class.ilPageConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abstract class ilPageConfig
public const SEC_PROTECT_NONE = 0; // page does not support section protection
public const SEC_PROTECT_EDITABLE = 1; // current use can edit protected sections
public const SEC_PROTECT_PROTECTED = 2; // current use cannot edit protected sections
protected int $layout_template_type = 0;

protected bool $int_link_def_id_is_ref = false;
protected ilLanguage $lng;
Expand Down Expand Up @@ -87,12 +88,28 @@ final public function __construct()
}
}
$this->init();
if ($this->getLayoutTemplateType() > 0) {
$templates = ilPageLayout::activeLayouts($this->getLayoutTemplateType());
if (count($templates) > 0) {
$this->setEnablePCType("LayoutTemplate", true);
}
}
}

public function init(): void
{
}

public function setLayoutTemplateType(int $type): void
{
$this->layout_template_type = $type;
}

public function getLayoutTemplateType(): int
{
return $this->layout_template_type;
}

public function setEnablePCType(string $a_pc_type, bool $a_val): void
{
$this->pc_enabled[$a_pc_type] = $a_val;
Expand Down
1 change: 1 addition & 0 deletions Services/COPage/service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<pagecontent pc_type="skills" name="Skills" directory="classes" int_links="0" style_classes="0" xsl="0" def_enabled="0" top_item="1" order_nr="160"/>
<pagecontent pc_type="vrfc" name="Verification" directory="classes" int_links="0" style_classes="0" xsl="0" def_enabled="0" top_item="1" order_nr="180"/>
<pagecontent pc_type="src" name="SourceCode" directory="classes" int_links="0" style_classes="0" xsl="0" def_enabled="1" top_item="1" order_nr="190"/>
<pagecontent pc_type="lay" name="LayoutTemplate" directory="PC/LayoutTemplate" int_links="0" style_classes="0" xsl="0" def_enabled="0" top_item="1" order_nr="195"/>
<pagecontent pc_type="templ" name="ContentTemplate" directory="classes" int_links="0" style_classes="0" xsl="0" def_enabled="0" top_item="1" order_nr="200"/>
<pagecontent pc_type="tab" name="Table" directory="classes" int_links="0" style_classes="1" xsl="0" def_enabled="1" top_item="1" order_nr="200"/>
<pagecontent pc_type="td" name="TableData" directory="classes" int_links="0" style_classes="0" xsl="0" def_enabled="1" top_item="0" order_nr="0"/>
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -6354,6 +6354,7 @@ content#:#cont_ed_insert_grid#:#Spaltenlayout einfügen
content#:#cont_ed_insert_grid_info#:#Fügt ein responsives Spaltenlayout basierend auf einem Raster mit 12 Einheiten je Zeile ein.
content#:#cont_ed_insert_iim#:#Interaktives Bild einfügen
content#:#cont_ed_insert_incl#:#Inhaltsbaustein einfügen
content#:#cont_ed_insert_lay#:#Layoutvorlage einfügen
content#:#cont_ed_insert_lhist#:#Lernverlauf einfügen
content#:#cont_ed_insert_list#:#Erweiterte Liste einfügen
content#:#cont_ed_insert_lpe#:#Login-Seitenelement einfügen
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -6354,6 +6354,7 @@ content#:#cont_ed_insert_grid#:#Insert Column Layout
content#:#cont_ed_insert_grid_info#:#Adds a responsive column layout based on a grid with 12 units per row.
content#:#cont_ed_insert_iim#:#Insert Interactive Image
content#:#cont_ed_insert_incl#:#Insert Content Snippet
content#:#cont_ed_insert_lay#:#Insert Layout Template
content#:#cont_ed_insert_lhist#:#Insert Learning History
content#:#cont_ed_insert_list#:#Insert Advanced List
content#:#cont_ed_insert_lpe#:#Insert Login Page Element
Expand Down

0 comments on commit 02341ed

Please sign in to comment.