5 * Copyright 2017,2018, Franck Villaume - TrivialDev
6 * http://fusionforge.org/
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
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 along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 class Activity extends FFError {
26 //No constructor. Inherit from FFError.
27 function check_perm_for_activity($arr, &$cached_perms) {
29 $ref = $arr['ref_id'];
30 $group_id = $arr['group_id'];
32 if (!isset($cached_perms[$s][$ref])) {
35 $cached_perms[$s][$ref] = forge_check_perm('scm', $group_id, 'read');
39 case 'trackerclose': {
40 $cached_perms[$s][$ref] = forge_check_perm('tracker', $ref, 'read');
44 $cached_perms[$s][$ref] = forge_check_perm('frs', $ref, 'read');
49 $cached_perms[$s][$ref] = forge_check_perm('forum', $ref, 'read');
55 $cached_perms[$s][$ref] = forge_check_perm('pm', $ref, 'read');
61 $cached_perms[$s][$ref] = forge_check_perm('docman', $group_id, 'read');
65 $cached_perms[$s][$ref] = forge_check_perm('plugin_mediawiki_read', $group_id, 'read');
69 if ($arr['subref_id']) {
70 $cached_perms[$s][$ref] = true;
72 $cached_perms[$s][$ref] = false;
77 // Must be a bug somewhere, we're supposed to handle all types
78 $cached_perms[$s][$ref] = false;
82 return $cached_perms[$s][$ref];
85 static function date_compare($a, $b) {
86 if ($a['activity_date'] == $b['activity_date']) {
89 return ($a['activity_date'] > $b['activity_date']) ? -1 : 1;
92 function getDisplayInfo($arr) {
95 switch (@$arr['section']) {
97 $icon = $HTML->getScmPic(_('Source Code'), _('Source Code'));
98 $url = util_make_link('/scm/'.$arr['ref_id'].$arr['subref_id'],_('scm commit')._(': ').$arr['description']);
101 case 'trackeropen': {
102 $icon = $HTML->getOpenTicketPic(_('Tracker Open'), _('Tracker Open'));
103 $url = util_make_link('/tracker/a_follow.php/'.$arr['subref_id'],_('Tracker Item').' [#'.$arr['subref_id'].'] '.$arr['description'].' '._('Opened'));
106 case 'trackerclose': {
107 $icon = $HTML->getClosedTicketPic(_('Tracker Closed'), _('Tracker Closed'));
108 $url = util_make_link('/tracker/a_follow.php/'.$arr['subref_id'],_('Tracker Item').' [#'.$arr['subref_id'].'] '.$arr['description'].' '._('Closed'));
112 $icon = $HTML->getPackagePic(_('Files'), _('Files'));
113 $url = util_make_link('/frs/?release_id='.$arr['subref_id'].'&group_id='.$arr['group_id'],_('FRS Release').' '.$arr['description']);
117 $icon = $HTML->getForumPic(_('Forum'), _('Forum'));
118 $url = util_make_link('/forum/message.php?msg_id='.$arr['subref_id'].'&group_id='.$arr['group_id'],_('Forum Post').' '.$arr['description']);
122 $icon = $HTML->getNewsPic(_('News'), _('News'));
123 $url = util_make_link('/forum/forum.php?forum_id='.$arr['subref_id'],_('News').' '.$arr['description']);
127 $icon = $HTML->getPmPic(_('Open Task'), _('Open Task'));
128 $url = util_make_link('/pm/t_follow.php/'.$arr['subref_id'],_('Tasks').' '.$arr['description']);
132 $icon = $HTML->getPmPic(_('Closed Task'), _('Closed Task'));
133 $url = util_make_link('/pm/t_follow.php/'.$arr['subref_id'],_('Tasks').' '.$arr['description']);
138 $icon = $HTML->getPmPic(_('Deleted Task'), _('Deleted Task'));
139 $url = util_make_link('/pm/t_follow.php/'.$arr['subref_id'],_('Tasks').' '.$arr['description']);
143 case 'docmanupdate': {
144 $document = document_get_object($arr['subref_id'], $arr['group_id']);
145 $stateid = $document->getStateID();
146 if ($stateid != 1 && !forge_check_perm('docman', $arr['group_id'], 'approve')) {
150 $dg = documentgroup_get_object($arr['ref_id'], $arr['group_id']);
151 if (!$dg || $dg->isError() || !$dg->getPath(true, false)) {
155 $icon = html_image($document->getFileTypeImage(), 22, 22, array('alt' => $document->getFileType()));
156 $url = util_make_link($document->getPermalink(),_('Document').' '.$arr['description']);
159 case 'docgroupnew': {
160 $dg = documentgroup_get_object($arr['subref_id'], $arr['group_id']);
161 if (!$dg || $dg->isError() || !$dg->getPath(true, false)) {
165 $icon = $HTML->getFolderPic(_('Directory'), 'directory');
166 if ($dg->getState() == 2) {
167 $view = 'listtrashfile';
171 $url = util_make_link('/docman/?group_id='.$arr['group_id'].'&view='.$view.'&dirid='.$arr['subref_id'],_('Directory').' '.$arr['description']);
176 $url = util_make_link('/developer/?diary_id='.$arr['ref_id'].'&diary_user='.$arr['user_id'].'&view=detail', $arr['description']);
180 $icon = isset($arr['icon']) ? $arr['icon'] : '';
181 $url = '<a href="'.$arr['link'].'">'.$arr['title'].'</a>';
187 return html_e('div', array('class' => 'box'), $icon .' '.$url);
190 function getActivitiesForProject($group_id, $begin, $end, $section) {
191 $res = db_query_params('SELECT * FROM activity_vw WHERE activity_date BETWEEN $1 AND $2
192 AND group_id = $3 AND section = ANY ($4) ORDER BY activity_date DESC',
196 db_string_array_to_any_clause($section)));
199 $this->setError(db_error());
204 while ($arr = db_fetch_array($res)) {
210 function getActivitiesForProjects($selected_groups, $begin, $end) {
211 $activities = array();
212 $res = db_query_params('SELECT * FROM activity_vw WHERE activity_date BETWEEN $1 AND $2
213 AND group_id = ANY ($3) ORDER BY activity_date DESC',
214 array($begin, $end, db_int_array_to_any_clause($selected_groups)));
215 if ($res && db_numrows($res) > 0) {
216 while ($arr = db_fetch_array($res)) {
217 $activities[] = $arr;
223 function getActivitiesForUser($user_id, $begin, $end, $section) {
224 $activities = array();
225 $res = db_query_params('SELECT * FROM activity_vw WHERE activity_date BETWEEN $1 AND $2
226 AND user_id = $3 AND section = ANY ($4) ORDER BY activity_date DESC',
230 db_string_array_to_any_clause($section)));
231 if ($res && db_numrows($res) > 0) {
232 while ($arr = db_fetch_array($res)) {
233 $activities[] = $arr;
239 function getActivitiesForUsers($selected_users, $begin, $end) {
240 $activities = array();
241 $res = db_query_params('SELECT * FROM activity_vw WHERE activity_date BETWEEN $1 AND $2
242 AND user_id = ANY ($3) ORDER BY activity_date DESC',
243 array($begin, $end, db_int_array_to_any_clause($selected_users)));
244 if ($res && db_numrows($res) > 0) {
245 while ($arr = db_fetch_array($res)) {
246 $activities[] = $arr;