ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExternalFeedBlockGUIGen.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Block/classes/class.ilBlockGUI.php");
25 define("IL_FORM_EDIT", 0);
26 define("IL_FORM_CREATE", 1);
27 define("IL_FORM_RE_EDIT", 2);
28 define("IL_FORM_RE_CREATE", 3);
29 
36 abstract class ilExternalFeedBlockGUIGen extends ilBlockGUI
37 {
38  protected $gui_object;
39  protected $form_edit_mode;
40 
45  public function __construct()
46  {
47  global $DIC;
48 
49  $this->lng = $DIC->language();
50  $ilCtrl = $DIC->ctrl();
51 
52  parent::__construct();
53 
54  $this->ctrl = $ilCtrl;
55 
56 
57  include_once("Services/Block/classes/class.ilExternalFeedBlock.php");
58  if (isset($_GET["external_feed_block_id"]) && $_GET["external_feed_block_id"] > 0) {
59  $this->external_feed_block = new ilExternalFeedBlock($_GET["external_feed_block_id"]);
60  }
61 
62  $this->ctrl->saveParameter($this, array("external_feed_block_id"));
63  }
64 
69  public function executeCommand()
70  {
72 
73  // get next class and command
74  $next_class = $this->ctrl->getNextClass($this);
75  $cmd = $this->ctrl->getCmd();
76 
77  switch ($next_class) {
78  default:
79  $html = $this->$cmd();
80  break;
81  }
82 
83  return $html;
84  }
85 
91  public function setGuiObject(&$a_gui_object)
92  {
93  $this->gui_object = $a_gui_object;
94  }
95 
101  public function getGuiObject()
102  {
103  return $this->gui_object;
104  }
105 
111  public function setFormEditMode($a_form_edit_mode)
112  {
113  $this->form_edit_mode = $a_form_edit_mode;
114  }
115 
121  public function getFormEditMode()
122  {
123  return $this->form_edit_mode;
124  }
125 
130  public function createFeedBlock()
131  {
133  return $this->form_gui->getHtml();
134  }
135 
140  public function editFeedBlock()
141  {
143  $this->getValuesFeedBlock();
144  return $this->form_gui->getHtml();
145  }
146 
151  public function saveFeedBlock()
152  {
154 
155  $this->external_feed_block = new ilExternalFeedBlock();
156 
157  if ($this->form_gui->checkInput() &&
158  !$this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
159  $this->external_feed_block->setTitle($this->form_gui->getInput("block_title"));
160  $this->external_feed_block->setFeedUrl($this->form_gui->getInput("block_feed_url"));
161  $this->prepareSaveFeedBlock($this->external_feed_block);
162  $this->external_feed_block->create();
163  $this->exitSaveFeedBlock();
164  } else {
165  if ($this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
166  ilUtil::sendFailure($this->lng->txt("feed_no_local_url"), true);
167  }
168  $this->form_gui->setValuesByPost();
169  return $this->form_gui->getHtml();
170  }
171  }
172 
177  public function updateFeedBlock()
178  {
180 
181  if ($this->form_gui->checkInput() &&
182  !$this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
183  $this->external_feed_block->setTitle($this->form_gui->getInput("block_title"));
184  $this->external_feed_block->setFeedUrl($this->form_gui->getInput("block_feed_url"));
185  $this->external_feed_block->update();
186  $this->exitUpdateFeedBlock();
187  } else {
188  if ($this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
189  ilUtil::sendFailure($this->lng->txt("feed_no_local_url"));
190  }
191  $this->form_gui->setValuesByPost();
192  return $this->form_gui->getHtml();
193  }
194  }
195 
201  public function initFormFeedBlock($a_mode)
202  {
203  $lng = $this->lng;
204 
205  $lng->loadLanguageModule("block");
206 
207  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
208 
209  $this->form_gui = new ilPropertyFormGUI();
210 
211 
212  // Property Title
213  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
214  $text_input->setInfo("");
215  $text_input->setRequired(true);
216  $text_input->setMaxLength(200);
217  $this->form_gui->addItem($text_input);
218 
219  // Property FeedUrl
220  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
221  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
222  $text_input->setRequired(true);
223  $text_input->setMaxLength(250);
224  $this->form_gui->addItem($text_input);
225 
226 
227  // save and cancel commands
228  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
229  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
230  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
231  } else {
232  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
233  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
234  }
235 
236  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
237  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
238 
239  $this->prepareFormFeedBlock($this->form_gui);
240  }
241 
246  public function getValuesFeedBlock()
247  {
248  $values = array();
249 
250  $values["block_title"] = $this->external_feed_block->getTitle();
251  $values["block_feed_url"] = $this->external_feed_block->getFeedUrl();
252 
253  $this->form_gui->setValuesByArray($values);
254  }
255 
260  public function cancelSaveFeedBlock()
261  {
263 
264  $ilCtrl->returnToParent($this);
265  }
266 
271  public function cancelUpdateFeedBlock()
272  {
274 
275  $ilCtrl->returnToParent($this);
276  }
277 
282  public function exitSaveFeedBlock()
283  {
285 
286  $ilCtrl->returnToParent($this);
287  }
288 
293  public function exitUpdateFeedBlock()
294  {
296 
297  $ilCtrl->returnToParent($this);
298  }
299 
305  public function prepareSaveFeedBlock(&$a_external_feed_block)
306  {
307  }
308 
314  public function prepareFormFeedBlock(&$a_form_gui)
315  {
316  }
317 }
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
prepareFormFeedBlock(&$a_form_gui)
FORM FeedBlock: Prepare form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
updateFeedBlock()
FORM FeedBlock: Update ExternalFeedBlock.
prepareSaveFeedBlock(&$a_external_feed_block)
FORM FeedBlock: Prepare Saving of ExternalFeedBlock.
setGuiObject(&$a_gui_object)
Set GuiObject.
Custom block for external feeds.
GUI class for external news feed custom block.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
$values
This class represents a text property in a property form.
exitUpdateFeedBlock()
FORM FeedBlock: Exit update.
exitSaveFeedBlock()
FORM FeedBlock: Exit save.
saveFeedBlock()
FORM FeedBlock: Save ExternalFeedBlock.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
setFormEditMode($a_form_edit_mode)
Set FormEditMode.
This class represents a block method of a block.
cancelUpdateFeedBlock()
FORM FeedBlock: Cancel update.
editFeedBlock()
FORM FeedBlock: Edit form.
getValuesFeedBlock()
FORM FeedBlock: Get current values for ExternalFeedBlock form.
$html
Definition: example_001.php:87
cancelSaveFeedBlock()
FORM FeedBlock: Cancel save.
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.