ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ParagraphManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected \ILIAS\Repository\HTTP\HTTPUtil $http_util;
29 protected \ILIAS\COPage\Dom\DomUtil $dom_util;
30
31 public function __construct()
32 {
33 global $DIC;
34 $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
35 $this->http_util = $DIC->copage()->internal()->gui()->httpUtil();
36 }
37
38 public function send(
39 \DOMDocument $dom,
40 string $par_id,
41 string $filename
42 ): void {
43 $content = "";
44 $path = "/descendant::Paragraph[position() = $par_id]";
45 $nodes = $this->dom_util->path(
46 $dom,
47 $path
48 );
49 if (count($nodes) != 1) {
50 throw new \ilCOPageException("Paragraph not found.");
51 }
52
53 $context_node = $nodes->item(0);
54 foreach ($context_node->childNodes as $child) {
55 $content .= $this->dom_util->dump($child);
56 }
57
58 $content = str_replace("<br />", "\n", $content);
59 $content = str_replace("<br/>", "\n", $content);
60
61 $plain_content = html_entity_decode($content);
62
63 $this->http_util->deliverString($plain_content, $filename);
64 }
65
66 public function getFirstParagraphText(\ilPageObject $page): string
67 {
68 $dom = $page->getDomDoc();
69 if ($dom) {
70 $path = "//Paragraph[1]";
71 $nodes = $this->dom_util->path($dom, $path);
72 if (count($nodes) > 0) {
73 $cont_node = $nodes->item(0)->parentNode;
74 $par = new \ilPCParagraph($page);
75 $par->setDomNode($cont_node);
76 $text = $par->getText();
77 return $text;
78 }
79 }
80 return "";
81 }
82
83 public function getParagraphForPCID(\ilPageObject $page, string $pcid): ?\ilPCParagraph
84 {
85 $dom = $page->getDomDoc();
86 if ($dom) {
87 $path = "//PageContent[@PCID='" . $pcid . "']/Paragraph[1]";
88 $nodes = $this->dom_util->path($dom, $path);
89 if (count($nodes) > 0) {
90 $cont_node = $nodes->item(0)->parentNode;
91 $par = new \ilPCParagraph($page);
92 $par->setDomNode($cont_node);
93 return $par;
94 }
95 }
96 return null;
97 }
98}
$filename
Definition: buildRTE.php:78
getParagraphForPCID(\ilPageObject $page, string $pcid)
send(\DOMDocument $dom, string $par_id, string $filename)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getDomDoc()
Get dom doc (DOMDocument)
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26