ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  if(!count($tpls))
66  {
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  foreach($tpls as $tpl)
76  {
77  $options[$tpl->getId()] = $tpl->getTitle();
78  }
79 
80  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
81  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
82  $tpl_selection = new ilSelectInputGUI(
83  '',
84  'tplid'
85  );
86  $tpl_selection->setOptions($options);
87  $tpl_selection->setValue(ilDidacticTemplateObjSettings::lookupTemplateId(
88  $this->getParentObject()->object->getRefId()
89  ));
90  $toolbar->addInputItem($tpl_selection);
91 
92  // Apply templates switch
93  $toolbar->addFormButton($this->lng->txt('change'),'confirmTemplateSwitch');
94  return true;
95  }
96 
97  /*
98  * Show didactic template switch confirmation screen
99  */
100  protected function confirmTemplateSwitch()
101  {
102  global $ilCtrl, $ilTabs, $tpl;
103 
104  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
105 
106  // Check if template is changed
107  $new_tpl_id = (int) $_REQUEST['tplid'];
108  if($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId()))
109  {
110  $GLOBALS['ilLog']->write(__METHOD__.': Template id: '.$new_tpl_id);
111  ilUtil::sendInfo($this->lng->txt('didactic_not_changed'),true);
112  $ilCtrl->returnToParent($this);
113  }
114 
115  $ilTabs->clearTargets();
116  $ilTabs->clearSubTabs();
117 
118  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
119  $confirm = new ilConfirmationGUI();
120  $confirm->setFormAction($ilCtrl->getFormAction($this));
121  $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
122  $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
123  $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
124 
125  if($new_tpl_id)
126  {
127  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
128  $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
129 
130  $confirm->addItem(
131  'tplid',
132  $new_tpl_id,
133  $dtpl->getTitle().
134  '<div class="il_Description">'.
135  $dtpl->getDescription().' '.
136  '</div>'
137  );
138  }
139  else
140  {
141  $confirm->addItem(
142  'tplid',
143  $new_tpl_id,
144  $this->lng->txt('default').' '.
145  '<div class="il_Description">'.
146  sprintf(
147  $this->lng->txt('didactic_default_type_info'),
148  $this->lng->txt('objs_'.$this->getParentObject()->object->getType())
149  ).
150  '</div>'
151  );
152 
153  }
154  $tpl->setContent($confirm->getHTML());
155  }
156 
160  protected function cancel()
161  {
162  global $ilCtrl;
163 
164  $ilCtrl->returnToParent($this);
165  }
166 
170  protected function switchTemplate()
171  {
172  global $ilCtrl;
173 
174  $new_tpl_id = (int) $_REQUEST['tplid'];
175 
176  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
178  $this->getParentObject()->object->getRefId()
179  );
180 
181  // Revert current template
182  if($current_tpl_id)
183  {
184  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
185  foreach(ilDidacticTemplateActionFactory::getActionsByTemplateId($current_tpl_id) as $action)
186  {
187  $action->setRefId($this->getParentObject()->object->getRefId());
188  $action->revert();
189  }
190  }
191  if($new_tpl_id)
192  {
193  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
194  foreach(ilDidacticTemplateActionFactory::getActionsByTemplateId($new_tpl_id) as $action)
195  {
196  $action->setRefId($this->getParentObject()->object->getRefId());
197  $action->apply();
198  }
199  }
200 
201  // Assign template id to object
203  $this->getParentObject()->object->getRefId(),
204  $this->getParentObject()->object->getId(),
205  $new_tpl_id
206  );
207 
208  ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'),true);
209  $ilCtrl->returnToParent($this);
210  }
211 }
212 ?>