ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
48  default:
49  if(!$cmd)
50  {
51  $cmd = 'overview';
52  }
53  $this->$cmd();
54 
55  break;
56  }
57  return true;
58  }
59 
60  public function appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
61  {
62  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettings.php';
63  $tpls = ilDidacticTemplateSettings::getInstanceByObjectType($a_obj_type)->getTemplates();
64 
65  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
67 
68  if(!count($tpls) && !$value)
69  {
70  return false;
71  }
72 
73  // Add template switch
74  $toolbar->addText($this->lng->txt('didactic_selected_tpl_option'));
75 
76  // Show template options
77  $options = array(0 => $this->lng->txt('didactic_default_type'));
78  $excl_tpl = false;
79 
80  foreach($tpls as $tpl)
81  {
82  //just add if template is effective except template is already applied to this object
83  if($tpl->isEffective($_GET['ref_id']))
84  {
85  $options[$tpl->getId()] = $tpl->getPresentationTitle();
86 
87  if($tpl->isExclusive())
88  {
89  $excl_tpl = true;
90  }
91  }
92  }
93 
94  if($excl_tpl && $value != 0)
95  {
96  //remove default entry if an exclusive template exists but only if the actual entry isn't the default
97  unset($options[0]);
98  }
99 
100  if(!in_array($value, array_keys($options)) || ($excl_tpl && $value == 0))
101  {
102  $options[$value] = $this->lng->txt('not_available');
103  }
104 
105  if(count($options) < 2)
106  {
107  return false;
108  }
109 
110  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
111  $tpl_selection = new ilSelectInputGUI(
112  '',
113  'tplid'
114  );
115  $tpl_selection->setOptions($options);
116  $tpl_selection->setValue($value);
117  $toolbar->addInputItem($tpl_selection);
118 
119  // Apply templates switch
120  $toolbar->addFormButton($this->lng->txt('change'),'confirmTemplateSwitch');
121  return true;
122  }
123 
124  /*
125  * Show didactic template switch confirmation screen
126  */
127  protected function confirmTemplateSwitch()
128  {
129  global $ilCtrl, $ilTabs, $tpl;
130 
131  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
132 
133  // Check if template is changed
134  $new_tpl_id = (int) $_REQUEST['tplid'];
135  if($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId()))
136  {
137  ilLoggerFactory::getLogger('otpl')->debug('Template id: '.$new_tpl_id);
138  ilUtil::sendInfo($this->lng->txt('didactic_not_changed'),true);
139  $ilCtrl->returnToParent($this);
140  }
141 
142  $ilTabs->clearTargets();
143  $ilTabs->clearSubTabs();
144 
145  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
146  $confirm = new ilConfirmationGUI();
147  $confirm->setFormAction($ilCtrl->getFormAction($this));
148  $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
149  $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
150  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
151 
152  if($new_tpl_id)
153  {
154  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
155  $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
156 
157  $confirm->addItem(
158  'tplid',
159  $new_tpl_id,
160  $dtpl->getPresentationTitle().
161  '<div class="il_Description">'.
162  $dtpl->getPresentationDescription().' '.
163  '</div>'
164  );
165  }
166  else
167  {
168  $confirm->addItem(
169  'tplid',
170  $new_tpl_id,
171  $this->lng->txt('default').' '.
172  '<div class="il_Description">'.
173  sprintf(
174  $this->lng->txt('didactic_default_type_info'),
175  $this->lng->txt('objs_'.$this->getParentObject()->object->getType())
176  ).
177  '</div>'
178  );
179 
180  }
181  $tpl->setContent($confirm->getHTML());
182  }
183 
187  protected function cancel()
188  {
189  global $ilCtrl;
190 
191  $ilCtrl->returnToParent($this);
192  }
193 
197  protected function switchTemplate()
198  {
199  global $ilCtrl;
200 
201  $new_tpl_id = (int) $_REQUEST['tplid'];
202 
203  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateUtils.php';
204  ilDidacticTemplateUtils::switchTemplate($this->getParentObject()->object->getRefId(), $new_tpl_id);
205 
206  ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'),true);
207  $ilCtrl->returnToParent($this);
208  }
209 }
210 ?>
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"]
appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
addText($a_text)
Add text.
$cmd
Definition: sahs_server.php:35
global $tpl
Definition: ilias.php:8
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.
if(!is_array($argv)) $options
__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.
Confirmation screen class.