3 * @author: Patrick Apel, tarent GmbH
5 * This file is part of FusionForge. FusionForge is free software;
6 * you can redistribute it and/or modify it under the terms of the
7 * GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the Licence, or (at your option)
11 * FusionForge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * Retrieve group_project_id and group_id for a specific project_task_id,
23 * for URI construction and similar things.
25 * @param int $project_task_id
26 * @return array|bool false, or an associative array with
27 * - int project_task_id (copy)
28 * - int group_project_id
31 function getGroupProjectIdGroupId($project_task_id) {
32 $res = db_query_params('SELECT project_task.group_project_id, project_group_list.group_id FROM project_task ' .
33 'INNER JOIN project_group_list ON project_task.group_project_id = project_group_list.group_project_id ' .
34 'WHERE project_task.project_task_id = $1',
35 array($project_task_id));
37 if (!$res || db_numrows($res) != 1) {
41 while ($arr = db_fetch_array($res)) {
43 'project_task_id' => (int)$project_task_id,
44 'group_project_id' => (int)$arr[0],
45 'group_id' => (int)$arr[1]
53 * Check if the task behind project_task_id is considered public.
55 * @param int $project_task_id
56 * @return bool true, if it is public; false otherwise
58 function isProjectTaskInfoPublic($project_task_id) {
59 $res = db_query_params('SELECT group_project_id FROM project_task WHERE project_task_id=$1',
60 array ($project_task_id)) ;
62 if (!$res || db_numrows($res) < 1) {
66 return RoleAnonymous::getInstance()->hasPermission('pm',
67 db_result ($res, 0, 'group_project_id'),
72 * Check whether the user has access to the project task by
73 * means of common group membership.
75 * @param int $project_task_id
76 * @param string $user_name Unix user name
77 * @return bool true, if he has access to the project task; false otherwise
79 function isUserAndTaskinSameGroup($project_task_id, $user_name) {
80 $res = db_query_params('SELECT group_project_id FROM project_task WHERE project_task_id=$1',
81 array ($project_task_id)) ;
83 if (!$res || db_numrows($res) < 1) {
86 $arr = db_fetch_array($res) ;
88 return forge_check_perm_for_user(user_get_object_by_name ($user_name), 'pm', $arr['group_project_id'], 'read') ;
92 * Query for controlling the result. It gives back all user_names and
93 * project_task_ids that matches the groups above:
95 * SELECT users.user_name, project_task.project_task_id FROM users
96 * INNER JOIN user_group ON users.user_id = user_group.user_id
97 * INNER JOIN project_group_list ON user_group.group_id = project_group_list.group_id
98 * INNER JOIN project_task ON project_group_list.group_project_id = project_task.group_project_id;
100 * Query for controlling the result. It gives back all user_names that
101 * does not match a group above:
103 * SELECT users.user_name, project_task.project_task_id FROM users
104 * LEFT JOIN user_group ON users.user_id = user_group.user_id
105 * LEFT JOIN project_group_list ON user_group.group_id = project_group_list.group_id
106 * LEFT JOIN project_task ON project_group_list.group_project_id = project_task.group_project_id
107 * WHERE project_task_id isNull;
111 * Retrieve extended information about a project task.
113 * @param int $project_task_id
114 * @return array|bool false (if an error occured) or an associative array with
115 * - int project_task_id (copy)
116 * - int group_project_id (for URI construction)
117 * - int group_id (for URI construction)
119 * - str summary (of the task)
121 * - int created_by (user ID)
122 * - str created_by_name (Unix user name)
126 * - str category_name (of the per-group category the task is in)
127 * - str project_name (of the per-group subproject the task is in)
129 function getAllFromProjectTask($project_task_id) {
130 $res = db_query_params('SELECT ' .
131 'project_task.project_task_id, project_task.group_project_id, project_task.summary, project_task.priority, ' .
132 'project_task.created_by, project_task.status_id, project_task.category_id, ' .
133 'users.user_name, ' .
134 'project_category.category_name, ' .
135 'project_group_list.project_name, ' .
136 'groups.group_name, ' .
137 'groups.group_id, ' .
138 'project_status.status_name ' .
139 'FROM project_status ' .
140 'INNER JOIN project_task ON ' .
141 'project_task.status_id = project_status.status_id ' .
142 'INNER JOIN users ON ' .
143 'users.user_id = project_task.created_by ' .
144 'INNER JOIN project_category ON ' .
145 'project_category.category_id = project_task.category_id ' .
146 'INNER JOIN project_group_list ON ' .
147 'project_group_list.group_project_id = project_task.group_project_id ' .
148 'INNER JOIN groups ON ' .
149 'groups.group_id = project_group_list.group_id ' .
150 'WHERE project_task.project_task_id = $1',
151 array($project_task_id));
153 if (!$res || db_numrows($res) != 1) {
157 while ($arr = db_fetch_array($res)) {
159 'project_task_id' => (int)$arr[0],
160 'group_project_id' => (int)$arr[1],
161 'group_id' => (int)$arr[11],
162 'summary' => $arr[2],
163 'priority' => (int)$arr[3],
164 'created_by' => (int)$arr[4],
165 'status_id' => (int)$arr[5],
166 'category_id' => (int)$arr[6],
167 'created_by_name' => $arr[7],
168 'category_name' => $arr[8],
169 'project_name' => $arr[9],
170 'group_name' => $arr[10],
171 'status_name' => $arr[12]