ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPCContentInclude.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPageContent.php");
5
18{
19 var $dom;
21
25 function init()
26 {
27 $this->setType("incl");
28 }
29
33 function setNode(&$a_node)
34 {
35 parent::setNode($a_node); // this is the PageContent node
36 $this->incl_node =& $a_node->first_child(); // this is the snippet node
37 }
38
45 function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
46 {
47 $this->node = $this->createPageContentNode();
48 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49 $this->incl_node =& $this->dom->create_element("ContentInclude");
50 $this->incl_node =& $this->node->append_child($this->incl_node);
51 }
52
56 function setContentId($a_id)
57 {
58 $this->setContentIncludeAttribute("ContentId", $a_id);
59 }
60
64 function getContentId()
65 {
66 return $this->getContentIncludeAttribute("ContentId");
67 }
68
72 function setContentType($a_type)
73 {
74 $this->setContentIncludeAttribute("ContentType", $a_type);
75 }
76
80 function getContentType()
81 {
82 return $this->getContentIncludeAttribute("ContentType");
83 }
84
88 function setInstId($a_id)
89 {
90 $this->setContentIncludeAttribute("InstId", $a_id);
91 }
92
96 function getInstId()
97 {
98 return $this->getContentIncludeAttribute("InstId");
99 }
100
107 protected function setContentIncludeAttribute($a_attr, $a_value)
108 {
109 if (!empty($a_value))
110 {
111 $this->incl_node->set_attribute($a_attr, $a_value);
112 }
113 else
114 {
115 if ($this->incl_node->has_attribute($a_attr))
116 {
117 $this->incl_node->remove_attribute($a_attr);
118 }
119 }
120 }
121
128 {
129 if (is_object($this->incl_node))
130 {
131 return $this->incl_node->get_attribute($a_attr);
132 }
133 }
134
143 static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
144 {
145 // pc content include
146 self::saveContentIncludeUsage($a_page, $a_domdoc);
147 }
148
154 static function beforePageDelete($a_page)
155 {
156 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
157 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType().":pg", $a_page->getId(), false, $a_page->getLanguage());
158 }
159
168 static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
169 {
170 self::saveContentIncludeUsage($a_page, $a_old_domdoc, $a_old_nr);
171 }
172
176 static function saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr = 0)
177 {
178 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
179 $ci_ids = self::collectContentIncludes($a_page, $a_domdoc);
180 ilPageContentUsage::deleteAllUsages("incl", $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr, $a_page->getLanguage());
181 foreach($ci_ids as $ci_id)
182 {
183 if ((int) $ci_id["inst_id"] <= 0 || $ci_id["inst_id"] == IL_INST_ID)
184 {
185 ilPageContentUsage::saveUsage("incl", $ci_id["id"], $a_page->getParentType().":pg", $a_page->getId(), $a_old_nr,
186 $a_page->getLanguage());
187 }
188 }
189 }
190
194 static function collectContentIncludes($a_page, $a_domdoc)
195 {
196 $xpath = new DOMXPath($a_domdoc);
197 $nodes = $xpath->query('//ContentInclude');
198
199 $ci_ids = array();
200 foreach ($nodes as $node)
201 {
202 $type = $node->getAttribute("ContentType");
203 $id = $node->getAttribute("ContentId");
204 $inst_id = $node->getAttribute("InstId");
205 $ci_ids[$type.":".$id.":".$inst_id] = array(
206 "type" => $type, "id" => $id, "inst_id" => $inst_id);
207 }
208
209 return $ci_ids;
210 }
211
212}
213
214?>
const IL_INSERT_AFTER
Class ilPCContentInclude.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create content include node in xml.
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
getContentIncludeAttribute($a_attr)
Get content include tag attribute.
setInstId($a_id)
Set installation id.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
setNode(&$a_node)
Set node.
static saveContentIncludeUsage($a_page, $a_domdoc, $a_old_nr=0)
save content include usages
setContentType($a_type)
Set content type.
static collectContentIncludes($a_page, $a_domdoc)
get all content includes that are used within the page
setContentIncludeAttribute($a_attr, $a_value)
Set attribute of content include tag.
static beforePageDelete($a_page)
Before page is being deleted.
getInstId()
Get installation id.
setContentId($a_id)
Set content id.
getContentType()
Get content type.
init()
Init page content component.
static saveUsage($a_pc_type, $a_pc_id, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Save usages.
static deleteAllUsages($a_pc_type, $a_usage_type, $a_usage_id, $a_usage_hist_nr=0, $a_lang="-")
Delete all usages.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.