ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPCResourcesGUI.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.ilPCResources.php");
5 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
6 
18 {
22  protected $rep_tree;
23 
27  protected $obj_definition;
28 
29 
34  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
35  {
36  global $DIC;
37 
38  $this->ctrl = $DIC->ctrl();
39  $this->tpl = $DIC["tpl"];
40  $this->lng = $DIC->language();
41  $this->obj_definition = $DIC["objDefinition"];
42  $tree = $DIC->repositoryTree();
43 
44  $this->rep_tree = $tree;
45  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
46  }
47 
51  public function executeCommand()
52  {
53  // get next class that processes or forwards current command
54  $next_class = $this->ctrl->getNextClass($this);
55 
56  // get current command
57  $cmd = $this->ctrl->getCmd();
58 
59  switch ($next_class) {
60  default:
61  $ret = $this->$cmd();
62  break;
63  }
64 
65  return $ret;
66  }
67 
71  public function insert()
72  {
73  $this->edit(true);
74  }
75 
79  public function edit($a_insert = false)
80  {
82  $tpl = $this->tpl;
83  $lng = $this->lng;
84  $objDefinition = $this->obj_definition;
85 
86  $this->displayValidationError();
87 
88  // edit form
89  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
90  $form = new ilPropertyFormGUI();
91  $form->setFormAction($ilCtrl->getFormAction($this));
92  if ($a_insert) {
93  $form->setTitle($this->lng->txt("cont_insert_resources"));
94  } else {
95  $form->setTitle($this->lng->txt("cont_update_resources"));
96  }
97 
98  // count number of existing objects per type and collect item groups
99  $ref_id = (int) $_GET["ref_id"];
100  $childs = $this->rep_tree->getChilds($ref_id);
101  $type_counts = array();
102  $item_groups = array();
103  foreach ($childs as $c) {
104  // see bug #12471
105  //echo "<br>-".$c["type"]."-".$objDefinition->getGroupOfObj($c["type"])."-";
106  $key = ($objDefinition->getGroupOfObj($c["type"]) != "")
107  ? $objDefinition->getGroupOfObj($c["type"])
108  : $c["type"];
109  $type_counts[$key] += 1;
110  if ($c["type"] == "itgr") {
111  $item_groups[$c["ref_id"]] = $c["title"];
112  }
113  }
114 
115  if (count($item_groups) > 0) {
116  // radio group for type selection
117  $radg = new ilRadioGroupInputGUI($lng->txt("cont_resources"), "res_type");
118  if (!$a_insert && $this->content_obj->getMainType() == "ItemGroup") {
119  $radg->setValue("itgr");
120  } else {
121  $radg->setValue("by_type");
122  }
123 
124  $op_type = new ilRadioOption($lng->txt("cont_resources_of_type"), "by_type", "");
125  $radg->addOption($op_type);
126  $op_itemgroup = new ilRadioOption($lng->txt("obj_itgr"), "itgr", "");
127  $radg->addOption($op_itemgroup);
128  $form->addItem($radg);
129  }
130 
131  // type selection
132  $type_prop = new ilSelectInputGUI(
133  $this->lng->txt("cont_type"),
134  "type"
135  );
136  $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
137  $obj_type = ilObject::_lookupType($obj_id);
138  $sub_objs = $objDefinition->getGroupedRepositoryObjectTypes($obj_type);
139  $types = array();
140  foreach ($sub_objs as $k => $so) {
141  if (!$objDefinition->isPlugin($k)) {
142  if ($k != "itgr") {
143  $types[$k] = $this->lng->txt("objs_" . $k) . " (" . (int) $type_counts[$k] . ")";
144  }
145  } else {
146  include_once("./Services/Component/classes/class.ilPlugin.php");
148  $types[$k] = $pl->txt("objs_" . $k) . " (" . (int) $type_counts[$k] . ")";
149  }
150 
151  }
152  $type_prop->setOptions($types);
153  $selected = ($a_insert)
154  ? ""
155  : $this->content_obj->getResourceListType();
156  $type_prop->setValue($selected);
157  if (count($item_groups) > 0) {
158  $op_type->addSubItem($type_prop);
159  } else {
160  $form->addItem($type_prop);
161  }
162 
163  if (count($item_groups) > 0) {
164  // item groups
165  $options = $item_groups;
166  $si = new ilSelectInputGUI($this->lng->txt("obj_itgr"), "itgr");
167  $si->setOptions($options);
168  $selected = ($a_insert)
169  ? ""
170  : $this->content_obj->getItemGroupRefId();
171  $op_itemgroup->addSubItem($si);
172  }
173 
174 
175  // save/cancel buttons
176  if ($a_insert) {
177  $form->addCommandButton("create_resources", $lng->txt("save"));
178  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
179  } else {
180  $form->addCommandButton("update_resources", $lng->txt("save"));
181  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
182  }
183  $html = $form->getHTML();
184  $tpl->setContent($html);
185  return $ret;
186  }
187 
188 
192  public function create()
193  {
194  $this->content_obj = new ilPCResources($this->getPage());
195  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
196 
197  if ($_POST["res_type"] != "itgr") {
198  $this->content_obj->setResourceListType(ilUtil::stripSlashes($_POST["type"]));
199  } else {
200  $this->content_obj->setItemGroupRefId(ilUtil::stripSlashes($_POST["itgr"]));
201  }
202  $this->updated = $this->pg_obj->update();
203  if ($this->updated === true) {
204  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
205  } else {
206  $this->insert();
207  }
208  }
209 
213  public function update()
214  {
215  if ($_POST["res_type"] != "itgr") {
216  $this->content_obj->setResourceListType(ilUtil::stripSlashes($_POST["type"]));
217  } else {
218  $this->content_obj->setItemGroupRefId(ilUtil::stripSlashes($_POST["itgr"]));
219  }
220  $this->updated = $this->pg_obj->update();
221  if ($this->updated === true) {
222  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
223  } else {
224  $this->pg_obj->addHierIDs();
225  $this->edit();
226  }
227  }
228 
236  {
237  global $DIC;
238 
239  $objDefinition = $DIC["objDefinition"];
240  $tree = $DIC->repositoryTree();
241  $lng = $DIC->language();
242 
243  $ref_id = (int) $_GET["ref_id"];
244  $obj_id = (int) ilObject::_lookupObjId($ref_id);
245  $obj_type = ilObject::_lookupType($obj_id);
246 
247  // determine type -> group
248  $type_to_grp = array();
249  $type_grps =
250  $objDefinition->getGroupedRepositoryObjectTypes($obj_type);
251  foreach ($type_grps as $grp => $def) {
252  foreach ($def["objs"] as $t) {
253  $type_to_grp[$t] = $grp;
254  }
255  }
256 
257  $childs = $tree->getChilds($ref_id);
258  $childs_by_type = array();
259  $item_groups = array();
260  foreach ($childs as $child) {
261  $childs_by_type[$type_to_grp[$child["type"]]][] = $child;
262  if ($child["type"] == "itgr") {
263  $item_groups[(int) $child["ref_id"]] = $child["title"];
264  }
265  }
266 
267  // handle "by type" lists
268  foreach ($type_grps as $type => $v) {
269  if (is_int(strpos($a_content, "[list-" . $type . "]"))) {
270  // render block
271  $tpl = new ilTemplate("tpl.resource_block.html", true, true, "Services/COPage");
272  $cnt = 0;
273 
274  if (is_array($childs_by_type[$type]) && count($childs_by_type[$type]) > 0) {
275  foreach ($childs_by_type[$type] as $child) {
276  $tpl->setCurrentBlock("row");
277  $tpl->setVariable("IMG", ilUtil::img(ilObject::_getIcon($child["obj_id"], "small")));
278  $tpl->setVariable("TITLE", $child["title"]);
279  $tpl->parseCurrentBlock();
280  $cnt++;
281  }
282  $tpl->setVariable("HEADER", $lng->txt("objs_" . $type));
283  $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
284  } else {
285  $tpl->setCurrentBlock("row");
286  $tpl->setVariable("TITLE", $lng->txt("no_items"));
287  $tpl->parseCurrentBlock();
288  $tpl->setVariable("HEADER", $lng->txt("objs_" . $type));
289  $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
290  }
291  }
292  }
293 
294  // handle item groups
295  while (preg_match('/\[(item-group-([0-9]*))\]/i', $a_content, $found)) {
296  $itgr_ref_id = (int) $found[2];
297 
298  // check whether this item group is child -> insert editing html
299  if (isset($item_groups[$itgr_ref_id])) {
300  include_once("./Modules/ItemGroup/classes/class.ilItemGroupItems.php");
301  $itgr_items = new ilItemGroupItems($itgr_ref_id);
302  $items = $itgr_items->getValidItems();
303 
304  // render block
305  $tpl = new ilTemplate("tpl.resource_block.html", true, true, "Services/COPage");
306  foreach ($items as $it_ref_id) {
307  $it_obj_id = ilObject::_lookupObjId($it_ref_id);
308  $it_title = ilObject::_lookupTitle($it_obj_id);
309  $it_type = ilObject::_lookupType($it_obj_id);
310 
311  // TODO: Handle this switch by module.xml definitions
312  if (in_array($it_type, array("catr", "crsr", "grpr"))) {
313  include_once('./Services/ContainerReference/classes/class.ilContainerReference.php');
314  $it_title = ilContainerReference::_lookupTitle($it_obj_id);
315  }
316 
317 
318  $tpl->setCurrentBlock("row");
319  $tpl->setVariable("IMG", ilUtil::img(ilObject::_getIcon($it_obj_id, "small")));
320  $tpl->setVariable("TITLE", $it_title);
321  $tpl->parseCurrentBlock();
322  }
323  $tpl->setVariable("HEADER", $item_groups[$itgr_ref_id]);
324  $html = $tpl->get();
325  } else {
326  $html = "<i>" . $lng->txt("cont_element_refers_removed_itgr") . "</i>";
327  }
328  $a_content = preg_replace('/\[' . $found[1] . '\]/i', $html, $a_content);
329  }
330 
331 
332  return $a_content;
333  }
334 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a property form user interface.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
edit($a_insert=false)
Edit resources form.
static _lookupTitle($a_id)
lookup object title
global $ilCtrl
Definition: ilias.php:18
static insertResourcesIntoPageContent($a_content)
Insert resources (see also ilContainerContentGUI::determinePageEmbeddedBlocks for presentation) ...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
This class represents a property in a property form.
create()
Create new Resources Component.
static _lookupTitle($a_obj_id)
Overwitten from base class.
if(isset($_POST['submit'])) $form
$a_content
Definition: workflow.php:93
Class ilPCResourcesGUI.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
displayValidationError()
display validation errors
Item group items.
executeCommand()
execute command
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Class ilPCResources.
static getRepoPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
$ret
Definition: parser.php:6
$def
Definition: croninfo.php:21
insert()
Insert new resources component form.
$key
Definition: croninfo.php:18
$_POST["username"]
$html
Definition: example_001.php:87
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
update()
Update Resources Component.