3 * Copyright 2016-2017, Franck Villaume - TrivialDev
4 * This file is a part of Fusionforge.
6 * Fusionforge is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Fusionforge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
20 require_once 'Widget.class.php';
22 class Widget_HomeDetailActivityMostActiveProjectWeek extends Widget {
24 var $cached_perms = array();
26 function __construct() {
27 parent::__construct('homedetailactivitymostactiveprojectweek');
28 if (forge_get_config('use_activity')) {
29 $this->content['title'] = _('Detailed Activity for the 10 Most Active Projects this Week');
33 function getContent() {
36 $result = $stats->getMostActiveStats('week', 0);
39 $selected_groups = array();
40 while (($row = db_fetch_array($result)) && ($count <= 10)) {
41 $group = group_get_object($row['group_id']);
42 if (forge_check_perm('project_read', $row['group_id']) && $group->usesActivity()) {
43 $selected_groups[] = $row['group_id'];
47 $activities = array();
48 $begin = (time()-(7*86400));
50 $res = db_query_params('SELECT * FROM activity_vw WHERE activity_date BETWEEN $1 AND $2
51 AND group_id = ANY ($3) ORDER BY activity_date DESC',
52 array($begin, $end, db_int_array_to_any_clause($selected_groups)));
53 if ($res && db_numrows($res) > 0) {
54 while ($arr = db_fetch_array($res)) {
58 foreach ($selected_groups as $group_id) {
59 // If plugins wants to add activities.
60 $hookParams['group'] = $group_id;
61 $hookParams['results'] = &$activities;
62 $hookParams['begin'] = $begin;
63 $hookParams['end'] = $end;
64 plugin_hook('activity', $hookParams);
66 if (count($activities) > 0) {
67 $date_format = _('%Y-%m-%d');
68 $date_format_js = _('yy-mm-dd');
69 usort($activities, 'Widget_HomeDetailActivityMostActiveProjectWeek::date_compare');
73 foreach ($activities as $activity) {
75 if (!$this->check_perm_for_activity($activity)) {
78 if (!$displayTableTop) {
80 $theader[] = _('Time');
81 $theader[] = _('Project');
82 $theader[] = _('Activity');
85 echo $HTML->listTableTop($theader);
88 switch (@$activity['section']) {
90 $icon = html_image('ic/cvs16b.png','','',array('alt'=>_('Source Code')));
91 $url = util_make_link('/scm/'.$activity['ref_id'].$activity['subref_id'],_('scm commit')._(': ').$activity['description']);
95 $icon = $HTML->getOpenTicketPic(_('Tracker Open'), 'trackeropen');
96 $url = util_make_link('/tracker/a_follow.php/'.$activity['subref_id'],_('Tracker Item').' [#'.$activity['subref_id'].'] '.$activity['description'].' '._('Open'));
99 case 'trackerclose': {
100 $icon = $HTML->getClosedTicketPic(_('Tracker Closed'), 'trackerclose');
101 $url = util_make_link('/tracker/a_follow.php/'.$activity['subref_id'],_('Tracker Item').' [#'.$activity['subref_id'].'] '.$activity['description'].' '._('Closed'));
105 $icon = html_image('ic/cvs16b.png','','',array('alt'=>_('Files')));
106 $url = util_make_link('/frs/?release_id='.$activity['subref_id'].'&group_id='.$activity['group_id'],_('FRS Release').' '.$activity['description']);
110 $icon = html_image('ic/forum20g.png','','',array('alt'=>_('Forum')));
111 $url = util_make_link('/forum/message.php?msg_id='.$activity['subref_id'].'&group_id='.$activity['group_id'],_('Forum Post').' '.$activity['description']);
115 $icon = html_image('ic/write16w.png','','',array('alt'=>_('News')));
116 $url = util_make_link('/forum/forum.php?forum_id='.$activity['subref_id'],_('News').' '.$activity['description']);
122 $icon = html_image('ic/taskman20w.png','','',array('alt'=>_('Tasks')));
123 $url = util_make_link('/pm/t_follow.php/'.$activity['subref_id'],_('Tasks').' '.$activity['description']);
127 case 'docmanupdate': {
128 $document = document_get_object($activity['subref_id'], $activity['group_id']);
129 $stateid = $document->getStateID();
130 if ($stateid != 1 && !forge_check_perm('docman', $activity['group_id'], 'approve')) {
133 $dg = documentgroup_get_object($activity['ref_id'], $activity['group_id']);
134 if (!$dg || $dg->isError() || !$dg->getPath(true, false)) {
137 $icon = html_image('ic/docman16b.png', '', '', array('alt'=>_('Documents')));
138 $url = util_make_link($document->getPermalink(),_('Document').' '.$activity['description']);
141 case 'docgroupnew': {
142 $dg = documentgroup_get_object($activity['subref_id'], $activity['group_id']);
143 if (!$dg || $dg->isError() || !$dg->getPath(true, false)) {
146 $icon = html_image('ic/cfolder15.png', '', '', array("alt"=>_('Directory')));
147 $url = util_make_link('docman/?group_id='.$activity['group_id'].'&view=listfile&dirid='.$activity['subref_id'],_('Directory').' '.$activity['description']);
151 $icon = isset($activity['icon']) ? $activity['icon'] : '';
152 $url = '<a href="'.$activity['link'].'">'.$activity['title'].'</a>';
158 if ($last_day != strftime($date_format, $activity['activity_date'])) {
160 $cells[] = array(strftime($date_format, $activity['activity_date']), 'colspan' => 4);
161 echo $HTML->multiTableRow(array('class' => 'tableheading'), $cells, true);
162 $last_day=strftime($date_format, $activity['activity_date']);
165 $cells[][] = date('H:i:s',$activity['activity_date']);
166 $group_object = group_get_object($activity['group_id']);
168 $cells[][] = util_make_link_g($group_object->getUnixName(), $activity['group_id'], $group_object->getPublicName());
169 $cells[][] = $icon .' '.$url;
170 if (isset($activity['user_name']) && $activity['user_name']) {
171 $cells[][] = util_display_user($activity['user_name'], $activity['user_id'],$activity['realname']);
173 $cells[][] = $activity['realname'];
175 echo $HTML->multiTableRow(array('class' => $HTML->boxGetAltRowStyle($j++, true)), $cells);
177 if ($displayTableTop) {
178 echo $HTML->listTableBottom();
181 echo $HTML->information(_('No activity during the last week'));
186 function getTitle() {
187 return $this->content['title'];
190 function isAvailable() {
191 return isset($this->content['title']);
194 function date_compare($a, $b) {
195 if ($a['activity_date'] == $b['activity_date']) {
198 return ($a['activity_date'] > $b['activity_date']) ? -1 : 1;
201 function check_perm_for_activity($arr) {
202 $s = $arr['section'];
203 $ref = $arr['ref_id'];
204 $group_id = $arr['group_id'];
206 if (!isset($this->cached_perms[$s][$ref])) {
209 $this->cached_perms[$s][$ref] = forge_check_perm('scm', $group_id, 'read');
213 case 'trackerclose': {
214 $this->cached_perms[$s][$ref] = forge_check_perm('tracker', $ref, 'read');
218 $this->cached_perms[$s][$ref] = forge_check_perm('frs', $ref, 'read');
223 $this->cached_perms[$s][$ref] = forge_check_perm('forum', $ref, 'read');
229 $this->cached_perms[$s][$ref] = forge_check_perm('pm', $ref, 'read');
234 case 'docgroupnew': {
235 $this->cached_perms[$s][$ref] = forge_check_perm('docman', $group_id, 'read');
239 // Must be a bug somewhere, we're supposed to handle all types
240 $this->cached_perms[$s][$ref] = false;
244 return $this->cached_perms[$s][$ref];