ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPCResources.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPageContent.php");
5 
18 {
19  public $dom;
20  public $res_node;
21 
25  public function init()
26  {
27  $this->setType("repobj");
28  }
29 
33  public function setNode($a_node)
34  {
35  parent::setNode($a_node); // this is the PageContent node
36  $this->res_node = $a_node->first_child(); // this is the Resources node
37  }
38 
45  public 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->res_node = $this->dom->create_element("Resources");
50  $this->res_node = $this->node->append_child($this->res_node);
51  }
52 
58  public function setResourceListType($a_type)
59  {
60  if (!empty($a_type)) {
61  $children = $this->res_node->child_nodes();
62  for ($i=0; $i<count($children); $i++) {
63  $this->res_node->remove_child($children[$i]);
64  }
65  $list_node = $this->dom->create_element("ResourceList");
66  $list_node = $this->res_node->append_child($list_node);
67  $list_node->set_attribute("Type", $a_type);
68  }
69  }
70 
76  public function setItemGroupRefId($a_ref_id)
77  {
78  if (!empty($a_ref_id)) {
79  $children = $this->res_node->child_nodes();
80  for ($i=0; $i<count($children); $i++) {
81  $this->res_node->remove_child($children[$i]);
82  }
83  $list_node = $this->dom->create_element("ItemGroup");
84  $list_node = $this->res_node->append_child($list_node);
85  $list_node->set_attribute("RefId", $a_ref_id);
86  }
87  }
88 
94  public function getResourceListType()
95  {
96  if (is_object($this->res_node)) {
97  $children = $this->res_node->child_nodes();
98  if (is_object($children[0]) && $children[0]->node_name() == "ResourceList") {
99  return $children[0]->get_attribute("Type");
100  }
101  }
102  return false;
103  }
104 
110  public function getItemGroupRefId()
111  {
112  if (is_object($this->res_node)) {
113  $children = $this->res_node->child_nodes();
114  if (is_object($children[0]) && $children[0]->node_name() == "ItemGroup") {
115  return (int) $children[0]->get_attribute("RefId");
116  }
117  }
118  return false;
119  }
120 
126  public function getMainType()
127  {
128  if (is_object($this->res_node)) {
129  $children = $this->res_node->child_nodes();
130  if (is_object($children[0])) {
131  return $children[0]->node_name();
132  }
133  }
134  return false;
135  }
136 
143  public static function modifyItemGroupRefIdsByMapping($a_page, $mappings)
144  {
145  $dom = $a_page->getDom();
146 
147  if ($dom instanceof php4DOMDocument) {
148  $dom = $dom->myDOMDocument;
149  }
150 
151  $xpath_temp = new DOMXPath($dom);
152  $igs = $xpath_temp->query("//Resources/ItemGroup");
153 
154  $updated = false;
155  foreach ($igs as $ig_node) {
156  $ref_id = $ig_node->getAttribute("RefId");
157  if ($mappings[$ref_id] > 0) {
158  $ig_node->setAttribute("RefId", $mappings[$ref_id]);
159  $updated = true;
160  }
161  }
162  return $updated;
163  }
164 
169  public static function getLangVars()
170  {
171  return array("pc_res");
172  }
173 
179  public static function resolveResources(ilPageObject $page, $ref_mappings)
180  {
181  return self::modifyItemGroupRefIdsByMapping($page, $ref_mappings);
182  }
183 }
init()
Init page content component.
static modifyItemGroupRefIdsByMapping($a_page, $mappings)
Modify ref ids by mapping.
setType($a_type)
Set Type.
getResourceListType()
Get Resource Lis Type.
Class ilPageContent.
getMainType()
Get main type.
$a_type
Definition: workflow.php:92
static getLangVars()
Get lang vars needed for editing.
setNode($a_node)
Set node.
Class ilPageObject.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create resources node in xml.
setResourceListType($a_type)
Set Type of Resource List (currently only one)
setItemGroupRefId($a_ref_id)
Set Item Group Ref Id.
const IL_INSERT_AFTER
Class ilPCResources.
Create styles array
The data for the language used.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getItemGroupRefId()
Get item group ref id.
$i
Definition: disco.tpl.php:19
static resolveResources(ilPageObject $page, $ref_mappings)
Resolve resources.