Skip to content

Commit

Permalink
copage: dom/type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Oct 31, 2023
1 parent 0d6186c commit bd62f1e
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Services/COPage/DOM/class.DomUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public function deleteAllChildsByName(
public function deleteAllChilds(
\DOMNode $parent
): void {
foreach ($parent->childNodes as $child) {
$parent->removeChild($child);
while ($parent->hasChildNodes()) {
$parent->removeChild($parent->firstChild);
}
}

Expand Down
1 change: 0 additions & 1 deletion Services/COPage/PC/Paragraph/class.ilPCParagraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function setText(
$error = $this->checkTextArray($text);

$orig_characteristic = "";

// remove all childs
if (empty($error)) {
$t = $text[0]["text"] ?? "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ protected function insertCommand(array $body): Server\Response
$hier_id = $hier_ids[$body["after_pcid"]];
$pc_id = $body["after_pcid"];
}

$manual = ((string) ($body["form_input_1"] ?? "") === "manual");
$manual = ((string) ($body["form/input_0"] ?? "") === "manual");

$src = new \ilPCSourceCode($page);
$src->create($page, $hier_id, $pc_id);
Expand Down Expand Up @@ -113,7 +112,6 @@ protected function updateCommand(array $body): Server\Response
/** @var \ilPCSourceCode $pc_src */
$pc_src = $page->getContentObjectForPcId($body["pcid"]);
$src_gui = new \ilPCSourceCodeGUI($page, $pc_src, "", $body["pcid"]);

$form = $src_gui->getEditingFormAdapter();
if ($form->isValid()) {
$pc_src->setDownloadTitle(str_replace('"', '', $form->getData("title")));
Expand Down
3 changes: 2 additions & 1 deletion Services/COPage/PC/SourceCode/class.ilPCSourceCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function modifyPageContentPostXsl(
foreach ($nodes as $context_node) {
$char = $context_node->getAttribute('Characteristic');

if ($char != "Code") {
if ($char !== "Code") {
$i++;
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions Services/COPage/PC/SourceCode/class.ilPCSourceCodeGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public function edit(): void
$this->lng->txt("cont_pc_code")
)->withValue($par_content);
$t = $this->gui->ui()->renderer()->render($f);
$t = str_replace("<textarea ", "<textarea name='code' rows='20' form='copg-src-form' ", $t);

$t = str_replace("<textarea", "<textarea name='code' rows='20' form='copg-src-form' ", $t);
$this->tpl->setContent($t . $this->getEditorScriptTag($this->pc_id, "SourceCode"));
}

Expand Down
16 changes: 8 additions & 8 deletions Services/COPage/PC/Table/class.TableCommandActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,27 +382,27 @@ protected function setCellProperties(array $body): Server\Response
if (isset($body["style_cb"])) {
$class = $body["style"] ?? "";
if ($class === "") {
$td_node->remove_attribute("Class");
$td_node->removeAttribute("Class");
} else {
$td_node->set_attribute("Class", $class);
$td_node->setAttribute("Class", $class);
}
}
// set width
if (isset($body["width_cb"])) {
$width = $body["width"] ?? "";
if ($width === "") {
$td_node->remove_attribute("Width");
$td_node->removeAttribute("Width");
} else {
$td_node->set_attribute("Width", $width);
$td_node->setAttribute("Width", $width);
}
}
// set alignment
if (isset($body["al_cb"])) {
$alignment = $body["alignment"] ?? "";
if ($alignment === "") {
$td_node->remove_attribute("HorizontalAlign");
$td_node->removeAttribute("HorizontalAlign");
} else {
$td_node->set_attribute("HorizontalAlign", $alignment);
$td_node->setAttribute("HorizontalAlign", $alignment);
}
}

Expand All @@ -428,8 +428,8 @@ protected function toggleMerge(array $body): Server\Response
$right = (int) ($data["right"] ?? -1);

$td_node = $tab->getTableDataNode($top, $left);
$td_node->set_attribute("ColSpan", $right - $left + 1);
$td_node->set_attribute("RowSpan", $bottom - $top + 1);
$td_node->setAttribute("ColSpan", $right - $left + 1);
$td_node->setAttribute("RowSpan", $bottom - $top + 1);

$tab->fixHideAndSpans();

Expand Down
1 change: 0 additions & 1 deletion Services/COPage/PC/Table/class.ilPCDataTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ protected function getCellContent(int $i, int $j): string
true,
false
);
include_once("./Services/COPage/classes/class.ilPCParagraphGUI.php");
$s_text = ilPCParagraphGUI::xml2outputJS(
$s_text,
"TableContent",
Expand Down
9 changes: 4 additions & 5 deletions Services/COPage/PC/Table/class.ilPCTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,14 @@ public function getCellNode(int $i, int $j, bool $create_if_not_exists = false):
/**
* Get cell paragraph node of row $i and cell $j
*/
public function getTableDataNode(int $i, int $j): ?php4DOMElement
public function getTableDataNode(int $i, int $j): ?DOMElement
{
$xpc = xpath_new_context($this->dom);
$path = "//PageContent[@HierId='" . $this->getHierId() . "']" .
"/Table/TableRow[$i+1]/TableData[$j+1]";
$res = xpath_eval($xpc, $path);
$nodes = $this->dom_util->path($this->dom_doc, $path);

if (isset($res->nodeset[0])) {
return $res->nodeset[0];
if (count($nodes) > 0) {
return $nodes->item(0);
}
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions Services/COPage/PC/Table/class.ilPCTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,14 @@ public function getEditDataTable(bool $initial = false): string
"/Table/TableRow";
$nodes = $this->dom_util->path($this->dom, $path);
$i = 0;
$total_rows = count($nodes);
foreach ($nodes as $node) {
$path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" .
"/Table/TableRow[$i+1]/TableData";
$nodes2 = $this->dom_util->path($this->dom, $path2);
// if this is the first row -> col icons
if ($i == 0) {
$total_cols = count($nodes2);
$j = 0;
foreach ($nodes2 as $node2) {
if ($j == 0) {
Expand Down
19 changes: 9 additions & 10 deletions Services/COPage/PC/Tabs/class.ilPCTabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,21 @@ public function getCssFiles(string $a_mode): array

public function saveCaption(string $pc_id, string $caption): void
{
$tab_nodes = $this->tabs_node->child_nodes();
for ($i = 0; $i < count($tab_nodes); $i++) {
if ($tab_nodes[$i]->node_name() == "Tab") {
$current_pc_id = $tab_nodes[$i]->get_attribute("PCID");
$tab_nodes = $this->getChildNode()->childNodes;
foreach ($tab_nodes as $tab_node) {
if ($tab_node->nodeName === "Tab") {
$current_pc_id = $tab_node->getAttribute("PCID");
if ($current_pc_id === $pc_id) {
if ($caption !== "") {
ilDOMUtil::setFirstOptionalElement(
$this->dom,
$tab_nodes[$i],
$this->dom_util->setFirstOptionalElement(
$tab_node,
"TabCaption",
array(),
[],
$caption,
array()
[]
);
} else {
ilDOMUtil::deleteAllChildsByName($tab_nodes[$i], array("TabCaption"));
$this->dom_util->deleteAllChildsByName($tab_node, ["TabCaption"]);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Services/COPage/classes/class.ilPageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ public function getContentDomNode(string $a_hier_id, string $a_pc_id = ""): ?DOM
return $cm->getContentDomNode($a_hier_id, $a_pc_id);
}

public function getDomNodeForPCId(string $pc_id): ?DOMNode
{
return $this->getContentDomNode("", $pc_id);
}

/**
* set xml content of page, start with <PageObject...>,
* end with </PageObject>, comply with ILIAS DTD, omit MetaData, use utf-8!
Expand Down

0 comments on commit bd62f1e

Please sign in to comment.