ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.PCFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\COPage\PC;
22
24
29{
30 protected ?\ilLogger $log;
32
34 {
35 global $DIC;
36
37 $this->pc_definition = $pc_definition;
38 $this->log = $DIC->copage()->internal()->domain()->log();
39 }
40
41 public function getByNode(
42 ?\DOMNode $node,
43 \ilPageObject $page_object
44 ): ?\ilPageContent {
45 if (is_null($node)) {
46 return null;
47 }
48 $a_hier_id = $node->getAttribute("HierId");
49 $a_pc_id = $node->getAttribute("PCID");
50 $child_node = null;
51 if (!is_object($node)) {
52 $this->log->debug("No node passed.");
53 return null;
54 }
55 $node_name = $node->nodeName;
56 if (in_array($node_name, ["PageObject", "TableRow"])) {
57 $this->log->debug("$node_name -> return.");
58 return null;
59 }
60 if ($node_name == "PageContent") {
61 $child_node = $node->firstChild;
62 $node_name = $child_node->nodeName;
63 }
64
65 // table extra handling (@todo: get rid of it)
66 if ($node_name == "Table") {
67 if ($child_node->getAttribute("DataTable") == "y") {
68 $tab = new \ilPCDataTable($page_object);
69 } else {
70 $tab = new \ilPCTable($page_object);
71 }
72 $tab->setDomNode($node);
73 $tab->setHierId($a_hier_id);
74 $tab->setPcId($a_pc_id);
75 $this->log->debug("return table.");
76 return $tab;
77 }
78
79 // media extra handling (@todo: get rid of it)
80 if ($node_name == "MediaObject") {
81 $mal_node = $child_node->firstChild;
82 //echo "ilPageObject::getContentObject:nodename:".$mal_node->node_name().":<br>";
83 $id_arr = explode("_", $mal_node->getAttribute("OriginId"));
84 $mob_id = (int) $id_arr[count($id_arr) - 1];
85
86 // see also #32331
87 if (\ilObject::_lookupType($mob_id) !== "mob") {
88 $mob_id = 0;
89 }
90
91 //$mob = new ilObjMediaObject($mob_id);
92 $mob = new \ilPCMediaObject($page_object);
93 $mob->readMediaObject($mob_id);
94
95 //$mob->setDom($this->dom);
96 $mob->setDomNode($node);
97 $mob->setHierId($a_hier_id);
98 $mob->setPcId($a_pc_id);
99 $this->log->debug("return media.");
100 return $mob;
101 }
102
103 //
104 // generic procedure
105 //
106
107 $pc_def = $this->pc_definition->getPCDefinitionByName($node_name);
108
109 // check if pc definition has been found
110 if (!is_array($pc_def)) {
111 throw new \ilCOPageUnknownPCTypeException('Unknown PC Name "' . $node_name . '".');
112 }
113 $pc_class = "ilPC" . $pc_def["name"];
114 $pc_path = "./" . $pc_def["component"] . "/" . $pc_def["directory"] . "/class." . $pc_class . ".php";
115 //require_once($pc_path);
116 $pc = new ("\\" . $pc_class)($page_object);
117 if (!in_array(
118 $node->nodeName,
119 ["PageContent", "TableData", "FileItem", "ListItem"]
120 )) {
121 $this->log->debug("returning null.");
122 return null;
123 }
124 $pc->setDomNode($node);
125 $pc->setHierId($a_hier_id);
126 $pc->setPcId($a_pc_id);
127 //$this->log->debug("returning $pc_class.");
128 return $pc;
129 }
130}
__construct(PCDefinition $pc_definition)
getByNode(?\DOMNode $node, \ilPageObject $page_object)
Component logger with individual log levels by component id.
static _lookupType(int $id, bool $reference=false)
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26