3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once('Widget.class.php');
22 require_once('common/tracker/ArtifactTypeFactory.class.php');
23 require_once('common/tracker/ArtifactsForUser.class.php');
24 require_once('common/tracker/Artifact.class.php');
25 require_once('common/tracker/ArtifactFile.class.php');
26 require_once('common/tracker/ArtifactType.class.php');
27 require_once('common/tracker/ArtifactCanned.class.php');
32 * Artifact assigned to or submitted by this person
34 class Widget_MyArtifacts extends Widget {
36 function Widget_MyArtifacts() {
37 $this->Widget('myartifacts');
38 $this->_artifact_show = UserManager::instance()->getCurrentUser()->getPreference('my_artifacts_show');
39 if($this->_artifact_show === false) {
40 $this->_artifact_show = 'AS';
41 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
45 return _("My Artifacts");
47 function updatePreferences(&$request) {
48 $request->valid(new Valid_String('cancel'));
49 $vShow = new Valid_WhiteList('show', array('A', 'S', 'N', 'AS'));
51 if (!$request->exist('cancel')) {
52 if ($request->valid($vShow)) {
53 switch($request->get('show')) {
55 $this->_artifact_show = 'A';
58 $this->_artifact_show = 'S';
61 $this->_artifact_show = 'N';
65 $this->_artifact_show = 'AS';
67 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
72 function hasPreferences() {
75 function getPreferences() {
77 $prefs .= _("Display artifacts:").' <select name="show">';
78 $prefs .= '<option value="A" '.($this->_artifact_show === 'A'?'selected="selected"':'').'>'._("assigned to me [A]");
79 $prefs .= '<option value="S" '.($this->_artifact_show === 'S'?'selected="selected"':'').'>'._("submitted by me [S]");
80 $prefs .= '<option value="AS" '.($this->_artifact_show === 'AS'?'selected="selected"':'').'>'._("assigned to or submitted by me [AS]");
81 $prefs .= '</select>';
88 function getContent() {
89 $html_my_artifacts = '<table style="width:100%">';
90 $atf = new ArtifactsForUser(UserManager::instance()->getCurrentUser());
91 $monitored = $atf->getAssignedArtifactsByGroup();
92 $submitted = $atf->getSubmittedArtifactsByGroup();
93 if($this->_artifact_show == 'AS'){
94 $my_artifacts=array_merge($submitted,$monitored);
96 if($this->_artifact_show== 'S') {
97 $my_artifacts=$submitted;
99 if($this->_artifact_show== 'A') {
100 $my_artifacts=$monitored;
103 /* if ($atf = new ArtifactTypeFactory(false)) {
104 $my_artifacts = $atf->getMyArtifacts(user_getid(), $this->_artifact_show);*/
105 if (count($my_artifacts) > 0) {
106 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 0);
108 $html_my_artifacts = _("Failed to create ArtifactTypeFactory");
110 $html_my_artifacts .= '<TR><TD COLSPAN="3">'.(($this->_artifact_show == 'N' || count($my_artifacts) > 0)?' ':_("None")).'</TD></TR>';
111 $html_my_artifacts .= '</table>';
112 return $html_my_artifacts;
114 function _display_artifacts($list_trackers, $print_box_begin) {
115 $request =& HTTPRequest::instance();
117 $vItemId = new Valid_UInt('hide_item_id');
118 $vItemId->required();
119 if($request->valid($vItemId)) {
120 $hide_item_id = $request->get('hide_item_id');
122 $hide_item_id = null;
125 $vArtifact = new Valid_WhiteList('hide_artifact', array(0, 1));
126 $vArtifact->required();
127 if($request->valid($vArtifact)) {
128 $hide_artifact = $request->get('hide_artifact');
130 $hide_artifact = null;
133 $j = $print_box_begin;
134 $html_my_artifacts = "";
145 $artifact_types = array();
148 $pm = ProjectManager::instance();
149 foreach ($list_trackers as $trackers_array ) {
150 $atid = $trackers_array->getArtifactType()->getID();
151 /* if(array_key_exists($allIds,$atid)) {
158 $group_id = $trackers_array->getArtifactType()->getGroup()->getID();
160 // {{{ check permissions
162 $group = $pm->getProject($group_id);
163 if (!$group || !is_object($group) || $group->isError()) {
166 //Check if user can view artifact
167 if($trackers_array->getArtifactType()->userCanView() ) {
169 //work on the tracker of the last round if there was one
170 if ($atid != $atid_old && $count_aids != 0) {
171 list($hide_now,$count_diff,$hide_url) =
172 my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
173 $html_hdr = '<tr class="boxitem"><td colspan="3">' .
174 $hide_url.'<A HREF="/tracker/?group_id='.$group_id_old.'&atid='.$atid_old.'">'.
175 $group_name." - ".$tracker_name.'</A> ';
176 $count_new = max(0, $count_diff);
178 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
179 $html_my_artifacts .= $html_hdr.$html;
188 if ($count_aids == 0) {
189 //have to call it to get at least the hide_now even if count_aids is false at this point
190 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
193 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
194 $tracker_name = $trackers_array->ArtifactType->getName();
195 $aid = $trackers_array->getID();
196 $summary = $trackers_array->getSummary();
198 $group_id_old = $group_id;
200 // If user is assignee and submitter of an artifact, it will
201 // appears 2 times in the result set.
202 if($aid != $aid_old) {
206 if (!$hide_now && $aid != $aid_old) {
208 // Form the 'Submitted by/Assigned to flag' for marking
209 if($trackers_array->getAssignedTo()== user_getid())
211 if($trackers_array->getSubmittedBy()== user_getid()) {
218 elseif($trackers_array->getSubmittedBy()== user_getid()){
228 <TR class="'.$class.'">'.
229 '<TD class="priority'.$trackers_array->getPriority().'">'.$trackers_array->getPriority().'</TD>'.
230 '<TD colspan="1"><A HREF="/tracker/?func=detail&group_id='.
231 $group_id.'&aid='.$aid.'&atid='.$atid.
232 '">'. stripslashes($summary).'</A></TD>'.
233 '<TD class="small">';
234 $html .= ' '.$AS_flag.'</TD>'.$percent_complete.'</TR>';
241 //work on the tracker of the last round if there was one
242 if ($atid_old != 0 && $count_aids != 0) {
243 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
244 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="3">' : '').
245 $hide_url.'<A HREF="/tracker/?group_id='.$group_id_old.'&atid='.$atid_old.'">'.
246 $group_name." - ".$tracker_name.'</A> ';
247 $count_new = max(0, $count_diff);
249 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
250 $html_my_artifacts .= $html_hdr.$html;
252 return $html_my_artifacts;
256 function getCategory() {
259 function getDescription() {
260 return _("List artifacts you have submitted or assigned to you, by project.");