ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
60  $this->object->getStyleSheetId(), $this->object->getType())));
61 
62  $this->ctrl->setReturnByClass("ilcontainerstartobjectspagegui", "edit");
63  include_once "Services/Container/classes/class.ilContainerStartObjectsPageGUI.php";
64  $pgui = new ilContainerStartObjectsPageGUI($this->object->getId());
65  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
67  $this->object->getStyleSheetId(), $this->object->getType()));
68 
69 
70  // needed for editor?
71  //include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
72  //$pgui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0));
73 
74  $ret = $this->ctrl->forwardCommand($pgui);
75  if($ret)
76  {
77  $this->tpl->setContent($ret);
78  }
79  break;
80 
81  default:
82  $cmd = $this->ctrl->getCmd("listStructure");
83  $cmd .= "Object";
84  $this->$cmd();
85  break;
86  }
87  }
88 
89  protected function checkPermission($a_cmd)
90  {
91  global $ilAccess;
92 
93  $ref_id = $this->object->getRefId();
94  if(!$ilAccess->checkAccess($a_cmd, "", $ref_id))
95  {
96  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
97  ilUtil::redirect("goto.php?target=".$this->object->getType()."_".$ref_id);
98  }
99  }
100 
101  public function setTabs($a_active = "manage")
102  {
103  global $ilSetting;
104 
105  $this->tabs_gui->addSubTab("manage",
106  $this->lng->txt("cntr_manage"),
107  $this->ctrl->getLinkTarget($this, "listStructure"));
108 
109  // :TODO: depending on this setting?
110  if ($ilSetting->get("enable_cat_page_edit"))
111  {
112  $this->tabs_gui->addSubTab("page_editor",
113  $this->lng->txt("cntr_text_media_editor"),
114  $this->ctrl->getLinkTargetByClass("ilContainerStartObjectsPageGUI", "edit"));
115  }
116 
117  $this->tabs_gui->activateSubTab($a_active);
118  }
119 
120  protected function listStructureObject()
121  {
122  global $ilToolbar;
123 
124  $this->checkPermission('write');
125  $this->setTabs();
126 
127  $ilToolbar->addButton($this->lng->txt('crs_add_starter'),
128  $this->ctrl->getLinkTarget($this, 'selectStarter'));
129 
130  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
131  $table = new ilContainerStartObjectsTableGUI($this, 'listStructure', $this->start_object);
132  $this->tpl->setContent($table->getHTML());
133  }
134 
135  protected function saveSortingObject()
136  {
137  $pos = $_POST["pos"];
138  if(is_array($pos))
139  {
140  asort($pos);
141  $counter = 0;
142  foreach(array_keys($pos) as $start_id)
143  {
144  $counter += 10;
145  $this->start_object->setObjectPos($start_id, $counter);
146  }
147 
148  ilUtil::sendSuccess($this->lng->txt('cntr_saved_sorting'), true);
149  }
150 
151  $this->ctrl->redirect($this, "listStructure");
152  }
153 
154  protected function askDeleteStarterObject()
155  {
156  if(!count($_POST['starter']))
157  {
158  ilUtil::sendFailure($this->lng->txt('select_one'), true);
159  $this->ctrl->redirect($this, "listStructure");
160  }
161 
162  $this->checkPermission('write');
163  $this->setTabs();
164 
165  // display confirmation message
166  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
167  $cgui = new ilConfirmationGUI();
168  $cgui->setFormAction($this->ctrl->getFormAction($this, "listStructure"));
169  $cgui->setHeaderText($this->lng->txt("crs_starter_delete_sure"));
170  $cgui->setCancel($this->lng->txt("cancel"), "listStructure");
171  $cgui->setConfirm($this->lng->txt("remove"), "deleteStarter");
172 
173  // list objects that should be deleted
174  $all = $this->start_object->getStartObjects();
175  foreach($_POST['starter'] as $starter_id)
176  {
177  $obj_id = ilObject::_lookupObjId($all[$starter_id]["item_ref_id"]);
178  $title = ilObject::_lookupTitle($obj_id);
179  $icon = ilObject::_getIcon($obj_id, "tiny");
180  $alt = $this->lng->txt('obj_'.ilObject::_lookupType($obj_id));
181  $cgui->addItem("starter[]", $starter_id, $title, $icon, $alt);
182  }
183 
184  $this->tpl->setContent($cgui->getHTML());
185  }
186 
187  protected function deleteStarterObject()
188  {
189  $this->checkPermission('write');
190 
191  if(!count($_POST['starter']))
192  {
193  ilUtil::sendFailure($this->lng->txt('select_one'), true);
194  }
195  else
196  {
197  foreach($_POST['starter'] as $starter_id)
198  {
199  $this->start_object->delete((int)$starter_id);
200  }
201 
202  ilUtil::sendSuccess($this->lng->txt('crs_starter_deleted'), true);
203  }
204 
205  $this->ctrl->redirect($this, "listStructure");
206  }
207 
208  protected function selectStarterObject()
209  {
210  $this->checkPermission('write');
211  $this->setTabs();
212 
213  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
214  $table = new ilContainerStartObjectsTableGUI($this, 'selectStarter', $this->start_object);
215  $this->tpl->setContent($table->getHTML());
216  }
217 
218  protected function addStarterObject()
219  {
220  $this->checkPermission('write');
221 
222  if(!count($_POST['starter']))
223  {
224  ilUtil::sendFailure($this->lng->txt('select_one'), true);
225  $this->ctrl->redirect($this, "selectStarter");
226  }
227 
228  $added = 0;
229  foreach($_POST['starter'] as $item_ref_id)
230  {
231  if(!$this->start_object->exists($item_ref_id))
232  {
233  ++$added;
234  $this->start_object->add($item_ref_id);
235  }
236  }
237  if($added)
238  {
239  ilUtil::sendSuccess($this->lng->txt('crs_added_starters'), true);
240  $this->ctrl->redirect($this, "listStructure");
241  }
242  else
243  {
244  ilUtil::sendFailure($this->lng->txt('crs_starters_already_assigned'), true);
245  $this->ctrl->redirect($this, "selectStarter");
246  }
247  }
248 }
249 
250 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Container start objects page GUI class.
$_POST['username']
Definition: cron.php:12
Container start objects page object.
Class ilObject Basic functions for all objects.
$cmd
Definition: sahs_server.php:35
static _lookupTitle($a_id)
lookup object title
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static _lookupObjId($a_id)
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$ref_id
Definition: sahs_server.php:39
getContentStylePath($a_style_id)
get content style path
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
static redirect($a_script)
http redirect to other script
Class ilContainerStartObjectsGUI.
Confirmation screen class.