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 $gfcommon.'include/utils.php';
25 require_once $gfwww.'include/html.php';
26 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
27 require_once $gfcommon.'tracker/ArtifactsForUser.class.php';
28 require_once $gfcommon.'tracker/Artifact.class.php';
29 require_once $gfcommon.'tracker/ArtifactFile.class.php';
30 require_once $gfcommon.'tracker/ArtifactType.class.php';
31 require_once $gfcommon.'tracker/ArtifactCanned.class.php';
36 * Artifact assigned to or submitted by or monitored by this person
38 class Widget_MyArtifacts extends Widget {
40 function Widget_MyArtifacts() {
41 $this->Widget('myartifacts');
42 $this->_artifact_show = UserManager::instance()->getCurrentUser()->getPreference('my_artifacts_show');
43 if($this->_artifact_show === false) {
44 $this->_artifact_show = 'ASM';
45 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
50 return _("My Artifacts");
53 function updatePreferences(&$request) {
54 $request->valid(new Valid_String('cancel'));
55 $vShow = new Valid_WhiteList('show', array('A', 'S', 'M', 'N', 'AS', 'AM', 'SM', 'ASM'));
57 if (!$request->exist('cancel')) {
58 if ($request->valid($vShow)) {
59 switch($request->get('show')) {
61 $this->_artifact_show = 'A';
64 $this->_artifact_show = 'S';
67 $this->_artifact_show = 'M';
70 $this->_artifact_show = 'N';
73 $this->_artifact_show = 'AS';
76 $this->_artifact_show = 'AM';
79 $this->_artifact_show = 'SM';
83 $this->_artifact_show = 'ASM';
85 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
91 function hasPreferences() {
95 function getPreferences() {
96 $optionsArray = array('A','S','M','AS','AM','SM', 'ASM');
97 $textsArray = array();
98 $textsArray[] = _('assigned to me'.' [A]');
99 $textsArray[] = _('submitted by me'.' [S]');
100 $textsArray[] = _('monitored by me'.' [M]');
101 $textsArray[] = _('assigned to or submitted by me'.' [AS]');
102 $textsArray[] = _('assigned to or monitored by me'.' [AM]');
103 $textsArray[] = _('submitted by or monitored by me'.' [SM]');
104 $textsArray[] = _('assigned to or submitted by or monitored by me'.' [ASM]');
105 $prefs = _("Display artifacts:").html_build_select_box_from_arrays($optionsArray, $textsArray, "show", $this->_artifact_show);
109 function getContent() {
110 $html_my_artifacts = '<table style="width:100%">';
111 $atf = new ArtifactsForUser(@UserManager::instance()->getCurrentUser());
112 $my_artifacts = array();
113 if ($this->_artifact_show == 'ASM'){
114 $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()));
116 if ($this->_artifact_show == 'AS'){
117 $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()));
119 if ($this->_artifact_show == 'AM'){
120 $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()));
122 if ($this->_artifact_show == 'SM'){
123 $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()));
125 if ($this->_artifact_show== 'S') {
126 $my_artifacts = $atf->getSubmittedArtifactsByGroup();
128 if ($this->_artifact_show== 'A') {
129 $my_artifacts = $atf->getAssignedArtifactsByGroup();
131 if ($this->_artifact_show== 'M') {
132 $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()));;
135 if (count($my_artifacts) > 0) {
136 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 1);
138 $html_my_artifacts .= '<tr><td colspan="3">' .
139 _("You have no artifacts.") . '</td></tr>';
141 $html_my_artifacts .= '<tr><td colspan="3">'.(($this->_artifact_show == 'N' || count($my_artifacts) > 0)?' ':_("None")).'</td></tr>';
142 $html_my_artifacts .= '</table>';
143 return $html_my_artifacts;
146 function _display_artifacts($list_trackers, $print_box_begin) {
148 $request = HTTPRequest::instance();
149 $vItemId = new Valid_UInt('hide_item_id');
150 $vItemId->required();
151 if($request->valid($vItemId)) {
152 $hide_item_id = $request->get('hide_item_id');
154 $hide_item_id = null;
157 $vArtifact = new Valid_WhiteList('hide_artifact', array(0, 1));
158 $vArtifact->required();
159 if($request->valid($vArtifact)) {
160 $hide_artifact = $request->get('hide_artifact');
162 $hide_artifact = null;
165 $j = $print_box_begin;
166 $html_my_artifacts = "";
177 $artifact_types = array();
180 $pm = ProjectManager::instance();
181 foreach ($list_trackers as $trackers_array ) {
182 $atid = $trackers_array->getArtifactType()->getID();
183 $group_id = $trackers_array->getArtifactType()->getGroup()->getID();
186 $group = $pm->getProject($group_id);
187 if (!$group || !is_object($group) || $group->isError()) {
190 //Check if user can view artifact
191 if (forge_check_perm ('tracker', $trackers_array->getArtifactType()->getID(), 'read')) {
193 //work on the tracker of the last round if there was one
194 if ($atid != $atid_old && $count_aids != 0) {
195 list($hide_now,$count_diff,$hide_url) =
196 my_hide_url('artifact', $atid_old, $hide_item_id, $count_aids, $hide_artifact);
197 $html_hdr = '<tr class="boxitem"><td colspan="3">' .
199 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
201 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
203 $count_new = max(0, $count_diff);
205 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
206 $html_my_artifacts .= $html_hdr.$html;
215 if ($count_aids == 0) {
216 //have to call it to get at least the hide_now even if count_aids is false at this point
217 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
220 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
221 $tracker_name = $trackers_array->ArtifactType->getName();
222 $aid = $trackers_array->getID();
223 $summary = $trackers_array->getSummary();
225 $group_id_old = $group_id;
227 // If user is assignee and submitter of an artifact, it will
228 // appears 2 times in the result set.
229 if($aid != $aid_old) {
233 if (!$hide_now && $aid != $aid_old) {
235 // Form the 'Submitted by/Assigned/Monitored_by to flag' for marking
238 if($trackers_array->getAssignedTo()== user_getid()) {
240 $AS_title .= _('Assigned');
242 if ($trackers_array->getSubmittedBy()== user_getid()) {
244 if (strlen($AS_title))
246 $AS_title .= _('Submitted');
248 if ($trackers_array->isMonitoring()) {
250 if (strlen($AS_title))
252 $AS_title .= _('Monitored');
254 if (!strlen($AS_flag)) {
260 <tr '. $HTML->boxGetAltRowStyle($count_aids) .'>'.
261 '<td class="priority'.$trackers_array->getPriority().'">'.$trackers_array->getPriority().'</td>'.
262 '<td>'.util_make_link('/tracker/?func=detail&group_id='.$group_id.'&aid='.$aid.'&atid='.$atid, stripslashes($summary), array("class"=>"tabtitle", "title"=>_('Browse this artefact'))).
264 '<td class="small tabtitle-ne" title="'.$AS_title.'">';
265 $html .= ' '.$AS_flag.'</td></tr>';
272 //work on the tracker of the last round if there was one
273 if ($atid_old != 0 && $count_aids != 0) {
274 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
275 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="3">' : '').
277 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
279 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
281 $count_new = max(0, $count_diff);
283 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
284 $html_my_artifacts .= $html_hdr.$html;
286 return $html_my_artifacts;
289 function getCategory() {
293 function getDescription() {
294 return _("List artifacts you have submitted or assigned to you or you are monitoring, by project.");