3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012, Franck Villaume - TrivialDev
5 * http://fusionforge.org
7 * This file is a part of Fusionforge.
9 * Fusionforge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Fusionforge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
23 require_once('Widget.class.php');
24 require_once('common/tracker/ArtifactTypeFactory.class.php');
25 require_once('common/tracker/ArtifactsForUser.class.php');
26 require_once('common/tracker/Artifact.class.php');
27 require_once('common/tracker/ArtifactFile.class.php');
28 require_once('common/tracker/ArtifactType.class.php');
29 require_once('common/tracker/ArtifactCanned.class.php');
34 * Artifact assigned to or submitted by this person
36 class Widget_MyArtifacts extends Widget {
38 function Widget_MyArtifacts() {
39 $this->Widget('myartifacts');
40 $this->_artifact_show = UserManager::instance()->getCurrentUser()->getPreference('my_artifacts_show');
41 if($this->_artifact_show === false) {
42 $this->_artifact_show = 'AS';
43 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
48 return _("My Artifacts");
51 function updatePreferences(&$request) {
52 $request->valid(new Valid_String('cancel'));
53 $vShow = new Valid_WhiteList('show', array('A', 'S', 'N', 'AS'));
55 if (!$request->exist('cancel')) {
56 if ($request->valid($vShow)) {
57 switch($request->get('show')) {
59 $this->_artifact_show = 'A';
62 $this->_artifact_show = 'S';
65 $this->_artifact_show = 'N';
69 $this->_artifact_show = 'AS';
71 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
77 function hasPreferences() {
81 function getPreferences() {
83 $prefs .= _("Display artifacts:").' <select name="show">';
84 $prefs .= '<option value="A" '.($this->_artifact_show === 'A'?'selected="selected"':'').'>'._("assigned to me [A]");
85 $prefs .= '<option value="S" '.($this->_artifact_show === 'S'?'selected="selected"':'').'>'._("submitted by me [S]");
86 $prefs .= '<option value="AS" '.($this->_artifact_show === 'AS'?'selected="selected"':'').'>'._("assigned to or submitted by me [AS]");
87 $prefs .= '</select>';
91 function getContent() {
92 $html_my_artifacts = '<table style="width:100%">';
93 $atf = new ArtifactsForUser(@UserManager::instance()->getCurrentUser());
94 $assigned = $atf->getAssignedArtifactsByGroup();
95 $submitted = $atf->getSubmittedArtifactsByGroup();
96 $all = $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()));
98 $my_artifacts = array();
99 if($this->_artifact_show == 'AS'){
102 if($this->_artifact_show== 'S') {
103 $my_artifacts=$submitted;
105 if($this->_artifact_show== 'A') {
106 $my_artifacts=$assigned;
109 if (count($my_artifacts) > 0) {
110 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 1);
112 $html_my_artifacts .= '<tr><td colspan="3">' .
113 _("You have no artifacts") . '</td></tr>';
115 $html_my_artifacts .= '<tr><td colspan="3">'.(($this->_artifact_show == 'N' || count($my_artifacts) > 0)?' ':_("None")).'</td></tr>';
116 $html_my_artifacts .= '</table>';
117 return $html_my_artifacts;
120 function _display_artifacts($list_trackers, $print_box_begin) {
122 $request = HTTPRequest::instance();
123 $vItemId = new Valid_UInt('hide_item_id');
124 $vItemId->required();
125 if($request->valid($vItemId)) {
126 $hide_item_id = $request->get('hide_item_id');
128 $hide_item_id = null;
131 $vArtifact = new Valid_WhiteList('hide_artifact', array(0, 1));
132 $vArtifact->required();
133 if($request->valid($vArtifact)) {
134 $hide_artifact = $request->get('hide_artifact');
136 $hide_artifact = null;
139 $j = $print_box_begin;
140 $html_my_artifacts = "";
151 $artifact_types = array();
154 $pm = ProjectManager::instance();
155 foreach ($list_trackers as $trackers_array ) {
156 $atid = $trackers_array->getArtifactType()->getID();
157 $group_id = $trackers_array->getArtifactType()->getGroup()->getID();
160 $group = $pm->getProject($group_id);
161 if (!$group || !is_object($group) || $group->isError()) {
164 //Check if user can view artifact
165 if (forge_check_perm ('tracker', $trackers_array->getArtifactType()->getID(), 'read')) {
167 //work on the tracker of the last round if there was one
168 if ($atid != $atid_old && $count_aids != 0) {
169 list($hide_now,$count_diff,$hide_url) =
170 my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
171 $html_hdr = '<tr class="boxitem"><td colspan="3">' .
172 $hide_url.'<a href="/tracker/?group_id='.$group_id_old.'&atid='.$atid_old.'">'.
173 $group_name." - ".$tracker_name.'</a> ';
174 $count_new = max(0, $count_diff);
176 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
177 $html_my_artifacts .= $html_hdr.$html;
186 if ($count_aids == 0) {
187 //have to call it to get at least the hide_now even if count_aids is false at this point
188 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
191 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
192 $tracker_name = $trackers_array->ArtifactType->getName();
193 $aid = $trackers_array->getID();
194 $summary = $trackers_array->getSummary();
196 $group_id_old = $group_id;
198 // If user is assignee and submitter of an artifact, it will
199 // appears 2 times in the result set.
200 if($aid != $aid_old) {
204 if (!$hide_now && $aid != $aid_old) {
206 // Form the 'Submitted by/Assigned to flag' for marking
207 if($trackers_array->getAssignedTo()== user_getid())
209 if($trackers_array->getSubmittedBy()== user_getid()) {
216 elseif($trackers_array->getSubmittedBy()== user_getid()){
225 <tr '. $HTML->boxGetAltRowStyle($count_aids) .'>'.
226 '<td class="priority'.$trackers_array->getPriority().'">'.$trackers_array->getPriority().'</td>'.
227 '<td><a href="/tracker/?func=detail&group_id='.
228 $group_id.'&aid='.$aid.'&atid='.$atid.
229 '">'. stripslashes($summary).'</a></td>'.
230 '<td class="small">';
231 $html .= ' '.$AS_flag.'</td></tr>';
238 //work on the tracker of the last round if there was one
239 if ($atid_old != 0 && $count_aids != 0) {
240 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
241 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="3">' : '').
242 $hide_url.'<a href="/tracker/?group_id='.$group_id_old.'&atid='.$atid_old.'">'.
243 $group_name." - ".$tracker_name.'</a> ';
244 $count_new = max(0, $count_diff);
246 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
247 $html_my_artifacts .= $html_hdr.$html;
249 return $html_my_artifacts;
252 function getCategory() {
256 function getDescription() {
257 return _("List artifacts you have submitted or assigned to you, by project.");