3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012-2015, Franck Villaume - TrivialDev
5 * Copyright (C) 2014 Alain Peyrat - Alcatel-Lucent
7 * This file is a part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
23 require_once 'Widget.class.php';
24 require_once $gfwww.'include/my_utils.php';
25 require_once $gfcommon.'include/MonitorElement.class.php';
28 * Widget_MyMonitoredForums
30 * Forums that are actively monitored
33 class Widget_MyMonitoredForums extends Widget {
34 function __construct() {
35 parent::__construct('mymonitoredforums');
39 return _('Monitored Forums');
42 function getContent() {
44 $html_my_monitored_forums = '';
45 $monitorElementObject = new MonitorElement('forum');
46 $distinctMonitorGroupIdsArray = $monitorElementObject->getMonitoredDistinctGroupIdsByUserIdInArray(user_getid());
47 if (!$distinctMonitorGroupIdsArray || count($distinctMonitorGroupIdsArray) < 1) {
48 $html_my_monitored_forums .= $HTML->warning_msg(_('You are not monitoring any forums.')).html_e('p', array(), _("If you monitor forums, you will be sent new posts in the form of an email, with a link to the new message.")).html_e('p', array(), _("You can monitor forums by clicking on the appropriate menu item in the discussion forum itself."));
50 $validDistinctMonitorGroupIdsArray = array();
51 foreach ($distinctMonitorGroupIdsArray as $distinctMonitorGroupId) {
52 if (forge_check_perm('project_read', $distinctMonitorGroupId)) {
53 $validDistinctMonitorGroupIdsArray[] = $distinctMonitorGroupId;
55 // Oh ho! we found some monitored elements where user has no read access. Let's clean the situation
56 $monitorElementObject->disableMonitoringForGroupIdByUserId($distinctMonitorGroupId, user_getid());
59 if (count($validDistinctMonitorGroupIdsArray)) {
60 $request =& HTTPRequest::instance();
61 $vItemId = new Valid_UInt('hide_item_id');
63 if ($request->valid($vItemId)) {
64 $hide_item_id = $request->get('hide_item_id');
68 $vForum = new Valid_WhiteList('hide_forum', array(0, 1));
70 if ($request->valid($vForum)) {
71 $hide_forum = $request->get('hide_forum');
75 $setListTableTop = true;
76 foreach ($validDistinctMonitorGroupIdsArray as $validDistinctMonitorGroupId) {
77 $groupObject = group_get_object($validDistinctMonitorGroupId);
78 $monitoredForumIdsArray = $monitorElementObject->getMonitoredIdsByGroupIdByUserIdInArray($validDistinctMonitorGroupId, user_getid());
79 $validMonitoredForumIds = array();
80 foreach ($monitoredForumIdsArray as $monitoredForumId) {
81 if (forge_check_perm('forum', $monitoredForumId, 'read')) {
82 $validMonitoredForumIds[] = $monitoredForumId;
84 // Oh ho! we found some monitored elements where user has no read access. Let's clean the situation
85 $monitorElementObject->disableMonitoringByUserId($monitoredForumId, user_getid());
88 if (count($validMonitoredForumIds)) {
89 if ($setListTableTop) {
90 $html_my_monitored_forums .= $HTML->listTableTop();
91 $setListTableTop = false;
94 list($hide_now, $count_diff, $hide_url) = my_hide_url('forum', $validDistinctMonitorGroupId, $hide_item_id, count($validMonitoredForumIds), $hide_forum);
95 $count_new = max(0, $count_diff);
97 $cells[] = array($hide_url.util_make_link('/forum/?group_id='.$validDistinctMonitorGroupId, $groupObject->getPublicName()).' ['.count($validMonitoredForumIds).($count_new ? ', '.html_e('b', array(), sprintf(_('%s new'), $count_new)).']' : ']'), 'colspan' => 2);
98 $html_hdr = $HTML->multiTableRow(array('class' => 'boxitem'), $cells);
101 foreach ($validMonitoredForumIds as $key => $validMonitoredForumId) {
102 $forumObject = forum_get_object($validMonitoredForumId);
104 $cells[] = array(' - '.util_make_link('/forum/forum.php?forum_id='.$validMonitoredForumId, $forumObject->getName()), 'style' => 'width:99%');
105 $cells[] = array(util_make_link('/forum/monitor.php?forum_id='.$validMonitoredForumId.'&group_id='.$groupObject->getID().'&stop=1',
106 $HTML->getDeletePic(_('Stop monitoring'), _('Stop monitoring'), array('onClick' => 'return confirm("'._('Stop monitoring this forum?').'")'))),
107 'class' => 'align-center');
108 $html .= $HTML->multiTableRow(array(), $cells);
111 $html_my_monitored_forums .= $html_hdr.$html;
113 $html_my_monitored_forums .= $HTML->warning_msg(_('You are not monitoring any forums.')).html_e('p', array(), _("If you monitor forums, you will be sent new posts in the form of an email, with a link to the new message.")).html_e('p', array(), _("You can monitor forums by clicking on the appropriate menu item in the discussion forum itself."));
115 if (!$setListTableTop) {
116 $html_my_monitored_forums .= $HTML->listTableBottom();
117 $html_my_monitored_forums .= html_e('p', array(), _('Detailed page about monitored forums')._(': ').util_make_link('/forum/myforums.php', _('Here')));
121 $html_my_monitored_forums .= $HTML->warning_msg(_('You are not monitoring any forums.')).html_e('p', array(), _("If you monitor forums, you will be sent new posts in the form of an email, with a link to the new message.")).html_e('p', array(), _("You can monitor forums by clicking on the appropriate menu item in the discussion forum itself."));
124 return $html_my_monitored_forums;
127 function getCategory() {
131 function getDescription() {
132 return _("List forums that you are currently monitoring, by project.")
134 . _("To cancel any of the monitored items just click on the trash icon next to the item label.");
141 function getAjaxUrl($owner_id, $owner_type) {
142 $request =& HTTPRequest::instance();
143 $ajax_url = parent::getAjaxUrl($owner_id, $owner_type);
144 if ($request->exist('hide_item_id') || $request->exist('hide_forum')) {
145 $ajax_url .= '&hide_item_id='.$request->get('hide_item_id').'&hide_forum='.$request->get('hide_forum');
150 function isAvailable() {
151 if (!forge_get_config('use_forum')) {
154 foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
155 if ($p->usesForum()) {