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 = '<table style="width:100%">';
139 $html_my_artifacts .= $this->_display_artifacts($my_artifacts, 1);
140 $html_my_artifacts .= '</table>';
142 $html_my_artifacts = '<div class="warning">'. _("You have no artifacts") . '</div>';
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) =
198 my_hide_url('artifact', $atid_old, $hide_item_id, $count_aids, $hide_artifact);
199 $html_hdr = '<tr class="boxitem"><td colspan="3">' .
201 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
203 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
205 $count_new = max(0, $count_diff);
207 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
208 $html_my_artifacts .= $html_hdr.$html;
217 if ($count_aids == 0) {
218 //have to call it to get at least the hide_now even if count_aids is false at this point
219 $hide_now = my_hide('artifact',$atid,$hide_item_id,$hide_artifact);
222 $group_name = $trackers_array->ArtifactType->Group->getPublicName();
223 $tracker_name = $trackers_array->ArtifactType->getName();
224 $aid = $trackers_array->getID();
225 $summary = $trackers_array->getSummary();
227 $group_id_old = $group_id;
229 // If user is assignee and submitter of an artifact, it will
230 // appears 2 times in the result set.
231 if($aid != $aid_old) {
235 if (!$hide_now && $aid != $aid_old) {
237 // Form the 'Submitted by/Assigned/Monitored_by to flag' for marking
240 if($trackers_array->getAssignedTo()== user_getid()) {
242 $AS_title .= _('Assigned');
244 if ($trackers_array->getSubmittedBy()== user_getid()) {
246 if (strlen($AS_title))
248 $AS_title .= _('Submitted');
250 if ($trackers_array->isMonitoring()) {
252 if (strlen($AS_title))
254 $AS_title .= _('Monitored');
256 if (!strlen($AS_flag)) {
262 <tr '. $HTML->boxGetAltRowStyle($count_aids) .'>'.
263 '<td class="priority'.$trackers_array->getPriority().'">'.$trackers_array->getPriority().'</td>'.
264 '<td>'.util_make_link('/tracker/?func=detail&group_id='.$group_id.'&aid='.$aid.'&atid='.$atid, stripslashes($summary), array("class"=>"tabtitle", "title"=>_('Browse this artefact'))).
266 '<td class="small tabtitle-ne" title="'.$AS_title.'">';
267 $html .= ' '.$AS_flag.'</td></tr>';
274 //work on the tracker of the last round if there was one
275 if ($atid_old != 0 && $count_aids != 0) {
276 list($hide_now,$count_diff,$hide_url) = my_hide_url('artifact',$atid_old,$hide_item_id,$count_aids,$hide_artifact);
277 $html_hdr = '<tr class="boxitem"><td colspan="3">'.
279 util_make_link('/tracker/?group_id='.$group_id_old, $group_name, array('class'=>'tabtitle-nw', 'title'=>_('Browse Trackers List for this project'))).
281 util_make_link('/tracker/?group_id='.$group_id_old.'&atid='.$atid_old, $tracker_name, array('class'=>'tabtitle', 'title'=>_('Browse this tracker for this project'))).
283 $count_new = max(0, $count_diff);
285 $html_hdr .= my_item_count($count_aids,$count_new).'</td></tr>';
286 $html_my_artifacts .= $html_hdr.$html;
288 return $html_my_artifacts;
291 function getCategory() {
295 function getDescription() {
296 return _("List artifacts you have submitted or assigned to you or you are monitoring, by project.");
299 function isAvailable() {
300 if (!forge_get_config('use_tracker')) {
303 foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
304 if ($p->usesTracker()) {