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
39 class Widget_MyArtifacts extends Widget {
41 function __construct() {
42 $this->Widget('myartifacts');
43 $this->_artifact_show = UserManager::instance()->getCurrentUser()->getPreference('my_artifacts_show');
44 if($this->_artifact_show === false) {
45 $this->_artifact_show = 'ASM';
46 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
51 return _("My Artifacts");
54 function updatePreferences(&$request) {
55 $request->valid(new Valid_String('cancel'));
56 $vShow = new Valid_WhiteList('show', array('A', 'S', 'M', 'N', 'AS', 'AM', 'SM', 'ASM'));
58 if (!$request->exist('cancel')) {
59 if ($request->valid($vShow)) {
60 switch($request->get('show')) {
62 $this->_artifact_show = 'A';
65 $this->_artifact_show = 'S';
68 $this->_artifact_show = 'M';
71 $this->_artifact_show = 'N';
74 $this->_artifact_show = 'AS';
77 $this->_artifact_show = 'AM';
80 $this->_artifact_show = 'SM';
84 $this->_artifact_show = 'ASM';
86 UserManager::instance()->getCurrentUser()->setPreference('my_artifacts_show', $this->_artifact_show);
92 function hasPreferences() {
96 function getPreferences() {
97 $optionsArray = array('A','S','M','AS','AM','SM', 'ASM');
98 $textsArray = array();
99 $textsArray[] = _('assigned to me'.' [A]');
100 $textsArray[] = _('submitted by me'.' [S]');
101 $textsArray[] = _('monitored by me'.' [M]');
102 $textsArray[] = _('assigned to or submitted by me'.' [AS]');
103 $textsArray[] = _('assigned to or monitored by me'.' [AM]');
104 $textsArray[] = _('submitted by or monitored by me'.' [SM]');
105 $textsArray[] = _('assigned to or submitted by or monitored by me'.' [ASM]');
106 $prefs = _("Display artifacts:").html_build_select_box_from_arrays($optionsArray, $textsArray, "show", $this->_artifact_show);
110 function getContent() {
112 $atf = new ArtifactsForUser(@UserManager::instance()->getCurrentUser());
113 $my_artifacts = array();
114 if ($this->_artifact_show == 'ASM'){
115 $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()));
117 if ($this->_artifact_show == 'AS'){
118 $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()));
120 if ($this->_artifact_show == 'AM'){
121 $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()));
123 if ($this->_artifact_show == 'SM'){
124 $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()));
126 if ($this->_artifact_show== 'S') {
127 $my_artifacts = $atf->getSubmittedArtifactsByGroup();
129 if ($this->_artifact_show== 'A') {
130 $my_artifacts = $atf->getAssignedArtifactsByGroup();
132 if ($this->_artifact_show== 'M') {
133 $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()));;
136 if (count($my_artifacts) > 0) {
137 $html_my_artifacts = '<table style="width:100%">';
138 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 1);
139 $html_my_artifacts .= '</table>';
141 $html_my_artifacts = '<div class="warning">'. _("You have no artifacts") . '</div>';
144 return $html_my_artifacts;
147 function _display_artifacts($list_trackers, $print_box_begin) {
149 $request = HTTPRequest::instance();
150 $vItemId = new Valid_UInt('hide_item_id');
151 $vItemId->required();
152 if($request->valid($vItemId)) {
153 $hide_item_id = $request->get('hide_item_id');
155 $hide_item_id = null;
158 $vArtifact = new Valid_WhiteList('hide_artifact', array(0, 1));
159 $vArtifact->required();
160 if($request->valid($vArtifact)) {
161 $hide_artifact = $request->get('hide_artifact');
163 $hide_artifact = null;
166 $j = $print_box_begin;
167 $html_my_artifacts = "";
178 $artifact_types = array();
181 $pm = ProjectManager::instance();
182 foreach ($list_trackers as $trackers_array ) {
183 $atid = $trackers_array->getArtifactType()->getID();
184 $group_id = $trackers_array->getArtifactType()->getGroup()->getID();
187 $group = $pm->getProject($group_id);
188 if (!$group || !is_object($group) || $group->isError()) {
191 //Check if user can view artifact
192 if (forge_check_perm ('tracker', $trackers_array->getArtifactType()->getID(), 'read')) {
194 //work on the tracker of the last round if there was one
195 if ($atid != $atid_old && $count_aids != 0) {
196 list($hide_now,$count_diff,$hide_url) =
197 my_hide_url('artifact', $atid_old, $hide_item_id, $count_aids, $hide_artifact);
198 $html_hdr = '<tr class="boxitem"><td colspan="3">' .
200 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
202 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
204 $count_new = max(0, $count_diff);
206 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
207 $html_my_artifacts .= $html_hdr.$html;
216 if ($count_aids == 0) {
217 //have to call it to get at least the hide_now even if count_aids is false at this point
218 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
221 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
222 $tracker_name = $trackers_array->ArtifactType->getName();
223 $aid = $trackers_array->getID();
224 $summary = $trackers_array->getSummary();
226 $group_id_old = $group_id;
228 // If user is assignee and submitter of an artifact, it will
229 // appears 2 times in the result set.
230 if($aid != $aid_old) {
234 if (!$hide_now && $aid != $aid_old) {
236 // Form the 'Submitted by/Assigned/Monitored_by to flag' for marking
239 if($trackers_array->getAssignedTo()== user_getid()) {
241 $AS_title .= _('Assigned');
243 if ($trackers_array->getSubmittedBy()== user_getid()) {
245 if (strlen($AS_title))
247 $AS_title .= _('Submitted');
249 if ($trackers_array->isMonitoring()) {
251 if (strlen($AS_title))
253 $AS_title .= _('Monitored');
255 if (!strlen($AS_flag)) {
261 <tr '. $HTML->boxGetAltRowStyle($count_aids) .'>'.
262 '<td class="priority'.$trackers_array->getPriority().'">'.$trackers_array->getPriority().'</td>'.
263 '<td>'.util_make_link('/tracker/?func=detail&group_id='.$group_id.'&aid='.$aid.'&atid='.$atid, stripslashes($summary), array("class"=>"tabtitle", "title"=>_('Browse this artefact'))).
265 '<td class="small tabtitle-ne" title="'.$AS_title.'">';
266 $html .= ' '.$AS_flag.'</td></tr>';
273 //work on the tracker of the last round if there was one
274 if ($atid_old != 0 && $count_aids != 0) {
275 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
276 $html_hdr = '<tr class="boxitem"><td colspan="3">'.
278 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
280 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
282 $count_new = max(0, $count_diff);
284 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
285 $html_my_artifacts .= $html_hdr.$html;
287 return $html_my_artifacts;
290 function getCategory() {
294 function getDescription() {
295 return _("List artifacts you have submitted or assigned to you or you are monitoring, by project.");