3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2010, Franck Villaume - Capgemini
5 * Copyright 2011-2014,2016, Franck Villaume - TrivialDev
6 * http://fusionforge.org
8 * This file is a part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
24 require_once 'Widget.class.php';
25 require_once $gfcommon.'docman/DocumentFactory.class.php';
28 * Widget_MyProjectsLastDocuments
31 class Widget_MyProjectsLastDocuments extends Widget {
32 function __construct() {
33 parent::__construct('myprojectslastdocuments');
37 return _('The 5 Last Documents in My Projects');
40 function getContent() {
41 $html_my_projects = '';
43 $user = session_get_user();
44 $groups = $user->getGroups();
46 if (count ($groups) < 1) {
47 $html_my_projects .= $HTML->warning_msg(_("You're not a member of any project"));
49 sortProjectList($groups);
50 $request = HTTPRequest::instance();
51 $vItemId = new Valid_UInt('hide_item_id');
53 if($request->valid($vItemId)) {
54 $hide_item_id = $request->get('hide_item_id');
58 $html_my_projects .= $HTML->listTableTop();
60 foreach ($groups as $g) {
61 if ($g->usesDocman()) {
64 $vWhiteList = new Valid_WhiteList('hide_dmproj', array(0, 1));
65 $vWhiteList->required();
66 if($request->valid($vWhiteList)) {
67 $hide_docmanproject = $request->get('hide_dmproj');
69 $hide_docmanproject = null;
73 $stateIdDocuments = array(1);
74 if (forge_check_perm('docman', $g->getID(), 'approve')) {
76 $stateIdDocuments = array(1, 2, 3, 4, 5);
78 $df = new DocumentFactory($g);
79 $df->setDocGroupState($stateIdDg);
80 $df->setStateID($stateIdDocuments);
82 $df->setOrder(array('updatedate', 'createdate'));
86 list($hide_now,$count_diff,$hide_url) = my_hide_url('dmproj', $g->getID(), $hide_item_id, count($df->Documents), $hide_docmanproject);
87 $html_hdr = ($i ? '<tr class="boxitem"><td colspan="4">' : '').
88 $hide_url.util_make_link('/docman/?group_id='.$g->getID(), $g->getPublicName()).
89 ' </td></tr>';
93 $keys = array_keys($df->Documents);
96 $html .= '<tr><td colspan="4">'.$HTML->warning_msg(_('No documents.')).'</td></tr>';
98 foreach ($keys as $key) {
99 $dg = new DocumentGroup($g, $key);
100 $view = ($dg->getState() != 2) ? 'listfile' : 'listtrashfile';
101 $html .= '<tr><td colspan="4">'.util_make_link('/docman/?group_id='.$g->getID().'&view='.$view.'&dirid='.$key, $dg->getPath()).'</td></tr>';
103 $count = count($df->Documents[$key]);
104 for ($i=0; $i < $count; $i++) {
105 $doc =& $df->Documents[$key][$i];
107 switch ($doc->getFileType()) {
109 $docurl = util_make_link($doc->getFileName(), html_image($doc->getFileTypeImage(), 22, 22, array('alt'=>$doc->getFileType())), array(), true);
113 $docurl = util_make_link('/docman/view.php/'.$g->getID().'/'.$doc->getID(), html_image($doc->getFileTypeImage(), 22, 22, array('alt'=>$doc->getFileType())));
116 $html .= '<td>'.$docurl.'</td>';
117 $html .= '<td>'.$doc->getFileName().'</td>';
118 $html .= '<td>'.util_display_user($doc->getCreatorUserName(), $doc->getCreatorID(), $doc->getCreatorRealName()).'</td>';
119 if ( $doc->getUpdated() ) {
120 $html .= '<td>'.date(_('Y-m-d H:i'), $doc->getUpdated()).'</td>';
122 $html .= '<td>'.date(_('Y-m-d H:i'), $doc->getCreated()).'</td>';
131 $html_my_projects .= $html_hdr.$html;
134 $html_my_projects .= $HTML->listTableBottom();
136 return $html_my_projects;
139 function getDescription() {
140 return _('List the last 5 documents (with filename, author and last modification time) published in projects you belong to. Selecting any of these projects brings you to the corresponding Project Document Manager page. The documents will be per directory ordered. Selecting any of directory links will brings you to the corresponding Project Document Manager Listing Directory page');
143 function getCategory() {
144 return _('Documents Manager');
147 function isAvailable() {
148 if (!forge_get_config('use_docman')) {
151 foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
152 if ($p->usesDocman()) {
162 // c-file-style: "bsd"