5 * Copyright 2002, GForge, LLC
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
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 along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/Error.class.php';
25 require_once $gfcommon.'include/User.class.php';
26 require_once $gfcommon.'tracker/Artifact.class.php';
27 require_once $gfcommon.'tracker/ArtifactFromID.class.php';
29 class ArtifactsForUser extends Error {
37 * Creates a new ArtifactsFor User object
39 * @param user the User object for which to collect artifacts
41 function ArtifactsForUser(&$user) {
47 * getArtifactsFromSQL - Gets an array of Artifacts
49 * @param sql The sql that returns artifact_id
50 * @return Artifact[] The array of Artifacts
52 function &getArtifactsFromSQLwithParams ($sql, $params) {
54 $result = db_query_params ($sql, $params);
55 $rows=db_numrows($result);
59 for ($i=0; $i < $rows; $i++) {
60 $id = db_result($result,$i,'artifact_id');
61 $arr = db_fetch_array($result);
62 $afi = new ArtifactFromID($id,$arr);
63 if ($afi->isError()) {
64 $this->setError($afi->getErrorMessage());
65 } elseif($afi->Artifact->ArtifactType->Group->getStatus() == 'A') {
66 $artifacts[] =& $afi->Artifact;
73 * getAssignedArtifacts - Get the users's assigned artifacts
74 * @return Artifact[] The array of Artifacts
76 function &getAssignedArtifactsByGroup() {
77 return $this->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av WHERE av.assigned_to=$1 AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',
78 array($this->User->getID())) ;
83 * getSubmittedArtifactsByGroup
85 * @return Artifact[] The array of Artifacts
87 function &getSubmittedArtifactsByGroup() {
88 return $this->getArtifactsFromSQLwithParams('SELECT * FROM artifact_vw av WHERE av.submitted_by=$1 AND av.status_id=1 ORDER BY av.group_artifact_id, av.artifact_id DESC',
89 array($this->User->getID())) ;
93 * getMonitoredArtifacts
95 * @return Artifact[] The array of Artifacts
97 function & getMonitoredArtifacts() {
100 $result=db_query_params ('SELECT groups.group_name,groups.group_id,
101 artifact_group_list.group_artifact_id,
102 artifact_group_list.name
103 FROM groups,artifact_group_list,artifact_type_monitor
104 WHERE groups.group_id=artifact_group_list.group_id
105 AND groups.status =$1
106 AND artifact_group_list.group_artifact_id=artifact_type_monitor.group_artifact_id
107 AND artifact_type_monitor.user_id=$2
108 ORDER BY group_name ASC',
110 $this->User->getID()));
111 $rows=db_numrows($result);
115 for ($i=0; $i<$rows; $i++) {
116 $group_id = db_result($result,$i,'group_id');
117 $group_artifact_id = db_result($result,$i,'group_artifact_id');
118 $group = group_get_object($group_id);
119 $artifact = new ArtifactType($group,$group_artifact_id);
120 $ag = $artifact->getGroup();
121 if ($artifact->isError()) {
122 $this->setError($artifact->getErrorMessage());
124 $artifacts[] = $artifact;
133 // c-file-style: "bsd"