• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/News/classes/class.ilNewsItemGUIGen.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 define("IL_FORM_EDIT", 0);
00025 define("IL_FORM_CREATE", 1);
00026 define("IL_FORM_RE_EDIT", 2);
00027 define("IL_FORM_RE_CREATE", 3);
00028 
00035 class ilNewsItemGUIGen 
00036 {
00037 
00038         protected $enable_edit = 0;
00039         protected $context_obj_id;
00040         protected $context_obj_type;
00041         protected $context_sub_obj_id;
00042         protected $context_sub_obj_type;
00043         protected $form_edit_mode;
00044 
00049         public function __construct()
00050         {
00051                 global $ilCtrl;
00052                 
00053                 $this->ctrl = $ilCtrl;
00054                 
00055                 
00056                 include_once("Services/News/classes/class.ilNewsItemGen.php");
00057                 if ($_GET["news_item_id"] > 0)
00058                 {
00059                         $this->news_item = new ilNewsItemGen($_GET["news_item_id"]);
00060                 }
00061                 
00062                 $this->ctrl->saveParameter($this, array("news_item_id"));
00063                 
00064                 // Init EnableEdit.
00065                 $this->setEnableEdit(false);
00066                 
00067                 // Init Context.
00068                 $this->setContextObjId($ilCtrl->getContextObjId());
00069                 $this->setContextObjType($ilCtrl->getContextObjType());
00070                 $this->setContextSubObjId($ilCtrl->getContextSubObjId());
00071                 $this->setContextSubObjType($ilCtrl->getContextSubObjType());
00072                 
00073 
00074         }
00075 
00080         public function &executeCommand()
00081         {
00082                 global $ilCtrl;
00083                 
00084                 // get next class and command
00085                 $next_class = $this->ctrl->getNextClass($this);
00086                 $cmd = $this->ctrl->getCmd();
00087                 
00088                 switch ($next_class)
00089                 {
00090                         default:
00091                                 $html = $this->$cmd();
00092                                 break;
00093                 }
00094                 
00095                 return $html;
00096 
00097         }
00098 
00104         public function setEnableEdit($a_enable_edit = 0)
00105         {
00106                 $this->enable_edit = $a_enable_edit;
00107         }
00108 
00114         public function getEnableEdit()
00115         {
00116                 return $this->enable_edit;
00117         }
00118 
00124         public function setContextObjId($a_context_obj_id)
00125         {
00126                 $this->context_obj_id = $a_context_obj_id;
00127         }
00128 
00134         public function getContextObjId()
00135         {
00136                 return $this->context_obj_id;
00137         }
00138 
00144         public function setContextObjType($a_context_obj_type)
00145         {
00146                 $this->context_obj_type = $a_context_obj_type;
00147         }
00148 
00154         public function getContextObjType()
00155         {
00156                 return $this->context_obj_type;
00157         }
00158 
00164         public function setContextSubObjId($a_context_sub_obj_id)
00165         {
00166                 $this->context_sub_obj_id = $a_context_sub_obj_id;
00167         }
00168 
00174         public function getContextSubObjId()
00175         {
00176                 return $this->context_sub_obj_id;
00177         }
00178 
00184         public function setContextSubObjType($a_context_sub_obj_type)
00185         {
00186                 $this->context_sub_obj_type = $a_context_sub_obj_type;
00187         }
00188 
00194         public function getContextSubObjType()
00195         {
00196                 return $this->context_sub_obj_type;
00197         }
00198 
00204         public function setFormEditMode($a_form_edit_mode)
00205         {
00206                 $this->form_edit_mode = $a_form_edit_mode;
00207         }
00208 
00214         public function getFormEditMode()
00215         {
00216                 return $this->form_edit_mode;
00217         }
00218 
00223         public function createNewsItem()
00224         {
00225                 $this->initFormNewsItem(IL_FORM_CREATE);
00226                 return $this->form_gui->getHtml();
00227 
00228         }
00229 
00234         public function editNewsItem()
00235         {
00236                 $this->initFormNewsItem(IL_FORM_EDIT);
00237                 $this->getValuesNewsItem();
00238                 return $this->form_gui->getHtml();
00239 
00240         }
00241 
00246         public function saveNewsItem()
00247         {
00248                 $this->initFormNewsItem(IL_FORM_CREATE);
00249                 if ($this->form_gui->checkInput())
00250                 {
00251                         $this->news_item = new ilNewsItem();
00252                         $this->news_item->setTitle($this->form_gui->getInput("news_title"));
00253                         $this->news_item->setContent($this->form_gui->getInput("news_content"));
00254                         $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
00255                         $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
00256                         $this->prepareSaveNewsItem($this->news_item);
00257                         $this->news_item->create();
00258                         $this->exitSaveNewsItem();
00259                 }
00260                 else
00261                 {
00262                         $this->form_gui->setValuesByPost();
00263                         return $this->form_gui->getHtml();
00264                 }
00265 
00266         }
00267 
00272         public function updateNewsItem()
00273         {
00274                 $this->initFormNewsItem(IL_FORM_EDIT);
00275                 if ($this->form_gui->checkInput())
00276                 {
00277                         
00278                         $this->news_item->setTitle($this->form_gui->getInput("news_title"));
00279                         $this->news_item->setContent($this->form_gui->getInput("news_content"));
00280                         $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
00281                         $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
00282                         $this->news_item->update();
00283                         $this->exitUpdateNewsItem();
00284                 }
00285                 else
00286                 {
00287                         $this->form_gui->setValuesByPost();
00288                         return $this->form_gui->getHtml();
00289                 }
00290 
00291         }
00292 
00298         public function initFormNewsItem($a_mode)
00299         {
00300                 global $lng;
00301                 
00302                 $lng->loadLanguageModule("news");
00303                 
00304                 include("Services/Form/classes/class.ilPropertyFormGUI.php");
00305                 
00306                 $this->form_gui = new ilPropertyFormGUI();
00307                 
00308                 
00309                 // Property Title
00310                 $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
00311                 $text_input->setInfo("");
00312                 $text_input->setRequired(true);
00313                 $text_input->setMaxLength(200);
00314                 $this->form_gui->addItem($text_input);
00315                 
00316                 // Property Content
00317                 $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
00318                 $text_area->setInfo("");
00319                 $text_area->setRequired(false);
00320                 $this->form_gui->addItem($text_area);
00321                 
00322                 // Property Visibility
00323                 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
00324                 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
00325                 $radio_group->addOption($radio_option);
00326                 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
00327                 $radio_group->addOption($radio_option);
00328                 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
00329                 $radio_group->setRequired(false);
00330                 $radio_group->setValue("users");
00331                 $this->form_gui->addItem($radio_group);
00332                 
00333                 // Property ContentLong
00334                 $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
00335                 $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
00336                 $text_area->setRequired(false);
00337                 $text_area->setCols("40");
00338                 $text_area->setRows("8");
00339                 $text_area->setUseRte(true);
00340                 $this->form_gui->addItem($text_area);
00341                 
00342                 
00343                 // save and cancel commands
00344                 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
00345                 {
00346                         $this->form_gui->addCommandButton("saveNewsItem", $lng->txt("save"));
00347                         $this->form_gui->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"));
00348                 }
00349                 else
00350                 {
00351                         $this->form_gui->addCommandButton("updateNewsItem", $lng->txt("save"));
00352                         $this->form_gui->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"));
00353                 }
00354                 
00355                 $this->form_gui->setTitle($lng->txt("news_news_item_head"));
00356                 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
00357                 
00358                 $this->prepareFormNewsItem($this->form_gui);
00359 
00360         }
00361 
00366         public function getValuesNewsItem()
00367         {
00368                 $values = array();
00369                 
00370                 $values["news_title"] = $this->news_item->getTitle();
00371                 $values["news_content"] = $this->news_item->getContent();
00372                 $values["news_visibility"] = $this->news_item->getVisibility();
00373                 $values["news_content_long"] = $this->news_item->getContentLong();
00374                 
00375                 $this->form_gui->setValuesByArray($values);
00376 
00377         }
00378 
00383         public function cancelSaveNewsItem()
00384         {
00385                 global $ilCtrl;
00386 
00387                 $ilCtrl->returnToParent($this);
00388         }
00389 
00394         public function cancelUpdateNewsItem()
00395         {
00396                 global $ilCtrl;
00397 
00398                 $ilCtrl->returnToParent($this);
00399         }
00400 
00405         public function exitSaveNewsItem()
00406         {
00407                 global $ilCtrl;
00408 
00409                 $ilCtrl->returnToParent($this);
00410         }
00411 
00416         public function exitUpdateNewsItem()
00417         {
00418                 global $ilCtrl;
00419 
00420                 $ilCtrl->returnToParent($this);
00421         }
00422 
00428         public function prepareSaveNewsItem(&$a_news_item)
00429         {
00430 
00431         }
00432 
00438         public function prepareFormNewsItem(&$a_form_gui)
00439         {
00440 
00441         }
00442 
00447         public function getNewsForContextBlock()
00448         {
00449                 global $lng;
00450                 
00451                 include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
00452                 $block_gui = new ilNewsForContextBlockGUI(get_class($this));
00453                 $this->prepareBlockNewsForContext($block_gui);
00454                 
00455                 $news_item = new ilNewsItemGen();
00456                 $this->prepareBlockQueryNewsForContext($news_item);
00457                 $data = $news_item->queryNewsForContext();
00458                 
00459                 $block_gui->setTitle($lng->txt("news_block_news_for_context"));
00460                 $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
00461                 $block_gui->setData($data);
00462                 
00463                 return $block_gui->getHTML();
00464 
00465         }
00466 
00472         public function prepareBlockNewsForContext(&$a_block_gui)
00473         {
00474 
00475         }
00476 
00482         public function prepareBlockQueryNewsForContext(&$a_news_item)
00483         {
00484                 
00485                 $a_news_item->setContextObjId($this->getContextObjId());
00486                 $a_news_item->setContextObjType($this->getContextObjType());
00487                 $a_news_item->setContextSubObjId($this->getContextSubObjId());
00488                 $a_news_item->setContextSubObjType($this->getContextSubObjType());
00489 
00490         }
00491 
00496         public function getNewsForContextTable()
00497         {
00498                 global $lng;
00499                 
00500                 include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
00501                 $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable");
00502                 
00503                 $news_item = new ilNewsItemGen();
00504                 $this->prepareTableQueryNewsForContext($news_item);
00505                 $data = $news_item->queryNewsForContext();
00506                 
00507                 $table_gui->setTitle($lng->txt("news_table_news_for_context"));
00508                 $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
00509                 $table_gui->setData($data);
00510                 $this->prepareTableNewsForContext($table_gui);
00511                 
00512                 return $table_gui->getHTML();
00513 
00514         }
00515 
00521         public function prepareTableQueryNewsForContext(&$a_news_item)
00522         {
00523                 
00524                 $a_news_item->setContextObjId($this->getContextObjId());
00525                 $a_news_item->setContextObjType($this->getContextObjType());
00526                 $a_news_item->setContextSubObjId($this->getContextSubObjId());
00527                 $a_news_item->setContextSubObjType($this->getContextSubObjType());
00528 
00529         }
00530 
00536         public function prepareTableNewsForContext(&$a_table_gui)
00537         {
00538 
00539         }
00540 
00541 
00542 }
00543 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1