forked from ILIAS-eLearning/ILIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Services/COPage/PC/LayoutTemplate/class.ilPCLayoutTemplate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
129
Services/COPage/PC/LayoutTemplate/class.ilPCLayoutTemplateGUI.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters