ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\COPage\ID\ContentIdManager Class Reference
+ Collaboration diagram for ILIAS\COPage\ID\ContentIdManager:

Public Member Functions

 __construct (\ilPageObject $page, ?ContentIdGeneratorInterface $generator=null)
 
 addHierIDsToDom ()
 Add hierarchical ID (e.g. More...
 
 getHierIds ()
 get all hierarchical ids More...
 
 stripHierIDsFromDom ()
 
 generatePCId ()
 
 insertPCIds ()
 
 getDuplicatePCIds ()
 
 hasDuplicatePCIds ()
 
 stripPCIDs ()
 
 checkPCIds ()
 
 getAllPCIds ()
 
 getHierIdsForPCIds (array $a_pc_ids)
 
 getHierIdForPcId (string $pcid)
 
 getPCIdsForHierIds (array $hier_ids)
 
 getPCIdForHierId (string $hier_id)
 

Protected Member Functions

 incEdId (string $ed_id)
 Increases an hierarchical editing id at lowest level (last number) More...
 
 decEdId (string $ed_id)
 Decreases an hierarchical editing id at lowest level (last number) More...
 

Protected Attributes

const ID_ELEMENTS
 
array $hier_ids = []
 
ilPageObject $page
 
DomUtil $dom_util
 
ContentIdGenerator $generator
 

Detailed Description

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

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

Constructor & Destructor Documentation

◆ __construct()

ILIAS\COPage\ID\ContentIdManager::__construct ( \ilPageObject  $page,
?ContentIdGeneratorInterface  $generator = null 
)

Definition at line 46 of file class.ContentIdManager.php.

References $DIC, and ILIAS\COPage\ID\ContentIdManager\$page.

49  {
50  global $DIC;
51 
52  $this->dom_util = $DIC->copage()
53  ->internal()
54  ->domain()
55  ->domUtil();
56  $this->page = $page;
57  $this->generator = $generator ?? $DIC->copage()
58  ->internal()
59  ->domain()
60  ->contentIdGenerator();
61  }
global $DIC
Definition: shib_login.php:26

Member Function Documentation

◆ addHierIDsToDom()

ILIAS\COPage\ID\ContentIdManager::addHierIDsToDom ( )

Add hierarchical ID (e.g.

for editing) attributes "HierId" to current dom tree. This attribute will be added to the following elements: PageObject, Paragraph, Table, TableRow, TableData. Only elements of these types are counted as "childs" here. Hierarchical IDs have the format "x_y_z_...", e.g. "1_4_2" means: second child of fourth child of first child of page. The PageObject element gets the special id "pg". The first child of the page starts with id 1. The next child gets the 2 and so on. Another example: The first child of the page is a Paragraph -> id 1. The second child is a table -> id 2. The first row gets the id 2_1, the

Definition at line 75 of file class.ContentIdManager.php.

References $path, and ILIAS\COPage\ID\ContentIdManager\incEdId().

75  : void
76  {
77  $this->hier_ids = [];
78  $dom = $this->page->getDomDoc();
79 
80  $sep = $path = "";
81  foreach (self::ID_ELEMENTS as $el) {
82  $path .= $sep . "//" . $el;
83  $sep = " | ";
84  }
85 
86  $nodes = $this->dom_util->path($dom, $path);
87 
88  foreach ($nodes as $node) {
89  $cnode = $node;
90  $ctag = $cnode->nodeName;
91 
92  // get hierarchical id of previous sibling
93  $sib_hier_id = "";
94  while ($cnode = $cnode->previousSibling) {
95  if (($cnode->nodeType == XML_ELEMENT_NODE)
96  && $cnode->hasAttribute("HierId")) {
97  $sib_hier_id = $cnode->getAttribute("HierId");
98  break;
99  }
100  }
101 
102  if ($sib_hier_id != "") { // set id to sibling id "+ 1"
103  $node_hier_id = $this->incEdId($sib_hier_id);
104  $node->setAttribute("HierId", $node_hier_id);
105  $this->hier_ids[] = $node_hier_id;
106  } else { // no sibling -> node is first child
107  // get hierarchical id of next parent
108  $cnode = $node;
109  $par_hier_id = "";
110  while ($cnode = $cnode->parentNode) {
111  if (($cnode->nodeType == XML_ELEMENT_NODE)
112  && $cnode->hasAttribute("HierId")) {
113  $par_hier_id = $cnode->getAttribute("HierId");
114  break;
115  }
116  }
117  if (($par_hier_id != "") && ($par_hier_id != "pg")) { // set id to parent_id."_1"
118  $node_hier_id = $par_hier_id . "_1";
119  $node->setAttribute("HierId", $node_hier_id);
120  $this->hier_ids[] = $node_hier_id;
121  } else { // no sibling, no parent -> first node
122  $node_hier_id = "1";
123  $node->setAttribute("HierId", $node_hier_id);
124  $this->hier_ids[] = $node_hier_id;
125  }
126  }
127  }
128 
129  // set special hierarchical id "pg" for pageobject
130  $path = "//PageObject";
131  $nodes = $this->dom_util->path($dom, $path);
132  foreach ($nodes as $node) {
133  $node->setAttribute("HierId", "pg");
134  $this->hier_ids[] = "pg";
135  }
136  }
$path
Definition: ltiservices.php:29
incEdId(string $ed_id)
Increases an hierarchical editing id at lowest level (last number)
+ Here is the call graph for this function:

◆ checkPCIds()

ILIAS\COPage\ID\ContentIdManager::checkPCIds ( )

Definition at line 260 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\$page, $path, and ilPageObject\buildDom().

260  : bool
261  {
262  $page = $this->page;
263  $page->buildDom();
264  $dom = $page->getDomDoc();
265 
266  $sep = $path = "";
267  foreach (self::ID_ELEMENTS as $el) {
268  $path .= $sep . "//" . $el . "[not(@PCID)]";
269  $sep = " | ";
270  $path .= $sep . "//" . $el . "[@PCID='']";
271  }
272  $nodes = $this->dom_util->path($dom, $path);
273  if (count($nodes) > 0) {
274  return false;
275  }
276  return true;
277  }
buildDom(bool $a_force=false)
getDomDoc()
Get dom doc (DOMDocument)
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:

◆ decEdId()

ILIAS\COPage\ID\ContentIdManager::decEdId ( string  $ed_id)
protected

Decreases an hierarchical editing id at lowest level (last number)

Parameters
string$ed_idhierarchical ID
Returns
string hierarchical ID (decreased)

Definition at line 180 of file class.ContentIdManager.php.

References $id.

180  : string
181  {
182  $id = explode("_", $ed_id);
183  $id[count($id) - 1]--;
184  return implode("_", $id);
185  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ generatePCId()

ILIAS\COPage\ID\ContentIdManager::generatePCId ( )

Definition at line 187 of file class.ContentIdManager.php.

Referenced by ILIAS\COPage\ID\ContentIdManager\insertPCIds().

187  : string
188  {
189  return $this->generator->generate();
190  }
+ Here is the caller graph for this function:

◆ getAllPCIds()

ILIAS\COPage\ID\ContentIdManager::getAllPCIds ( )

Definition at line 279 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\$page, $path, and ilPageObject\buildDom().

279  : array
280  {
281  $page = $this->page;
282  $page->buildDom();
283  $dom = $page->getDomDoc();
284 
285  $pcids = array();
286 
287  $sep = $path = "";
288  foreach (self::ID_ELEMENTS as $el) {
289  $path .= $sep . "//" . $el . "[@PCID]";
290  $sep = " | ";
291  }
292 
293  // get existing ids
294  $nodes = $this->dom_util->path($dom, $path);
295  foreach ($nodes as $node) {
296  $pcids[] = $node->getAttribute("PCID");
297  }
298  return $pcids;
299  }
buildDom(bool $a_force=false)
getDomDoc()
Get dom doc (DOMDocument)
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:

◆ getDuplicatePCIds()

ILIAS\COPage\ID\ContentIdManager::getDuplicatePCIds ( )

Definition at line 212 of file class.ContentIdManager.php.

References $path.

Referenced by ILIAS\COPage\ID\ContentIdManager\hasDuplicatePCIds().

212  : array
213  {
214  $this->page->buildDom();
215  $dom = $this->page->getDomDoc();
216 
217  $pcids = [];
218  $duplicates = [];
219 
220  $sep = $path = "";
221  foreach (self::ID_ELEMENTS as $el) {
222  $path .= $sep . "//" . $el . "[@PCID]";
223  $sep = " | ";
224  }
225 
226  // get existing ids
227  $nodes = $this->dom_util->path($dom, $path);
228  foreach ($nodes as $node) {
229  $pc_id = $node->getAttribute("PCID");
230  if ($pc_id != "") {
231  if (isset($pcids[$pc_id])) {
232  $duplicates[] = $pc_id;
233  }
234  $pcids[$pc_id] = $pc_id;
235  }
236  }
237  return $duplicates;
238  }
$path
Definition: ltiservices.php:29
+ Here is the caller graph for this function:

◆ getHierIdForPcId()

ILIAS\COPage\ID\ContentIdManager::getHierIdForPcId ( string  $pcid)

Definition at line 323 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\getHierIdsForPCIds().

323  : string
324  {
325  $hier_ids = $this->getHierIdsForPCIds([$pcid]);
326  return $hier_ids[$pcid] ?? "";
327  }
+ Here is the call graph for this function:

◆ getHierIds()

ILIAS\COPage\ID\ContentIdManager::getHierIds ( )

get all hierarchical ids

Definition at line 141 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\$hier_ids.

141  : array
142  {
143  return $this->hier_ids;
144  }

◆ getHierIdsForPCIds()

ILIAS\COPage\ID\ContentIdManager::getHierIdsForPCIds ( array  $a_pc_ids)

Definition at line 302 of file class.ContentIdManager.php.

References $path.

Referenced by ILIAS\COPage\ID\ContentIdManager\getHierIdForPcId().

302  : array
303  {
304  if (!is_array($a_pc_ids) || count($a_pc_ids) == 0) {
305  return array();
306  }
307  $ret = array();
308 
309  $dom = $this->page->getDomDoc();
310  if (is_object($dom)) {
311  $path = "//*[@PCID]";
312  $nodes = $this->dom_util->path($dom, $path);
313  foreach ($nodes as $node) {
314  $pc_id = $node->getAttribute("PCID");
315  if (in_array($pc_id, $a_pc_ids)) {
316  $ret[$pc_id] = $node->getAttribute("HierId");
317  }
318  }
319  }
320  return $ret;
321  }
$path
Definition: ltiservices.php:29
+ Here is the caller graph for this function:

◆ getPCIdForHierId()

ILIAS\COPage\ID\ContentIdManager::getPCIdForHierId ( string  $hier_id)

Definition at line 351 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\getPCIdsForHierIds().

351  : string
352  {
353  $hier_ids = $this->getPCIdsForHierIds([$hier_id]);
354  return ($hier_ids[$hier_id] ?? "");
355  }
+ Here is the call graph for this function:

◆ getPCIdsForHierIds()

ILIAS\COPage\ID\ContentIdManager::getPCIdsForHierIds ( array  $hier_ids)

Definition at line 329 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\$page, $path, and ilPageObject\getDomDoc().

Referenced by ILIAS\COPage\ID\ContentIdManager\getPCIdForHierId().

329  : array
330  {
331  $page = $this->page;
332  $dom = $page->getDomDoc();
333  if (!is_array($hier_ids) || count($hier_ids) == 0) {
334  return [];
335  }
336  $ret = [];
337  if (is_object($dom)) {
338  $page->addHierIDs();
339  $path = "//*[@HierId]";
340  $nodes = $this->dom_util->path($dom, $path);
341  foreach ($nodes as $node) {
342  $hier_id = $node->getAttribute("HierId");
343  if (in_array($hier_id, $hier_ids)) {
344  $ret[$hier_id] = $node->getAttribute("PCID");
345  }
346  }
347  }
348  return $ret;
349  }
getDomDoc()
Get dom doc (DOMDocument)
$path
Definition: ltiservices.php:29
addHierIDs()
Add hierarchical ID (e.g.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasDuplicatePCIds()

ILIAS\COPage\ID\ContentIdManager::hasDuplicatePCIds ( )

Definition at line 240 of file class.ContentIdManager.php.

References ILIAS\COPage\ID\ContentIdManager\getDuplicatePCIds().

240  : bool
241  {
242  $duplicates = $this->getDuplicatePCIds();
243  return count($duplicates) > 0;
244  }
+ Here is the call graph for this function:

◆ incEdId()

ILIAS\COPage\ID\ContentIdManager::incEdId ( string  $ed_id)
protected

Increases an hierarchical editing id at lowest level (last number)

Parameters
string$ed_idhierarchical ID
Returns
string hierarchical ID (increased)

Definition at line 168 of file class.ContentIdManager.php.

References $id.

Referenced by ILIAS\COPage\ID\ContentIdManager\addHierIDsToDom().

168  : string
169  {
170  $id = explode("_", $ed_id);
171  $id[count($id) - 1]++;
172  return implode("_", $id);
173  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ insertPCIds()

ILIAS\COPage\ID\ContentIdManager::insertPCIds ( )

Definition at line 192 of file class.ContentIdManager.php.

References $id, $path, and ILIAS\COPage\ID\ContentIdManager\generatePCId().

192  : void
193  {
194  $this->page->buildDom();
195  $dom = $this->page->getDomDoc();
196 
197  // add missing ones
198  $sep = $path = "";
199  foreach (self::ID_ELEMENTS as $el) {
200  $path .= $sep . "//" . $el . "[not(@PCID)]";
201  $sep = " | ";
202  $path .= $sep . "//" . $el . "[@PCID='']";
203  $sep = " | ";
204  }
205  $nodes = $this->dom_util->path($dom, $path);
206  foreach ($nodes as $node) {
207  $id = $this->generatePCId();
208  $node->setAttribute("PCID", $id);
209  }
210  }
$path
Definition: ltiservices.php:29
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ stripHierIDsFromDom()

ILIAS\COPage\ID\ContentIdManager::stripHierIDsFromDom ( )

Definition at line 146 of file class.ContentIdManager.php.

References $path.

146  : void
147  {
148  $this->hier_ids = [];
149  $dom = $this->page->getDomDoc();
150 
151  if (is_object($dom)) {
152  $path = "//*[@HierId]";
153  $nodes = $this->dom_util->path($dom, $path);
154  foreach ($nodes as $node) {
155  if ($node->hasAttribute("HierId")) {
156  $node->removeAttribute("HierId");
157  }
158  }
159  }
160  }
$path
Definition: ltiservices.php:29

◆ stripPCIDs()

ILIAS\COPage\ID\ContentIdManager::stripPCIDs ( )

Definition at line 246 of file class.ContentIdManager.php.

References $path.

246  : void
247  {
248  $dom = $this->page->getDomDoc();
249  if (is_object($dom)) {
250  $path = "//*[@PCID]";
251  $nodes = $this->dom_util->path($dom, $path);
252  foreach ($nodes as $node) {
253  if ($node->hasAttribute("PCID")) {
254  $node->removeAttribute("PCID");
255  }
256  }
257  }
258  }
$path
Definition: ltiservices.php:29

Field Documentation

◆ $dom_util

DomUtil ILIAS\COPage\ID\ContentIdManager::$dom_util
protected

Definition at line 43 of file class.ContentIdManager.php.

◆ $generator

ContentIdGenerator ILIAS\COPage\ID\ContentIdManager::$generator
protected

Definition at line 44 of file class.ContentIdManager.php.

◆ $hier_ids

array ILIAS\COPage\ID\ContentIdManager::$hier_ids = []
protected

◆ $page

◆ ID_ELEMENTS

const ILIAS\COPage\ID\ContentIdManager::ID_ELEMENTS
protected
Initial value:
=
["PageContent",
"TableRow",
"TableData",
"ListItem",
"FileItem",
"Section",
"Tab",
"ContentPopup",
"GridCell"]

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


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