3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012, Franck Villaume - TrivialDev
6 * This file is a part of Fusionforge.
8 * Fusionforge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Fusionforge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'Widget.class.php';
25 * Widget_ProjectDocumentsActivity
28 class Widget_ProjectDocumentsActivity extends Widget {
31 function __construct() {
32 $this->Widget('projectdocumentsactivity');
33 if (session_loggedin()) {
34 $this->_statistic_show = UserManager::instance()->getCurrentUser()->getPreference('my_docman_project_activitity_show');
36 $this->_statistic_show = 'FUD';
38 $request =& HTTPRequest::instance();
39 $pm = ProjectManager::instance();
40 $project = $pm->getProject($request->get('group_id'));
41 if ($project && $this->canBeUsedByProject($project) && forge_check_perm('docman', $project->getID(), 'read')) {
42 $this->content['title'] = _('Last 4 weeks Documents Manager Activity');
46 function hasPreferences() {
47 if (session_loggedin()) {
53 function updatePreferences(&$request) {
54 $request->valid(new Valid_String('cancel'));
55 $vShow = new Valid_WhiteList('show', array('F', 'D', 'U', 'FU', 'FD', 'FUD'));
57 if (!$request->exist('cancel')) {
58 if ($request->valid($vShow)) {
59 switch($request->get('show')) {
61 $this->_statistic_show = 'F';
64 $this->_statistic_show = 'D';
67 $this->_statistic_show = 'U';
70 $this->_statistic_show = 'FU';
73 $this->_statistic_show = 'FD';
77 $this->_statistic_show = 'FUD';
79 UserManager::instance()->getCurrentUser()->setPreference('my_docman_project_activitity_show', $this->_statistic_show);
85 function getPreferences() {
86 $optionsArray = array('F', 'D', 'U', 'FU', 'FD', 'FUD');
87 $textsArray = array();
88 $textsArray[] = _('new files'.' [F]');
89 $textsArray[] = _('new directories'.' [D]');
90 $textsArray[] = _('updated files'.' [U]');
91 $textsArray[] = _('new and update Files'.' [FU]');
92 $textsArray[] = _('new files and directories'.' [FD]');
93 $textsArray[] = _('new and update files and directories'.' [FUD]');
94 $prefs = _("Display statistics:").html_build_select_box_from_arrays($optionsArray, $textsArray, "show", $this->_statistic_show);
98 function getContent() {
99 require_once $GLOBALS['gfcommon'].'docman/DocumentManager.class.php';
101 html_use_jqueryjqplotpluginBar();
102 echo $HTML->getJavascripts();
103 echo $HTML->getStylesheets();
104 $request =& HTTPRequest::instance();
105 $group_id = $request->get('group_id');
106 $group = group_get_object($group_id);
107 $dm = new DocumentManager($group);
108 $begin1 = strtotime('monday this week');
110 $begin2 = strtotime('-1 week', $begin1);
112 $begin3 = strtotime('-1 week', $begin2);
114 $begin4 = strtotime('-1 week', $begin3);
116 $sections = array('docmannew', 'docgroupnew', 'docmanupdate');
117 $activitysArray[] = $dm->getActivity($sections, $begin4, $end4);
118 $activitysArray[] = $dm->getActivity($sections, $begin3, $end3);
119 $activitysArray[] = $dm->getActivity($sections, $begin2, $end2);
120 $activitysArray[] = $dm->getActivity($sections, $begin1, $end1);
121 echo '<script type="text/javascript">//<![CDATA['."\n";
122 switch($this->_statistic_show) {
124 echo 'var s1 = ['.$activitysArray[0]['docmannew'].', '.$activitysArray[1]['docmannew'].', '.$activitysArray[2]['docmannew'].', '.$activitysArray[3]['docmannew'].'];';
125 echo 'var series = [s1];';
126 echo 'var labels = [{label:\''._('new Files').'\'}];';
129 echo 'var s2 = ['.$activitysArray[0]['docmanupdate'].', '.$activitysArray[1]['docmanupdate'].', '.$activitysArray[2]['docmanupdate'].', '.$activitysArray[3]['docmanupdate'].'];';
130 echo 'var series = [s2];';
131 echo 'var labels = [{label:\''._('updated Files').'\'}];';
135 echo 'var s3 = ['.$activitysArray[0]['docgroupnew'].', '.$activitysArray[1]['docgroupnew'].', '.$activitysArray[2]['docgroupnew'].', '.$activitysArray[3]['docgroupnew'].'];';
136 echo 'var series = [s3];';
137 echo 'var labels = [{label:\''._('new Directories').'\'}];';
141 echo 'var s1 = ['.$activitysArray[0]['docmannew'].', '.$activitysArray[1]['docmannew'].', '.$activitysArray[2]['docmannew'].', '.$activitysArray[3]['docmannew'].'];';
142 echo 'var s2 = ['.$activitysArray[0]['docmanupdate'].', '.$activitysArray[1]['docmanupdate'].', '.$activitysArray[2]['docmanupdate'].', '.$activitysArray[3]['docmanupdate'].'];';
143 echo 'var series = [s1, s2];';
144 echo 'var labels = [{label:\''._('new Files').'\'},
145 {label:\''._('updated Files').'\'}];';
149 echo 'var s1 = ['.$activitysArray[0]['docmannew'].', '.$activitysArray[1]['docmannew'].', '.$activitysArray[2]['docmannew'].', '.$activitysArray[3]['docmannew'].'];';
150 echo 'var s3 = ['.$activitysArray[0]['docgroupnew'].', '.$activitysArray[1]['docgroupnew'].', '.$activitysArray[2]['docgroupnew'].', '.$activitysArray[3]['docgroupnew'].'];';
151 echo 'var series = [s1, s3];';
152 echo 'var labels = [{label:\''._('new Files').'\'},
153 {label:\''._('new Directories').'\'}];';
157 echo 'var s1 = ['.$activitysArray[0]['docmannew'].', '.$activitysArray[1]['docmannew'].', '.$activitysArray[2]['docmannew'].', '.$activitysArray[3]['docmannew'].'];';
158 echo 'var s2 = ['.$activitysArray[0]['docmanupdate'].', '.$activitysArray[1]['docmanupdate'].', '.$activitysArray[2]['docmanupdate'].', '.$activitysArray[3]['docmanupdate'].'];';
159 echo 'var s3 = ['.$activitysArray[0]['docgroupnew'].', '.$activitysArray[1]['docgroupnew'].', '.$activitysArray[2]['docgroupnew'].', '.$activitysArray[3]['docgroupnew'].'];';
160 echo 'var series = [s1, s2, s3];';
161 echo 'var labels = [{label:\''._('new Files').'\'},
162 {label:\''._('updated Files').'\'},
163 {label:\''._('new Directories').'\'}];';
167 echo 'var ticks = [\''._('3 weeks ago').'\', \''._('2 weeks ago').'\', \''._('Last Week').'\', \''._('Current Week').'\'];';
169 echo 'jQuery(document).ready(function(){
170 plot1 = jQuery.jqplot(\'chart1\', series, {
172 renderer:jQuery.jqplot.BarRenderer,
173 rendererOptions: {fillToZero: true}
180 placement: \'insideGrid\',
185 renderer: jQuery.jqplot.CategoryAxisRenderer,
191 echo 'jQuery(window).resize(function() {
192 plot1.replot( { resetAxes: true } );
194 echo '//]]></script>';
195 echo '<div id="chart1"></div>';
196 echo '<div class="underline-link">' . util_make_link('/docman/?group_id='.$group_id, _('Browse Documents Manager')) . '</div>';
199 function getTitle() {
200 return $this->content['title'];
203 function isAvailable() {
204 return isset($this->content['title']);
207 function canBeUsedByProject(&$project) {
208 return $project->usesDocman();
211 function getCategory() {
212 return 'Documents-Manager';
215 function getDescription() {
216 return _(' Display activity about Document Manager (new documents, new edit, new directory ...) during the last 4 weeks.');