File: Widget_MyProjectsLastDocuments.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (155 lines) | stat: -rw-r--r-- 5,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
 * Copyright 2010, Franck Villaume - Capgemini
 * Copyright 2011-2013, Franck Villaume - TrivialDev
 * http://fusionforge.org
 *
 * This file is a part of FusionForge.
 *
 * FusionForge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * FusionForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
 */

require_once 'Widget.class.php';
include $gfcommon.'docman/DocumentFactory.class.php';

/**
 * Widget_MyProjectsLastDocuments
 */

class Widget_MyProjectsLastDocuments extends Widget {
	function __construct() {
		$this->Widget('myprojectslastdocuments');
	}

	function getTitle() {
		return _("The 5 Last Documents in My Projects");
	}

	function getContent() {
		$html_my_projects = '';
		global $HTML;
		$user = session_get_user();
		$groups = $user->getGroups();

		if (count ($groups) < 1) {
			$html_my_projects .= '<div class="warning">'. _("You're not a member of any project") .'</div>';
		} else {
			sortProjectList($groups);
			$request = HTTPRequest::instance();
			$vItemId = new Valid_UInt('hide_item_id');
			$vItemId->required();
			if($request->valid($vItemId)) {
				$hide_item_id = $request->get('hide_item_id');
			} else {
				$hide_item_id = null;
			}
			$html_my_projects .= '<table style="width:100%">';
			$i = 0;
			foreach ($groups as $g) {
				if ($g->usesDocman()) {
					$i++;

					$vWhiteList = new Valid_WhiteList('hide_dmproj', array(0, 1));
					$vWhiteList->required();
					if($request->valid($vWhiteList)) {
						$hide_docmanproject = $request->get('hide_dmproj');
					} else {
						$hide_docmanproject = null;
					}

					$df = new DocumentFactory($g);
					$df->setLimit(5);
					$df->setOrder(array('updatedate','createdate'));
					$df->setSort('DESC');
					$df->getDocuments();

					list($hide_now,$count_diff,$hide_url) = my_hide_url('dmproj', $g->getID(), $hide_item_id, count($df->Documents), $hide_docmanproject);
					$html_hdr = ($i ? '<tr class="boxitem"><td colspan="4">' : '').
						$hide_url.'<a href="/docman/?group_id='.$g->getID().'">'.
						$g->getPublicName().'</a>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>';

					$html = '';
					if (!$hide_now) {
						$keys = array_keys($df->Documents);
						$j = 0;
						if (!count($keys)) {
							$html .= '<tr><td colspan="4"><div class="warning">'._('No documents.').'</div></td></tr>';
						}
						foreach ($keys as $key) {
							$dg = new DocumentGroup($g, $key);
							$view = ($dg->getState() != 2) ? 'listfile' : 'listtrashfile';
							$html .= '<tr><td colspan="4"><a href="'.util_make_url('/docman/?group_id='.$g->getID().'&view='.$view.'&dirid='.$key).'">'.$dg->getPath().'</a></td></tr>';
							$j++;
							$count = count($df->Documents[$key]);
							for ($i=0; $i < $count; $i++) {
								$doc =& $df->Documents[$key][$i];
								$html .= '<tr '. $HTML->boxGetAltRowStyle($j) .'>';
								switch ($doc->getFileType()) {
									case "URL": {
										$docurl = $doc->getFileName();
										break;
									}
									default: {
										$docurl = util_make_url('/docman/view.php/'.$g->getID().'/'.$doc->getID().'/'.urlencode($doc->getFileName()));
									}
								}
								$html .= '<td><a href="'.$docurl.'">'.html_image($doc->getFileTypeImage(), '22', '22', array('alt'=>$doc->getFileType())).'</a></td>';
								$html .= '<td>'.$doc->getFilename().'</td>';
								$html .= '<td>'.make_user_link($doc->getCreatorUserName(), $doc->getCreatorRealName()).'</td>';
								if ( $doc->getUpdated() ) {
									$html .= '<td>'.date(_('Y-m-d H:i'), $doc->getUpdated()).'</td>';
								} else {
									$html .= '<td>'.date(_('Y-m-d H:i'), $doc->getCreated()).'</td>';
								}
								$html .= '</tr>';
								$j++;
							}
							$j--;
						}
					}

					$html_my_projects .= $html_hdr.$html;
				}
			}
			$html_my_projects .= '</table>';
		}
		return $html_my_projects;
	}

	function getDescription() {
		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");
	}

	function getCategory() {
		return _('Documents Manager');
	}

	function isAvailable() {
		if (!forge_get_config('use_docman')) {
			return false;
		}
		foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
			if ($p->usesDocman()) {
				return true;
			}
		}
		return false;
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: