00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 class ilPDNewsGUI
00036 {
00037
00043 function ilPDNewsGUI()
00044 {
00045 global $tpl, $lng, $ilCtrl;
00046
00047
00048 $this->tpl =& $tpl;
00049 $this->lng =& $lng;
00050 $this->ctrl =& $ilCtrl;
00051
00052 $lng->loadLanguageModule("news");
00053
00054 $this->ctrl->saveParameter($this, "news_ref_id");
00055 }
00056
00060 function &executeCommand()
00061 {
00062 $next_class = $this->ctrl->getNextClass();
00063
00064 switch($next_class)
00065 {
00066
00067 default:
00068 $cmd = $this->ctrl->getCmd("view");
00069 $this->displayHeader();
00070 $this->$cmd();
00071 break;
00072 }
00073 $this->tpl->show(true);
00074 return true;
00075 }
00076
00080 function displayHeader()
00081 {
00082 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
00083 $this->lng->txt("personal_desktop"));
00084 $this->tpl->setTitle($this->lng->txt("personal_desktop"));
00085
00086
00087 ilUtil::sendInfo();
00088
00089 ilUtil::infoPanel();
00090 }
00091
00092
00093
00094
00095 function view()
00096 {
00097 global $ilUser, $lng, $tpl, $ilCtrl;
00098
00099 $news_tpl = new ilTemplate("tpl.pd_news.html", true, true, "Services/News");
00100
00101 include_once("Services/News/classes/class.ilNewsSubscription.php");
00102 include_once("Services/News/classes/class.ilNewsItem.php");
00103
00104
00105 $per = ($_SESSION["news_pd_news_per"] != "")
00106 ? $_SESSION["news_pd_news_per"]
00107 : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
00108 $news_set = new ilSetting("news");
00109 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
00110 $allow_longer_periods = $news_set->get("allow_longer_periods");
00111 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
00112
00113 $per_opts = array(
00114 2 => sprintf($lng->txt("news_period_x_days"), 2),
00115 3 => sprintf($lng->txt("news_period_x_days"), 3),
00116 5 => sprintf($lng->txt("news_period_x_days"), 5),
00117 7 => $lng->txt("news_period_1_week"),
00118 14 => sprintf($lng->txt("news_period_x_weeks"), 2),
00119 30 => $lng->txt("news_period_1_month"),
00120 60 => sprintf($lng->txt("news_period_x_months"), 2),
00121 120 => sprintf($lng->txt("news_period_x_months"), 4),
00122 180 => sprintf($lng->txt("news_period_x_months"), 6),
00123 366 => $lng->txt("news_period_1_year"));
00124
00125 $unset = array();
00126 foreach($per_opts as $k => $opt)
00127 {
00128 if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
00129 if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
00130 }
00131 foreach($unset as $k)
00132 {
00133 unset($per_opts[$k]);
00134 }
00135 foreach($per_opts as $k => $v)
00136 {
00137 $news_tpl->setCurrentBlock("per_option");
00138 $news_tpl->setVariable("VAL_PER", $k);
00139 $news_tpl->setVariable("TXT_PER", $v);
00140 if ($k == $per)
00141 {
00142 $news_tpl->setVariable("SEL_PER", ' selected="selected" ');
00143 }
00144 $news_tpl->parseCurrentBlock();
00145 }
00146
00147 $ref_ids = array();
00148 $obj_ids = array();
00149
00150
00151 $pd_items = $ilUser->getDesktopItems();
00152 foreach($pd_items as $item)
00153 {
00154 $ref_ids[] = $item["ref_id"];
00155 $obj_ids[] = $item["obj_id"];
00156 }
00157
00158
00159 $sel_ref_id = ($_GET["news_ref_id"] > 0)
00160 ? $_GET["news_ref_id"]
00161 : $ilUser->getPref("news_sel_ref_id");
00162
00163 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
00164
00165
00166 $news_tpl->setCurrentBlock("related_option");
00167 $news_tpl->setVariable("VAL_RELATED", "0");
00168 $news_tpl->setVariable("TXT_RELATED", $lng->txt("news_all_items"));
00169 $news_tpl->parseCurrentBlock();
00170
00171 $conts = array();
00172 $sel_has_news = false;
00173 foreach ($ref_ids as $ref_id)
00174 {
00175 $obj_id = ilObject::_lookupObjId($ref_id);
00176 $title = ilObject::_lookupTitle($obj_id);
00177
00178
00179
00180 $conts[$ref_id] = $title;
00181 if ($sel_ref_id == $ref_id)
00182 {
00183 $sel_has_news = true;
00184 }
00185
00186 }
00187
00188 $cnt = array();
00189 $nitem = new ilNewsItem();
00190 $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false,
00191 true, $per, $cnt);
00192
00193
00194 if (!$sel_has_news)
00195 {
00196 $sel_ref_id = "";
00197 }
00198 asort($conts);
00199 foreach($conts as $ref_id => $title)
00200 {
00201 $news_tpl->setCurrentBlock("related_option");
00202 $news_tpl->setVariable("VAL_RELATED", $ref_id);
00203 $news_tpl->setVariable("TXT_RELATED", $title." (".(int) $cnt[$ref_id].")");
00204 if ($sel_ref_id == $ref_id)
00205 {
00206 $news_tpl->setVariable("SEL", ' selected="selected" ');
00207 }
00208 $news_tpl->parseCurrentBlock();
00209 }
00210
00211 $news_tpl->setCurrentBlock("related_selection");
00212 $news_tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
00213 $news_tpl->setVariable("TXT_RELATED_TO", $lng->txt("news_related_to"));
00214 $news_tpl->setVariable("TXT_CHANGE", $lng->txt("change"));
00215 $news_tpl->parseCurrentBlock();
00216
00217 if ($sel_ref_id > 0)
00218 {
00219 $obj_id = ilObject::_lookupObjId($sel_ref_id);
00220 $obj_type = ilObject::_lookupType($obj_id);
00221 $nitem->setContextObjId($obj_id);
00222 $nitem->setContextObjType($obj_type);
00223 $news_items = $nitem->getNewsForRefId($sel_ref_id, false,
00224 false, $per, true);
00225 }
00226
00227 include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
00228 $pd_news_table = new ilPDNewsTableGUI($this, "view");
00229 $pd_news_table->setData($news_items);
00230
00231 if (count($news_items) > 0)
00232 {
00233 $news_tpl->setVariable("NEWS", $pd_news_table->getHTML());
00234 }
00235 else
00236 {
00237 $news_tpl->setCurrentBlock("no_news");
00238 $news_tpl->setVariable("NO_NEWS", $lng->txt("news_no_news_items"));
00239 $news_tpl->parseCurrentBlock();
00240 }
00241
00242 $tpl->setContent($news_tpl->get());
00243 }
00244
00248 function changeRelatedObject()
00249 {
00250 global $ilUser;
00251
00252 $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
00253 $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
00254 if ($_POST["news_per"] > 0)
00255 {
00256 $_SESSION["news_pd_news_per"] = $_POST["news_per"];
00257 }
00258 $this->ctrl->redirect($this, "view");
00259 }
00260
00261 }
00262 ?>