ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainerStartObjectsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  protected $object; // [ilObject]
16  protected $start_object; // [ilContainerStartObjects]
17 
18  public function __construct(ilObject $a_parent_obj)
19  {
20  global $ilCtrl, $ilTabs, $lng, $tpl;
21 
22  $this->ctrl = $ilCtrl;
23  $this->tabs_gui = $ilTabs;
24  $this->lng = $lng;
25  $this->tpl = $tpl;
26  $this->object = $a_parent_obj;
27 
28  include_once "Services/Container/classes/class.ilContainerStartObjects.php";
29  $this->start_object = new ilContainerStartObjects($this->object->getRefId(),
30  $this->object->getId());
31 
32  $this->lng->loadLanguageModule("crs");
33  }
34 
35  public function executeCommand()
36  {
37  // $this->prepareOutput();
38 
39  switch($this->ctrl->getNextClass($this))
40  {
41  case "ilcontainerstartobjectspagegui":
42  $this->checkPermission("write");
43  $this->tabs_gui->clearTargets();
44  $this->tabs_gui->setBackTarget($this->lng->txt("back"),
45  $this->ctrl->getLinkTarget($this, "listStructure"));
46 
47  include_once "Services/Container/classes/class.ilContainerStartObjectsPage.php";
48  if(!ilContainerStartObjectsPage::_exists("cstr", $this->object->getId()))
49  {
50  // doesn't exist -> create new one
51  $new_page_object = new ilContainerStartObjectsPage();
52  $new_page_object->setParentId($this->object->getId());
53  $new_page_object->setId($this->object->getId());
54  $new_page_object->createFromXML();
55  unset($new_page_object);
56  }
57 
58  $this->ctrl->setReturnByClass("ilcontainerstartobjectspagegui", "edit");
59  include_once "Services/Container/classes/class.ilContainerStartObjectsPageGUI.php";
60  $pgui = new ilContainerStartObjectsPageGUI($this->object->getId());
61 
62  // needed for editor?
63  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
64  $pgui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0));
65 
66  $ret = $this->ctrl->forwardCommand($pgui);
67  if($ret)
68  {
69  $this->tpl->setContent($ret);
70  }
71  break;
72 
73  default:
74  $cmd = $this->ctrl->getCmd("listStructure");
75  $cmd .= "Object";
76  $this->$cmd();
77  break;
78  }
79  }
80 
81  protected function checkPermission($a_cmd)
82  {
83  global $ilAccess;
84 
85  $ref_id = $this->object->getRefId();
86  if(!$ilAccess->checkAccess($a_cmd, "", $ref_id))
87  {
88  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
89  ilUtil::redirect("goto.php?target=".$this->object->getType()."_".$ref_id);
90  }
91  }
92 
93  public function setTabs($a_active = "manage")
94  {
95  global $ilSetting;
96 
97  $this->tabs_gui->addSubTab("manage",
98  $this->lng->txt("cntr_manage"),
99  $this->ctrl->getLinkTarget($this, "listStructure"));
100 
101  // :TODO: depending on this setting?
102  if ($ilSetting->get("enable_cat_page_edit"))
103  {
104  $this->tabs_gui->addSubTab("page_editor",
105  $this->lng->txt("cntr_text_media_editor"),
106  $this->ctrl->getLinkTargetByClass("ilContainerStartObjectsPageGUI", "edit"));
107  }
108 
109  $this->tabs_gui->activateSubTab($a_active);
110  }
111 
112  protected function listStructureObject()
113  {
114  global $ilToolbar;
115 
116  $this->checkPermission('write');
117  $this->setTabs();
118 
119  $ilToolbar->addButton($this->lng->txt('crs_add_starter'),
120  $this->ctrl->getLinkTarget($this, 'selectStarter'));
121 
122  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
123  $table = new ilContainerStartObjectsTableGUI($this, 'listStructure', $this->start_object);
124  $this->tpl->setContent($table->getHTML());
125  }
126 
127  protected function saveSortingObject()
128  {
129  $pos = $_POST["pos"];
130  if(is_array($pos))
131  {
132  asort($pos);
133  $counter = 0;
134  foreach(array_keys($pos) as $start_id)
135  {
136  $counter += 10;
137  $this->start_object->setObjectPos($start_id, $counter);
138  }
139 
140  ilUtil::sendSuccess($this->lng->txt('cntr_saved_sorting'), true);
141  }
142 
143  $this->ctrl->redirect($this, "listStructure");
144  }
145 
146  protected function askDeleteStarterObject()
147  {
148  if(!count($_POST['starter']))
149  {
150  ilUtil::sendFailure($this->lng->txt('select_one'), true);
151  $this->ctrl->redirect($this, "listStructure");
152  }
153 
154  $this->checkPermission('write');
155  $this->setTabs();
156 
157  // display confirmation message
158  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
159  $cgui = new ilConfirmationGUI();
160  $cgui->setFormAction($this->ctrl->getFormAction($this, "listStructure"));
161  $cgui->setHeaderText($this->lng->txt("crs_starter_delete_sure"));
162  $cgui->setCancel($this->lng->txt("cancel"), "listStructure");
163  $cgui->setConfirm($this->lng->txt("delete"), "deleteStarter");
164 
165  // list objects that should be deleted
166  $all = $this->start_object->getStartObjects();
167  foreach($_POST['starter'] as $starter_id)
168  {
169  $obj_id = ilObject::_lookupObjId($all[$starter_id]["item_ref_id"]);
170  $title = ilObject::_lookupTitle($obj_id);
171  $icon = ilObject::_getIcon($obj_id, "tiny");
172  $alt = $this->lng->txt('obj_'.ilObject::_lookupType($obj_id));
173  $cgui->addItem("starter[]", $starter_id, $title, $icon, $alt);
174  }
175 
176  $this->tpl->setContent($cgui->getHTML());
177  }
178 
179  protected function deleteStarterObject()
180  {
181  $this->checkPermission('write');
182 
183  if(!count($_POST['starter']))
184  {
185  ilUtil::sendFailure($this->lng->txt('select_one'), true);
186  }
187  else
188  {
189  foreach($_POST['starter'] as $starter_id)
190  {
191  $this->start_object->delete((int)$starter_id);
192  }
193 
194  ilUtil::sendSuccess($this->lng->txt('crs_starter_deleted'), true);
195  }
196 
197  $this->ctrl->redirect($this, "listStructure");
198  }
199 
200  protected function selectStarterObject()
201  {
202  $this->checkPermission('write');
203  $this->setTabs();
204 
205  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
206  $table = new ilContainerStartObjectsTableGUI($this, 'selectStarter', $this->start_object);
207  $this->tpl->setContent($table->getHTML());
208  }
209 
210  protected function addStarterObject()
211  {
212  $this->checkPermission('write');
213 
214  if(!count($_POST['starter']))
215  {
216  ilUtil::sendFailure($this->lng->txt('select_one'), true);
217  $this->ctrl->redirect($this, "selectStarter");
218  }
219 
220  $added = 0;
221  foreach($_POST['starter'] as $item_ref_id)
222  {
223  if(!$this->start_object->exists($item_ref_id))
224  {
225  ++$added;
226  $this->start_object->add($item_ref_id);
227  }
228  }
229  if($added)
230  {
231  ilUtil::sendSuccess($this->lng->txt('crs_added_starters'), true);
232  $this->ctrl->redirect($this, "listStructure");
233  }
234  else
235  {
236  ilUtil::sendFailure($this->lng->txt('crs_starters_already_assigned'), true);
237  $this->ctrl->redirect($this, "selectStarter");
238  }
239  }
240 }
241 
242 ?>