ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopTopicsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilShopTopics.php';
5 
16 {
17  private $objCurrentTopic = null;
18  private $ctrl = null;
19  private $tpl = null;
20  private $lng = null;
21  private $ask_for_deletion = false;
22 
23  public function __construct($a_gui_object)
24  {
25  global $tpl, $ilCtrl, $lng;
26 
27  $this->ctrl = $ilCtrl;
28  $this->lng = $lng;
29  $this->tpl = $tpl;
30 
31  $a_gui_object->tabs_gui->setTabActive('topics');
32 
33  $this->objCurrentTopic = new ilShopTopic(ilUtil::stripSlashes($_GET['topic_id']));
34  }
35 
36  public function executeCommand()
37  {
38  $cmd = $this->ctrl->getCmd();
39  switch($this->ctrl->getNextClass($this))
40  {
41  default:
42  if(!$cmd = $this->ctrl->getCmd())
43  {
44  $cmd = 'showTopicsList';
45  }
46  $this->$cmd();
47  break;
48  }
49 
50  return true;
51  }
52 
53  public function saveTopic()
54  {
55  $this->objCurrentTopic->setTitle(ilUtil::stripSlashes(trim($_POST['title'])));
56  $this->objCurrentTopic->setSorting((int)ilUtil::stripSlashes(trim($_POST['sorting'])));
57 
58  if($_POST['title'] == '')
59  {
60  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
61 
62  $this->showTopicForm();
63  }
64  else
65  {
66  $mode = $this->objCurrentTopic->getId() ? 'edit' : 'create';
67 
68  if($this->objCurrentTopic->save())
69  {
70  ilUtil::sendSuccess($this->lng->txt($mode == 'create' ? 'topic_saved' : 'topic_edited'));
71  }
72 
73  $this->showTopicsList();
74  }
75 
76  return true;
77  }
78 
79  public function showTopicForm()
80  {
81  $this->tpl->addBlockFile('ADM_CONTENT','adm_content', 'tpl.main_view.html', 'Services/Payment');
82 
83  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
84 
85  $form = new ilPropertyFormGUI();
86 
87  if($this->objCurrentTopic->getId())
88  {
89  $this->ctrl->setParameter($this, 'topic_id', $this->objCurrentTopic->getId());
90  }
91  $form->setFormAction($this->ctrl->getFormAction($this, 'saveTopic'));
92 
93  $form->setTitle($this->lng->txt($this->objCurrentTopic->getId() ? 'edit_topic' : 'new_topic'));
94 
95  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
96  $title->setValue($this->objCurrentTopic->getTitle());
97  $title->setRequired(true);
98  $form->addItem($title);
99 
100  $sorting = new ilTextInputGUI($this->lng->txt('pay_sorting_value'), 'sorting');
101  $sorting->setValue($this->objCurrentTopic->getSorting());
102  $sorting->setMaxLength(11);
103  $sorting->setSize(11);
104  $form->addItem($sorting);
105 
106  $form->addCommandButton('saveTopic', $this->lng->txt('save'));
107  $form->addCommandButton('showTopicsList', $this->lng->txt('cancel'));
108 
109  $this->tpl->setVariable('FORM', $form->getHTML());
110 
111  return true;
112  }
113 
114  public function confirmDeleteTopic()
115  {
116  if(!count($_POST['topic_id']))
117  {
118  ilUtil::sendInfo($this->lng->txt('select_one_topic'));
119  }
120  else
121  {
122  $this->ask_for_deletion = true;
123  }
124 
125  $this->showTopicsList();
126 
127  return true;
128  }
129 
130  public function saveSorting()
131  {
132  if(count($_POST['sorting']))
133  {
134  foreach($_POST['sorting'] as $topic_id => $sorting_value)
135  {
136  $oTopic = new ilShopTopic($topic_id);
137  $oTopic->setSorting($sorting_value);
138  $oTopic->save();
139  unset($oTopic);
140  }
141  }
142 
143  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
144 
145  $this->showTopicsList();
146 
147  return true;
148  }
149 
150  public function performDeleteTopic()
151  {
152  if(!count($_POST['topic_id']))
153  {
154  ilUtil::sendInfo($this->lng->txt('select_one_topic'));
155  }
156  else
157  {
158  foreach($_POST['topic_id'] as $topic_id)
159  {
160  $oTopic = new ilShopTopic($topic_id);
161  $oTopic->delete();
162  unset($oTopic);
163  }
164 
165  ilUtil::sendInfo($this->lng->txt('topics_deleted'));
166  }
167 
168  $this->showTopicsList();
169 
170  return true;
171  }
172 
173  public function showTopicsList()
174  {
175  $this->tpl->addBlockFile('ADM_CONTENT','adm_content', 'tpl.main_view.html', 'Services/Payment');
176 
177  if($this->ask_for_deletion)
178  {
179  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
180  $c_gui = new ilConfirmationGUI();
181 
182  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteTopic'));
183  $c_gui->setHeaderText($this->lng->txt('sure_delete_topics'));
184  $c_gui->setCancel($this->lng->txt('cancel'), 'showTopicsList');
185  $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteTopic');
186 
187  foreach($_POST['topic_id'] as $topic_id)
188  {
189  $c_gui->addItem('topic_id[]', $topic_id, ilShopTopic::_lookupTitle($topic_id));
190  }
191 
192  $this->tpl->setVariable('CONFIRMATION', $c_gui->getHTML());
193 
194  return true;
195  }
196 
197  include_once 'Services/Payment/classes/class.ilShopTopicsTableGUI.php';
198  $table_gui = new ilShopTopicsTableGUI($this, 'showTopicsList');
199  $table_gui->setTitle($this->lng->txt('topics'));
201  ilShopTopics::_getInstance()->setSortingDirection('ASC');
202  ilShopTopics::_getInstance()->read();
203  $table_gui->parseRecords(ilShopTopics::_getInstance()->getTopics());
204  $table_gui->addCommandButton('showTopicForm', $this->lng->txt('add'));
205  $table_gui->addCommandButton('saveSorting', $this->lng->txt('pay_save_sorting'));
206 
207  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
208 
209  return true;
210  }
211 }
212 ?>