ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\COPage\Compare\PageCompare Class Reference
+ Collaboration diagram for ILIAS\COPage\Compare\PageCompare:

Public Member Functions

 __construct ()
 
 compare (\ilPageObject $main_page, \ilPageObject $l_page, \ilPageObject $r_page,)
 

Protected Member Functions

 setParagraphContent (\ilPageObject $page, string $a_hier_id, string $content)
 
 addChangeDivClasses (\ilPageObject $page, array $a_hashes)
 
 getPageContentsHashes (\ilPageObject $page)
 Get page contents hashes. More...
 

Protected Attributes

DomUtil $dom_util
 

Detailed Description

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 28 of file class.PageCompare.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\COPage\Compare\PageCompare::__construct ( )

Definition at line 32 of file class.PageCompare.php.

References $DIC.

33  {
34  global $DIC;
35 
36  $this->dom_util = $DIC->copage()
37  ->internal()
38  ->domain()
39  ->domUtil();
40  }
global $DIC
Definition: shib_login.php:26

Member Function Documentation

◆ addChangeDivClasses()

ILIAS\COPage\Compare\PageCompare::addChangeDivClasses ( \ilPageObject  $page,
array  $a_hashes 
)
protected

Definition at line 105 of file class.PageCompare.php.

References $path, and ilPageObject\getDomDoc().

Referenced by ILIAS\COPage\Compare\PageCompare\compare().

108  : void {
109  $dom = $page->getDomDoc();
110  $path = "/*[1]";
111  $nodes = $this->dom_util->path($dom, $path);
112  $rnode = $nodes->item(0);
113  foreach ($a_hashes as $h) {
114  if (($h["change"] ?? "") != "") {
115  $dc_node = $dom->createElement("DivClass");
116  $dc_node->setAttribute("HierId", $h["hier_id"]);
117  $dc_node->setAttribute("Class", "ilEdit" . $h["change"]);
118  $dc_node = $rnode->appendChild($dc_node);
119  }
120  }
121  }
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compare()

ILIAS\COPage\Compare\PageCompare::compare ( \ilPageObject  $main_page,
\ilPageObject  $l_page,
\ilPageObject  $r_page 
)

Definition at line 42 of file class.PageCompare.php.

References ILIAS\COPage\Compare\PageCompare\addChangeDivClasses(), ILIAS\COPage\Compare\PageCompare\getPageContentsHashes(), ilPageObject\preparePageForCompare(), and ILIAS\COPage\Compare\PageCompare\setParagraphContent().

46  : array {
47  $main_page->preparePageForCompare($l_page);
48  $main_page->preparePageForCompare($r_page);
49  $l_hashes = $this->getPageContentsHashes($l_page);
50  $r_hashes = $this->getPageContentsHashes($r_page);
51  // determine all deleted and changed page elements
52  foreach ($l_hashes as $pc_id => $h) {
53  if (!isset($r_hashes[$pc_id])) {
54  $l_hashes[$pc_id]["change"] = "Deleted";
55  } else {
56  if ($h["hash"] != $r_hashes[$pc_id]["hash"]) {
57  $l_hashes[$pc_id]["change"] = "Modified";
58  $r_hashes[$pc_id]["change"] = "Modified";
59 
60  // if modified element is a paragraph, highlight changes
61  if ($l_hashes[$pc_id]["content"] != "" &&
62  $r_hashes[$pc_id]["content"] != "") {
63  $new_left = str_replace("\n", "<br />", $l_hashes[$pc_id]["content"]);
64  $new_right = str_replace("\n", "<br />", $r_hashes[$pc_id]["content"]);
65  $wldiff = new \WordLevelDiff(
66  array($new_left),
67  array($new_right)
68  );
69  $new_left = $wldiff->orig();
70  $new_right = $wldiff->closing();
71  $this->setParagraphContent($l_page, $l_hashes[$pc_id]["hier_id"], $new_left[0]);
72  $this->setParagraphContent($r_page, $l_hashes[$pc_id]["hier_id"], $new_right[0]);
73  }
74  }
75  }
76  }
77 
78  // determine all new paragraphs
79  foreach ($r_hashes as $pc_id => $h) {
80  if (!isset($l_hashes[$pc_id])) {
81  $r_hashes[$pc_id]["change"] = "New";
82  }
83  }
84  $this->addChangeDivClasses($l_page, $l_hashes);
85  $this->addChangeDivClasses($r_page, $r_hashes);
86 
87  return array("l_page" => $l_page,
88  "r_page" => $r_page,
89  "l_changes" => $l_hashes,
90  "r_changes" => $r_hashes
91  );
92  }
setParagraphContent(\ilPageObject $page, string $a_hier_id, string $content)
addChangeDivClasses(\ilPageObject $page, array $a_hashes)
getPageContentsHashes(\ilPageObject $page)
Get page contents hashes.
+ Here is the call graph for this function:

◆ getPageContentsHashes()

ILIAS\COPage\Compare\PageCompare::getPageContentsHashes ( \ilPageObject  $page)
protected

Get page contents hashes.

Definition at line 127 of file class.PageCompare.php.

References $path, ilPageObject\addHierIDs(), ilPageObject\buildDom(), ilPageObject\getDomDoc(), and ilPCParagraph\xml2output().

Referenced by ILIAS\COPage\Compare\PageCompare\compare().

127  : array
128  {
129  $page->buildDom();
130  $page->addHierIDs();
131  $dom = $page->getDomDoc();
132 
133  // get existing ids
134  $path = "//PageContent";
135  $hashes = array();
136  $nodes = $this->dom_util->path($dom, $path);
137  foreach ($nodes as $node) {
138  $hier_id = $node->getAttribute("HierId");
139  $pc_id = $node->getAttribute("PCID");
140  $dump = $this->dom_util->dump($node);
141  if (($hpos = strpos($dump, ' HierId="' . $hier_id . '"')) > 0) {
142  $dump = substr($dump, 0, $hpos) .
143  substr($dump, $hpos + strlen(' HierId="' . $hier_id . '"'));
144  }
145 
146  $childs = $node->childNodes;
147  $content = "";
148  if ($childs->item(0) && $childs->item(0)->nodeName == "Paragraph") {
149  $content = $this->dom_util->dump($childs->item(0));
150  $content = substr(
151  $content,
152  strpos($content, ">") + 1,
153  strrpos($content, "<") - (strpos($content, ">") + 1)
154  );
155  $content = \ilPCParagraph::xml2output($content);
156  }
157  $hashes[$pc_id] =
158  array("hier_id" => $hier_id, "hash" => md5($dump), "content" => $content);
159  }
160 
161  return $hashes;
162  }
static xml2output(string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
Converts xml from DB to output in edit textarea.
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParagraphContent()

ILIAS\COPage\Compare\PageCompare::setParagraphContent ( \ilPageObject  $page,
string  $a_hier_id,
string  $content 
)
protected

Definition at line 94 of file class.PageCompare.php.

References ilPageObject\getContentDomNode().

Referenced by ILIAS\COPage\Compare\PageCompare\compare().

98  : void {
99  $node = $page->getContentDomNode($a_hier_id);
100  if (is_object($node)) {
101  $this->dom_util->setContent($node, $content);
102  }
103  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $dom_util

DomUtil ILIAS\COPage\Compare\PageCompare::$dom_util
protected

Definition at line 30 of file class.PageCompare.php.


The documentation for this class was generated from the following file: