ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
18  protected $ctrl;
19 
23  protected $tabs_gui;
24 
28  protected $lng;
29 
33  protected $tpl;
34 
38  protected $access;
39 
43  protected $settings;
44 
48  protected $toolbar;
49 
50  protected $object; // [ilObject]
51  protected $start_object; // [ilContainerStartObjects]
52 
53  public function __construct(ilObject $a_parent_obj)
54  {
55  global $DIC;
56 
57  $this->access = $DIC->access();
58  $this->settings = $DIC->settings();
59  $this->toolbar = $DIC->toolbar();
60  $ilCtrl = $DIC->ctrl();
61  $ilTabs = $DIC->tabs();
62  $lng = $DIC->language();
63  $tpl = $DIC["tpl"];
64 
65  $this->ctrl = $ilCtrl;
66  $this->tabs_gui = $ilTabs;
67  $this->lng = $lng;
68  $this->tpl = $tpl;
69  $this->object = $a_parent_obj;
70 
71  include_once "Services/Container/classes/class.ilContainerStartObjects.php";
72  $this->start_object = new ilContainerStartObjects(
73  $this->object->getRefId(),
74  $this->object->getId()
75  );
76 
77  $this->lng->loadLanguageModule("crs");
78  }
79 
80  public function executeCommand()
81  {
82  // $this->prepareOutput();
83 
84  switch ($this->ctrl->getNextClass($this)) {
85  case "ilcontainerstartobjectspagegui":
86  $this->checkPermission("write");
87  $this->tabs_gui->clearTargets();
88  $this->tabs_gui->setBackTarget(
89  $this->lng->txt("back"),
90  $this->ctrl->getLinkTarget($this, "listStructure")
91  );
92 
93  include_once "Services/Container/classes/class.ilContainerStartObjectsPage.php";
94  if (!ilContainerStartObjectsPage::_exists("cstr", $this->object->getId())) {
95  // doesn't exist -> create new one
96  $new_page_object = new ilContainerStartObjectsPage();
97  $new_page_object->setParentId($this->object->getId());
98  $new_page_object->setId($this->object->getId());
99  $new_page_object->createFromXML();
100  unset($new_page_object);
101  }
102 
103  $this->tpl->setVariable(
104  "LOCATION_CONTENT_STYLESHEET",
106  $this->object->getStyleSheetId(),
107  $this->object->getType()
108  ))
109  );
110 
111  $this->ctrl->setReturnByClass("ilcontainerstartobjectspagegui", "edit");
112  include_once "Services/Container/classes/class.ilContainerStartObjectsPageGUI.php";
113  $pgui = new ilContainerStartObjectsPageGUI($this->object->getId());
114  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
116  $this->object->getStyleSheetId(),
117  $this->object->getType()
118  ));
119 
120  $ret = $this->ctrl->forwardCommand($pgui);
121  if ($ret) {
122  $this->tpl->setContent($ret);
123  }
124  break;
125 
126  default:
127  $cmd = $this->ctrl->getCmd("listStructure");
128  $cmd .= "Object";
129  $this->$cmd();
130  break;
131  }
132  }
133 
134  protected function checkPermission($a_cmd)
135  {
136  $ilAccess = $this->access;
137 
138  $ref_id = $this->object->getRefId();
139  if (!$ilAccess->checkAccess($a_cmd, "", $ref_id)) {
140  ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
141  ilUtil::redirect("goto.php?target=" . $this->object->getType() . "_" . $ref_id);
142  }
143  }
144 
145  public function setTabs($a_active = "manage")
146  {
148 
149  $this->tabs_gui->addSubTab(
150  "manage",
151  $this->lng->txt("cntr_manage"),
152  $this->ctrl->getLinkTarget($this, "listStructure")
153  );
154 
155  // :TODO: depending on this setting?
156  if ($ilSetting->get("enable_cat_page_edit")) {
157  $this->tabs_gui->addSubTab(
158  "page_editor",
159  $this->lng->txt("cntr_text_media_editor"),
160  $this->ctrl->getLinkTargetByClass("ilContainerStartObjectsPageGUI", "edit")
161  );
162  }
163 
164  $this->tabs_gui->activateSubTab($a_active);
165  }
166 
167  protected function listStructureObject()
168  {
169  $ilToolbar = $this->toolbar;
170 
171  $this->checkPermission('write');
172  $this->setTabs();
173 
174  $ilToolbar->addButton(
175  $this->lng->txt('crs_add_starter'),
176  $this->ctrl->getLinkTarget($this, 'selectStarter')
177  );
178 
179  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
180  $table = new ilContainerStartObjectsTableGUI($this, 'listStructure', $this->start_object);
181  $this->tpl->setContent($table->getHTML());
182  }
183 
184  protected function saveSortingObject()
185  {
186  $pos = $_POST["pos"];
187  if (is_array($pos)) {
188  asort($pos);
189  $counter = 0;
190  foreach (array_keys($pos) as $start_id) {
191  $counter += 10;
192  $this->start_object->setObjectPos($start_id, $counter);
193  }
194 
195  ilUtil::sendSuccess($this->lng->txt('cntr_saved_sorting'), true);
196  }
197 
198  $this->ctrl->redirect($this, "listStructure");
199  }
200 
201  protected function askDeleteStarterObject()
202  {
203  if (!count($_POST['starter'])) {
204  ilUtil::sendFailure($this->lng->txt('select_one'), true);
205  $this->ctrl->redirect($this, "listStructure");
206  }
207 
208  $this->checkPermission('write');
209  $this->setTabs();
210 
211  // display confirmation message
212  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
213  $cgui = new ilConfirmationGUI();
214  $cgui->setFormAction($this->ctrl->getFormAction($this, "listStructure"));
215  $cgui->setHeaderText($this->lng->txt("crs_starter_delete_sure"));
216  $cgui->setCancel($this->lng->txt("cancel"), "listStructure");
217  $cgui->setConfirm($this->lng->txt("remove"), "deleteStarter");
218 
219  // list objects that should be deleted
220  $all = $this->start_object->getStartObjects();
221  foreach ($_POST['starter'] as $starter_id) {
222  $obj_id = ilObject::_lookupObjId($all[$starter_id]["item_ref_id"]);
223  $title = ilObject::_lookupTitle($obj_id);
224  $icon = ilObject::_getIcon($obj_id, "tiny");
225  $alt = $this->lng->txt('obj_' . ilObject::_lookupType($obj_id));
226  $cgui->addItem("starter[]", $starter_id, $title, $icon, $alt);
227  }
228 
229  $this->tpl->setContent($cgui->getHTML());
230  }
231 
232  protected function deleteStarterObject()
233  {
234  $this->checkPermission('write');
235 
236  if (!count($_POST['starter'])) {
237  ilUtil::sendFailure($this->lng->txt('select_one'), true);
238  } else {
239  foreach ($_POST['starter'] as $starter_id) {
240  $this->start_object->delete((int) $starter_id);
241  }
242 
243  ilUtil::sendSuccess($this->lng->txt('crs_starter_deleted'), true);
244  }
245 
246  $this->ctrl->redirect($this, "listStructure");
247  }
248 
249  protected function selectStarterObject()
250  {
251  $this->checkPermission('write');
252  $this->setTabs();
253 
254  include_once './Services/Container/classes/class.ilContainerStartObjectsTableGUI.php';
255  $table = new ilContainerStartObjectsTableGUI($this, 'selectStarter', $this->start_object);
256  $this->tpl->setContent($table->getHTML());
257  }
258 
259  protected function addStarterObject()
260  {
261  $this->checkPermission('write');
262 
263  if (!count($_POST['starter'])) {
264  ilUtil::sendFailure($this->lng->txt('select_one'), true);
265  $this->ctrl->redirect($this, "selectStarter");
266  }
267 
268  $added = 0;
269  foreach ($_POST['starter'] as $item_ref_id) {
270  if (!$this->start_object->exists($item_ref_id)) {
271  ++$added;
272  $this->start_object->add($item_ref_id);
273  }
274  }
275  if ($added) {
276  ilUtil::sendSuccess($this->lng->txt('crs_added_starters'), true);
277  $this->ctrl->redirect($this, "listStructure");
278  } else {
279  ilUtil::sendFailure($this->lng->txt('crs_starters_already_assigned'), true);
280  $this->ctrl->redirect($this, "selectStarter");
281  }
282  }
283 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Container start objects page GUI class.
global $DIC
Definition: saml.php:7
Container start objects page object.
static _lookupTitle($a_id)
lookup object title
global $ilCtrl
Definition: ilias.php:18
$counter
static _lookupObjId($a_id)
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static getContentStylePath($a_style_id, $add_random=true)
get content style path
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
settings()
Definition: settings.php:2
Create new PHPExcel object
obj_idprivate
global $ilSetting
Definition: privfeed.php:17
$ret
Definition: parser.php:6
if(empty($password)) $table
Definition: pwgen.php:24
static redirect($a_script)
$_POST["username"]
Class ilContainerStartObjectsGUI.
Confirmation screen class.