3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012-2013, Franck Villaume - TrivialDev
5 * Copyright 2013, French Ministry of Education
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.'include/utils.php';
26 require_once $gfwww.'include/html.php';
27 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
28 require_once $gfcommon.'tracker/ArtifactsForUser.class.php';
29 require_once $gfcommon.'tracker/Artifact.class.php';
30 require_once $gfcommon.'tracker/ArtifactFile.class.php';
31 require_once $gfcommon.'tracker/ArtifactType.class.php';
32 require_once $gfcommon.'tracker/ArtifactCanned.class.php';
37 * Artifact assigned to or submitted by or monitored by this person
40 class Widget_MyArtifacts extends Widget {
42 function __construct() {
43 $this->Widget('myartifacts');
44 $this->_artifact_show = UserManager::instance()->getCurrentUser()->getPreference('my_artifacts_show');
45 if($this->_artifact_show === false) {
46 $this->_artifact_show = 'ASM';
47 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
52 return _('My Artifacts');
55 function updatePreferences(&$request) {
56 $request->valid(new Valid_String('cancel'));
57 $vShow = new Valid_WhiteList('show', array('A', 'S', 'M', 'N', 'AS', 'AM', 'SM', 'ASM'));
59 if (!$request->exist('cancel')) {
60 if ($request->valid($vShow)) {
61 switch($request->get('show')) {
63 $this->_artifact_show = 'A';
66 $this->_artifact_show = 'S';
69 $this->_artifact_show = 'M';
72 $this->_artifact_show = 'N';
75 $this->_artifact_show = 'AS';
78 $this->_artifact_show = 'AM';
81 $this->_artifact_show = 'SM';
85 $this->_artifact_show = 'ASM';
87 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
93 function hasPreferences() {
97 function getPreferences() {
98 $optionsArray = array('A','S','M','AS','AM','SM', 'ASM');
99 $textsArray = array();
100 $textsArray[] = _('assigned to me'.' [A]');
101 $textsArray[] = _('submitted by me'.' [S]');
102 $textsArray[] = _('monitored by me'.' [M]');
103 $textsArray[] = _('assigned to or submitted by me'.' [AS]');
104 $textsArray[] = _('assigned to or monitored by me'.' [AM]');
105 $textsArray[] = _('submitted by or monitored by me'.' [SM]');
106 $textsArray[] = _('assigned to or submitted by or monitored by me'.' [ASM]');
107 $prefs = _('Display artifacts:').html_build_select_box_from_arrays($optionsArray, $textsArray, 'show', $this->_artifact_show);
111 function getContent() {
113 $atf = new ArtifactsForUser(@UserManager::instance()->getCurrentUser());
114 $my_artifacts = array();
115 if ($this->_artifact_show == 'ASM'){
116 $my_artifacts = $atf->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av where (av.submitted_by=$1 OR av.assigned_to=$1 OR av.artifact_id IN (select artifact_monitor.artifact_id FROM artifact_monitor WHERE artifact_monitor.user_id = $1)) AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',array( UserManager::instance()->getCurrentUser()->getID()));
118 if ($this->_artifact_show == 'AS'){
119 $my_artifacts = $atf->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av where (av.submitted_by=$1 OR av.assigned_to=$1) AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',array( UserManager::instance()->getCurrentUser()->getID()));
121 if ($this->_artifact_show == 'AM'){
122 $my_artifacts = $atf->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av where (av.assigned_to=$1 OR av.artifact_id IN (select artifact_monitor.artifact_id FROM artifact_monitor WHERE artifact_monitor.user_id = $1)) AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',array( UserManager::instance()->getCurrentUser()->getID()));
124 if ($this->_artifact_show == 'SM'){
125 $my_artifacts = $atf->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av where (av.submitted_by=$1 OR av.artifact_id IN (select artifact_monitor.artifact_id FROM artifact_monitor WHERE artifact_monitor.user_id = $1)) AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',array( UserManager::instance()->getCurrentUser()->getID()));
127 if ($this->_artifact_show== 'S') {
128 $my_artifacts = $atf->getSubmittedArtifactsByGroup();
130 if ($this->_artifact_show== 'A') {
131 $my_artifacts = $atf->getAssignedArtifactsByGroup();
133 if ($this->_artifact_show== 'M') {
134 $my_artifacts = $atf->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av where (av.artifact_id IN (select artifact_monitor.artifact_id FROM artifact_monitor WHERE artifact_monitor.user_id = $1)) AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',array( UserManager::instance()->getCurrentUser()->getID()));;
137 if (count($my_artifacts) > 0) {
138 $html_my_artifacts = $HTML->listTableTop(array());
139 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 1);
140 $html_my_artifacts .= $HTML->listTableBottom();
142 $html_my_artifacts = $HTML->information(_('You have no artifacts.'));
145 return $html_my_artifacts;
148 function _display_artifacts($list_trackers, $print_box_begin) {
150 $request = HTTPRequest::instance();
151 $vItemId = new Valid_UInt('hide_item_id');
152 $vItemId->required();
153 if($request->valid($vItemId)) {
154 $hide_item_id = $request->get('hide_item_id');
156 $hide_item_id = null;
159 $vArtifact = new Valid_WhiteList('hide_artifact', array(0, 1));
160 $vArtifact->required();
161 if($request->valid($vArtifact)) {
162 $hide_artifact = $request->get('hide_artifact');
164 $hide_artifact = null;
167 $j = $print_box_begin;
168 $html_my_artifacts = '';
179 $artifact_types = array();
182 $pm = ProjectManager::instance();
183 foreach ($list_trackers as $trackers_array ) {
184 $atid = $trackers_array->getArtifactType()->getID();
185 $group_id = $trackers_array->getArtifactType()->getGroup()->getID();
188 $group = $pm->getProject($group_id);
189 if (!$group || !is_object($group) || $group->isError()) {
192 //Check if user can view artifact
193 if (forge_check_perm ('tracker', $trackers_array->getArtifactType()->getID(), 'read')) {
195 //work on the tracker of the last round if there was one
196 if ($atid != $atid_old && $count_aids != 0) {
197 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact', $atid_old, $hide_item_id, $count_aids, $hide_artifact);
198 $count_new = max(0, $count_diff);
200 $cells[] = array($hide_url.
201 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('title'=>_('Browse Trackers List for this project'))).
203 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('title'=>_('Browse this tracker for this project'))).
205 my_item_count($count_aids,$count_new), 'colspan' => 3);
206 $html_my_artifacts .= $HTML->multiTableRow(array('class' => 'boxitem'), $cells).$html;
213 if ($count_aids == 0) {
214 //have to call it to get at least the hide_now even if count_aids is false at this point
215 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
218 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
219 $tracker_name = $trackers_array->ArtifactType->getName();
220 $aid = $trackers_array->getID();
221 $summary = $trackers_array->getSummary();
223 $group_id_old = $group_id;
225 // If user is assignee and submitter of an artifact, it will
226 // appears 2 times in the result set.
227 if($aid != $aid_old) {
231 if (!$hide_now && $aid != $aid_old) {
233 // Form the 'Submitted by/Assigned/Monitored_by to flag' for marking
236 if($trackers_array->getAssignedTo()== user_getid()) {
238 $AS_title .= _('Assigned');
240 if ($trackers_array->getSubmittedBy()== user_getid()) {
242 if (strlen($AS_title))
244 $AS_title .= _('Submitted');
246 if ($trackers_array->isMonitoring()) {
248 if (strlen($AS_title))
250 $AS_title .= _('Monitored');
252 if (!strlen($AS_flag)) {
258 $cells[] = array($trackers_array->getPriority(), 'class' => 'priority'.$trackers_array->getPriority());
259 $cells[][] = util_make_link('/tracker/?func=detail&group_id='.$group_id.'&aid='.$aid.'&atid='.$atid, stripslashes($summary), array('title' => _('Browse this artifact')));
260 $cells[] = array($AS_flag, 'title' => $AS_title, 'class' => 'small');
261 $html .= $HTML->multiTableRow(array('class' => $HTML->boxGetAltRowStyle($count_aids, true)), $cells);
267 //work on the tracker of the last round if there was one
268 if ($atid_old != 0 && $count_aids != 0) {
269 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
270 $count_new = max(0, $count_diff);
272 $cells[] = array($hide_url.
273 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('title'=>_('Browse Trackers List for this project'))).
275 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('title'=>_('Browse this tracker for this project'))).
277 my_item_count($count_aids,$count_new), 'colspan' => 3);
278 $html_my_artifacts .= $HTML->multiTableRow(array('class' => 'boxitem'), $cells).$html;
280 return $html_my_artifacts;
283 function getCategory() {
284 return _('Trackers');
287 function getDescription() {
288 return _('List artifacts you have submitted or assigned to you or you are monitoring, by project.');
291 function isAvailable() {
292 if (!forge_get_config('use_tracker')) {
295 foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
296 if ($p->usesTracker()) {