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

Services/News/classes/class.ilPDNewsBlockGUI.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 include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
00025 
00036 class ilPDNewsBlockGUI extends ilNewsForContextBlockGUI
00037 {
00038         static $block_type = "pdnews";
00039         static $st_data;
00040         
00044         function ilPDNewsBlockGUI()
00045         {
00046                 global $ilCtrl, $lng, $ilUser, $ilBench, $ilAccess, $ilCtrl;
00047                 
00048                 $ilBench->start("News", "ilPDNewsBlockGUI_Constructor");
00049                 $news_set = new ilSetting("news");
00050                 
00051                 parent::ilBlockGUI();
00052                 
00053                 $this->setImage(ilUtil::getImagePath("icon_news_s.gif"));
00054 
00055                 $lng->loadLanguageModule("news");
00056                 include_once("./Services/News/classes/class.ilNewsItem.php");
00057 
00058                 $this->setLimit(5);
00059                 $this->setAvailableDetailLevels(3);
00060 
00061                 $this->dynamic = false;
00062                 
00063                 // store current access check results
00064                 $this->acc_results = $ilAccess->getResults();
00065                 
00066                 // read access cache
00067                 $this->acc_cache_hit = $ilAccess->readCache(
00068                         ((int) $news_set->get("acc_cache_mins")) * 60);
00069 
00070                 if ($this->getDynamic() && !$this->acc_cache_hit)
00071                 {
00072                         $this->dynamic = true;
00073                         $data = array();
00074                 }
00075                 else if ($this->getCurrentDetailLevel() > 0)
00076                 {
00077                         // do not ask two times for the data (e.g. if user displays a 
00078                         // single item on the personal desktop and the news block is 
00079                         // displayed at the same time)
00080                         if (empty(self::$st_data))
00081                         {
00082                                 self::$st_data = $this->getNewsData();
00083                                 $data = self::$st_data;
00084                         }
00085                         else
00086                         {
00087                                 $data = self::$st_data;
00088                         }
00089                 }
00090                 else
00091                 {
00092                         $data = array();
00093                 }
00094                 
00095                 $this->setTitle($lng->txt("news_internal_news"));
00096                 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
00097                 
00098                 $this->setData($data);
00099                 
00100                 $this->handleView();
00101                 
00102                 // reset access check results
00103                 $ilAccess->setResults($this->acc_results);
00104                 
00105                 $ilBench->stop("News", "ilPDNewsBlockGUI_Constructor");
00106         }
00107         
00111         function getNewsData()
00112         {
00113                 global $ilUser, $ilAccess;
00114                 
00115                 $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
00116                 $data = ilNewsItem::_getNewsItemsOfUser($ilUser->getId(), false,
00117                         false, $per);
00118                 if (!$this->acc_cache_hit)
00119                 {
00120                         $ilAccess->storeCache();
00121                 }
00122                 return $data;
00123         }
00124         
00130         static function getBlockType()
00131         {
00132                 return self::$block_type;
00133         }
00134         
00140         static function isRepositoryObject()
00141         {
00142                 return false;
00143         }
00144 
00148         static function getScreenMode()
00149         {
00150                 global $ilCtrl;
00151                 
00152                 switch($_GET["cmd"])
00153                 {
00154                         case "showNews":
00155                         case "showFeedUrl":
00156                         case "editSettings":
00157                                 return IL_SCREEN_CENTER;
00158                                 break;
00159                         
00160                         default:
00161                                 return IL_SCREEN_SIDE;
00162                                 break;
00163                 }
00164         }
00165 
00169         function &executeCommand()
00170         {
00171                 global $ilCtrl;
00172 
00173                 $next_class = $ilCtrl->getNextClass();
00174                 $cmd = $ilCtrl->getCmd("getHTML");
00175 
00176                 switch ($next_class)
00177                 {
00178                         default:
00179                                 return $this->$cmd();
00180                 }
00181         }
00182 
00186         function fillDataSection()
00187         {
00188                 global $ilBench;
00189                 
00190                 if ($this->dynamic)
00191                 {
00192                         $this->setDataSection($this->getDynamicReload());
00193                 }
00194                 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
00195                 {
00196                         $ilBench->start("News", "ilPDNewsBlockGUI_fillDataSection");
00197                         parent::fillDataSection();
00198                         $ilBench->stop("News", "ilPDNewsBlockGUI_fillDataSection");
00199                 }
00200                 else
00201                 {
00202                         $this->setEnableNumInfo(false);
00203                         if (count($this->getData()) == 0)
00204                         {
00205                                 $this->setEnableDetailRow(false);
00206                         }
00207                         $this->setDataSection($this->getOverview());
00208                 }
00209         }
00210 
00214         function getHTML()
00215         {
00216                 global $ilCtrl, $lng, $ilUser;
00217                 
00218                 // set footer info
00219                 $this->setFooterInfo($lng->txt("news_block_information"), true);
00220                 
00221                 $news_set = new ilSetting("news");
00222                 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
00223                 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
00224                 $allow_longer_periods = $news_set->get("allow_longer_periods");
00225                 
00226                 // subscribe/unsibscribe link
00227                 include_once("./Services/News/classes/class.ilNewsSubscription.php");
00228                 
00229                 // show feed url
00230                 if ($enable_internal_rss)
00231                 {
00232                         $this->addBlockCommand(
00233                                 $ilCtrl->getLinkTarget($this, "showFeedUrl"),
00234                                 $lng->txt("news_get_feed_url"), "", ilUtil::getImagePath("rss.gif"), true);
00235                 }
00236 
00237                 if ($allow_shorter_periods || $allow_longer_periods)
00238                 {
00239                         $this->addBlockCommand(
00240                                 $ilCtrl->getLinkTarget($this, "editSettings"),
00241                                 $lng->txt("settings"));
00242                 }
00243                         
00244                 $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
00245 
00246                 if ($per > 0)
00247                 {
00248                         switch ($per)
00249                         {
00250                                 case 2:
00251                                 case 3:
00252                                 case 5: $per_str = sprintf($lng->txt("news_period_x_days"), $per); break;
00253                                 case 7: $per_str = $lng->txt("news_period_1_week"); break;
00254                                 case 14: $per_str = sprintf($lng->txt("news_period_x_weeks"), 2); break;
00255                                 case 30: $per_str = $lng->txt("news_period_1_month"); break;
00256                                 case 60: $per_str = sprintf($lng->txt("news_period_x_months"), 2); break;
00257                                 case 120: $per_str = sprintf($lng->txt("news_period_x_months"), 4); break;
00258                                 case 180: $per_str = sprintf($lng->txt("news_period_x_months"), 6); break;
00259                                 case 366: $per_str = $lng->txt("news_period_1_year"); break;
00260                         }
00261                         if ($per_str != "")
00262                         {
00263                                 $this->setTitle($this->getTitle().' <span style="font-weight:normal;">- '.$per_str."</span>");
00264                         }
00265                 }
00266 
00267                 if ($this->getCurrentDetailLevel() == 0)
00268                 {
00269                         return "";
00270                 }
00271 
00272                 return ilBlockGUI::getHTML();
00273         }
00274         
00275 
00279         function showFeedUrl()
00280         {
00281                 global $lng, $ilCtrl, $ilUser;
00282                 
00283                 include_once("./Services/News/classes/class.ilNewsItem.php");
00284                 
00285                 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
00286                 $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
00287                 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
00288                 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
00289                 $tpl->setVariable("VAL_FEED_URL",
00290                         ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
00291                                 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
00292                 $tpl->setVariable("VAL_FEED_URL_TXT",
00293                         ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
00294                                 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
00295                 
00296                 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
00297                 $content_block = new ilPDContentBlockGUI();
00298                 $content_block->setContent($tpl->get());
00299                 $content_block->setTitle($lng->txt("news_internal_news"));
00300                 $content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
00301                 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
00302                         $lng->txt("selected_items_back"));
00303 
00304                 return $content_block->getHTML();
00305         }
00306 
00307         function addCloseCommand($a_content_block)
00308         {
00309                 global $lng, $ilCtrl;
00310                 
00311                 $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
00312                         $lng->txt("selected_items_back"));
00313         }
00314 
00315         function getDynamic()
00316         {
00317                 global $ilCtrl, $ilUser;
00318                 
00319                 if ($ilCtrl->getCmd() == "hideNotifications" ||
00320                         $ilCtrl->getCmd() == "showNotifications")
00321                 {
00322                         return false;
00323                 }
00324                 
00325                 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
00326                 {
00327                         if ($_SESSION["il_feed_js"] != "n" &&
00328                                 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
00329                         {
00330                                 // do not get feed dynamically, if cache hit is given.
00331 //                              if (!$this->feed->checkCacheHit())
00332 //                              {
00333                                         return true;
00334 //                              }
00335                         }
00336                 }
00337                 
00338                 return false;
00339         }
00340 
00341         function getDynamicReload()
00342         {
00343                 global $ilCtrl, $lng;
00344                 
00345                 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00346                         "block_pdnews_".$this->getBlockId());
00347 
00348                 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
00349                 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
00350                 $rel_tpl->setVariable("BLOCK_ID", "block_pdnews_".$this->getBlockId());
00351                 $rel_tpl->setVariable("TARGET", 
00352                         $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
00353                         
00354                 // no JS
00355                 $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
00356                 $rel_tpl->setVariable("TARGET_NO_JS",
00357                         $ilCtrl->getLinkTargetByClass("ilpdnewsblockgui", "disableJS"));
00358 
00359                 return $rel_tpl->get();
00360         }
00361         
00362         function getJSEnabler()
00363         {
00364                 global $ilCtrl, $lng;
00365                 
00366                 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00367                         "block_pdnews_".$this->getBlockId());
00368 
00369                 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
00370                 $rel_tpl->setVariable("BLOCK_ID", "block_pdnews_".$this->getBlockId());
00371                 $rel_tpl->setVariable("TARGET", 
00372                         $ilCtrl->getLinkTargetByClass("ilpdnewsblockgui", "enableJS", true));
00373                         
00374                 return $rel_tpl->get();
00375         }
00376         
00377         
00378         function disableJS()
00379         {
00380                 global $ilCtrl, $ilUser;
00381                 
00382                 $_SESSION["il_feed_js"] = "n";
00383                 $ilUser->writePref("il_feed_js", "n");
00384                 $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
00385         }
00386         
00387         function enableJS()
00388         {
00389                 global $ilUser;
00390                 
00391                 $_SESSION["il_feed_js"] = "y";
00392                 $ilUser->writePref("il_feed_js", "y");
00393                 echo $this->getHTML();
00394                 exit;
00395         }
00396         
00400         function showNews()
00401         {
00402                 // workaround for dynamic mode (if cache is disabled, showNews has no data)
00403                 if (empty(self::$st_data))
00404                 {
00405                         $this->setData($this->getNewsData());
00406                 }
00407 
00408                 return parent::showNews();
00409         }
00410 
00414         function editSettings()
00415         {
00416                 global $ilUser, $lng, $ilCtrl, $ilSetting;
00417                 
00418                 $news_set = new ilSetting("news");
00419                 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
00420                 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
00421                 $allow_longer_periods = $news_set->get("allow_longer_periods");
00422 
00423                 include_once("./Services/News/classes/class.ilNewsItem.php");
00424                 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
00425                 $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
00426                         
00427                 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
00428                 $form = new ilPropertyFormGUI();
00429                 $form->setTitle($lng->txt("news_settings"));
00430                 $form->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
00431                 
00432                 $per_opts = array(
00433                         2 => "2 ".$lng->txt("days"),
00434                         3 => "3 ".$lng->txt("days"),
00435                         5 => "5 ".$lng->txt("days"),
00436                         7 => "1 ".$lng->txt("week"),
00437                         14 => "2 ".$lng->txt("weeks"),
00438                         30 => "1 ".$lng->txt("month"),
00439                         60 => "2 ".$lng->txt("months"),
00440                         120 => "4 ".$lng->txt("months"),
00441                         180 => "6 ".$lng->txt("months"),
00442                         366 =>  "1 ".$lng->txt("year"));
00443                         
00444                 $unset = array();
00445                 foreach($per_opts as $k => $opt)
00446                 {
00447                         if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
00448                         if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
00449                 }
00450                 foreach($unset as $k)
00451                 {
00452                         unset($per_opts[$k]);
00453                 }
00454                 
00455                 $per_sel = new ilSelectInputGUI($lng->txt("news_pd_period"),
00456                         "news_pd_period");
00457                 //$per_sel->setInfo($lng->txt("news_pd_period_info"));
00458                 $per_sel->setOptions($per_opts);
00459                 $per_sel->setValue((int) $per);
00460                 $form->addItem($per_sel);
00461 
00462                 //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
00463                 //      "1", $public_feed, $lng->txt("news_public_feed_info"));
00464                 //if ($this->getProperty("public_notifications_option"))
00465                 //{
00466                 //      $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
00467                 //              "1", $public, $lng->txt("news_notifications_public_info"));
00468                 //}
00469                 $form->addCommandButton("saveSettings", $lng->txt("save"));
00470                 $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
00471                 $form->setFormAction($ilCtrl->getFormaction($this));
00472                 
00473                 return $form->getHTML();
00474         }
00475 
00479         function cancelSettings()
00480         {
00481                 global $ilCtrl;
00482                 
00483                 $ilCtrl->returnToParent($this);
00484         }
00485         
00489         function saveSettings()
00490         {
00491                 global $ilCtrl, $ilUser;
00492                 
00493                 $news_set = new ilSetting("news");
00494                 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
00495                 
00496                 ilBlockSetting::_write($this->getBlockType(), "news_pd_period",
00497                         $_POST["news_pd_period"],
00498                         $ilUser->getId(), $this->block_id);
00499                         
00500                 $ilCtrl->returnToParent($this);
00501         }
00502 
00503 }
00504 
00505 ?>

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