ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDidacticTemplateGUI.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 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
5 
14 {
15  private $parent_object;
16  private $lng;
17 
21  public function __construct($a_parent_obj)
22  {
23  global $lng;
24 
25  $this->parent_object = $a_parent_obj;
26  $this->lng = $lng;
27  $this->lng->loadLanguageModule('didactic');
28  }
29 
30  public function getParentObject()
31  {
32  return $this->parent_object;
33  }
34 
39  public function executeCommand()
40  {
41  global $ilCtrl;
42 
43  $next_class = $ilCtrl->getNextClass($this);
44  $cmd = $ilCtrl->getCmd();
45 
46  switch ($next_class) {
47  default:
48  if (!$cmd) {
49  $cmd = 'overview';
50  }
51  $this->$cmd();
52 
53  break;
54  }
55  return true;
56  }
57 
58  public function appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
59  {
60  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettings.php';
61  $tpls = ilDidacticTemplateSettings::getInstanceByObjectType($a_obj_type)->getTemplates();
62 
63  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
65 
66  if (!count($tpls) && !$value) {
67  return false;
68  }
69 
70  // Add template switch
71  $toolbar->addText($this->lng->txt('didactic_selected_tpl_option'));
72 
73  // Show template options
74  $options = array(0 => $this->lng->txt('didactic_default_type'));
75  $excl_tpl = false;
76 
77  foreach ($tpls as $tpl) {
78  //just add if template is effective except template is already applied to this object
79  if ($tpl->isEffective($_GET['ref_id'])) {
80  $options[$tpl->getId()] = $tpl->getPresentationTitle();
81 
82  if ($tpl->isExclusive()) {
83  $excl_tpl = true;
84  }
85  }
86  }
87 
88  if ($excl_tpl && $value != 0) {
89  //remove default entry if an exclusive template exists but only if the actual entry isn't the default
90  unset($options[0]);
91  }
92 
93  if (!in_array($value, array_keys($options)) || ($excl_tpl && $value == 0)) {
94  $options[$value] = $this->lng->txt('not_available');
95  }
96 
97  if (count($options) < 2) {
98  return false;
99  }
100 
101  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
102  $tpl_selection = new ilSelectInputGUI(
103  '',
104  'tplid'
105  );
106  $tpl_selection->setOptions($options);
107  $tpl_selection->setValue($value);
108  $toolbar->addInputItem($tpl_selection);
109 
110  // Apply templates switch
111  $toolbar->addFormButton($this->lng->txt('change'), 'confirmTemplateSwitch');
112  return true;
113  }
114 
115  /*
116  * Show didactic template switch confirmation screen
117  */
118  protected function confirmTemplateSwitch()
119  {
120  global $ilCtrl, $ilTabs, $tpl;
121 
122  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
123 
124  // Check if template is changed
125  $new_tpl_id = (int) $_REQUEST['tplid'];
126  if ($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId())) {
127  ilLoggerFactory::getLogger('otpl')->debug('Template id: ' . $new_tpl_id);
128  ilUtil::sendInfo($this->lng->txt('didactic_not_changed'), true);
129  $ilCtrl->returnToParent($this);
130  }
131 
132  $ilTabs->clearTargets();
133  $ilTabs->clearSubTabs();
134 
135  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
136  $confirm = new ilConfirmationGUI();
137  $confirm->setFormAction($ilCtrl->getFormAction($this));
138  $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
139  $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
140  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
141 
142  if ($new_tpl_id) {
143  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
144  $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
145 
146  $confirm->addItem(
147  'tplid',
148  $new_tpl_id,
149  $dtpl->getPresentationTitle() .
150  '<div class="il_Description">' .
151  $dtpl->getPresentationDescription() . ' ' .
152  '</div>'
153  );
154  } else {
155  $confirm->addItem(
156  'tplid',
157  $new_tpl_id,
158  $this->lng->txt('default') . ' ' .
159  '<div class="il_Description">' .
160  sprintf(
161  $this->lng->txt('didactic_default_type_info'),
162  $this->lng->txt('objs_' . $this->getParentObject()->object->getType())
163  ) .
164  '</div>'
165  );
166  }
167  $tpl->setContent($confirm->getHTML());
168  }
169 
173  protected function cancel()
174  {
175  global $ilCtrl;
176 
177  $ilCtrl->returnToParent($this);
178  }
179 
183  protected function switchTemplate()
184  {
185  global $ilCtrl;
186 
187  $new_tpl_id = (int) $_REQUEST['tplid'];
188 
189  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateUtils.php';
190  ilDidacticTemplateUtils::switchTemplate($this->getParentObject()->object->getRefId(), $new_tpl_id);
191 
192  ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'), true);
193  $ilCtrl->returnToParent($this);
194  }
195 }
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a selection list property in a property form.
$_GET["client_id"]
$tpl
Definition: ilias.php:10
appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
addText($a_text)
Add text.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
addInputItem(ilToolbarItem $a_item, $a_output_label=false)
Add input item.
static switchTemplate($a_ref_id, $a_new_tpl_id)
GUI class for didactic template settings inside repository objects.
__construct($a_parent_obj)
Constructor.
addFormButton($a_txt, $a_cmd, $a_acc_key="", $a_primary=false, $a_class=false)
Add form button to toolbar.
cancel()
Return to parent gui.
Create styles array
The data for the language used.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
Create new PHPExcel object
obj_idprivate
static getLogger($a_component_id)
Get component logger.
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
Confirmation screen class.