ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCResourcesGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Services/COPage/classes/class.ilPCResources.php");
25 require_once("./Services/COPage/classes/class.ilPageContentGUI.php");
26 
38 {
39 
44  function ilPCResourcesGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
45  {
46  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
47  }
48 
52  function &executeCommand()
53  {
54  // get next class that processes or forwards current command
55  $next_class = $this->ctrl->getNextClass($this);
56 
57  // get current command
58  $cmd = $this->ctrl->getCmd();
59 
60  switch($next_class)
61  {
62  default:
63  $ret =& $this->$cmd();
64  break;
65  }
66 
67  return $ret;
68  }
69 
73  function insert()
74  {
75  $this->edit(true);
76  }
77 
81  function edit($a_insert = false)
82  {
83  global $ilCtrl, $tpl, $lng, $objDefinition;
84 
85  $this->displayValidationError();
86 
87  // edit form
88  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
89  $form = new ilPropertyFormGUI();
90  $form->setFormAction($ilCtrl->getFormAction($this));
91  if ($a_insert)
92  {
93  $form->setTitle($this->lng->txt("cont_insert_resources"));
94  }
95  else
96  {
97  $form->setTitle($this->lng->txt("cont_update_resources"));
98  }
99 
100  // type selection
101  $type_prop = new ilRadioGroupInputGUI($this->lng->txt("cont_type"),
102  "type");
103  $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
104  $obj_type = ilObject::_lookupType($obj_id);
105  $sub_objs = $objDefinition->getGroupedRepositoryObjectTypes($obj_type);
106  $types = array();
107  foreach($sub_objs as $k => $so)
108  {
109  $types[$k] = $this->lng->txt("objs_".$k);
110  }
111  foreach($types as $k => $type)
112  {
113  $option = new ilRadioOption($type, $k, "");
114  $type_prop->addOption($option);
115  }
116  $selected = ($a_insert)
117  ? ""
118  : $this->content_obj->getResourceListType();
119  $type_prop->setValue($selected);
120  $form->addItem($type_prop);
121 
122  // save/cancel buttons
123  if ($a_insert)
124  {
125  $form->addCommandButton("create_resources", $lng->txt("save"));
126  $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
127  }
128  else
129  {
130  $form->addCommandButton("update_resources", $lng->txt("save"));
131  $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
132  }
133  $html = $form->getHTML();
134  $tpl->setContent($html);
135  return $ret;
136 
137  }
138 
139 
143  function create()
144  {
145  $this->content_obj = new ilPCResources($this->dom);
146  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
147  $this->content_obj->setResourceListType($_POST["type"]);
148  $this->updated = $this->pg_obj->update();
149  if ($this->updated === true)
150  {
151  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
152  }
153  else
154  {
155  $this->insert();
156  }
157  }
158 
162  function update()
163  {
164  $this->content_obj->setResourceListType($_POST["type"]);
165  $this->updated = $this->pg_obj->update();
166  if ($this->updated === true)
167  {
168  $this->ctrl->returnToParent($this, "jump".$this->hier_id);
169  }
170  else
171  {
172  $this->pg_obj->addHierIDs();
173  $this->edit();
174  }
175  }
176 }
177 ?>