3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
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 along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
28 * Fetches a ProjectGroup object from the database
30 * @param int the projectgroup id
31 * @param array whether or not the db result handle is passed in
32 * @return object the ProjectGroup object
34 function &projectgroup_get_object($group_project_id, $data = false) {
35 global $PROJECTGROUP_OBJ;
36 if (!isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
38 //the db result handle was passed in
40 $res = db_query_params('SELECT * FROM project_group_list_vw WHERE group_project_id=$1',
41 array($group_project_id));
42 if (db_numrows($res) <1 ) {
43 $PROJECTGROUP_OBJ["_".$group_project_id."_"]=false;
46 $data = db_fetch_array($res);
48 $Group = group_get_object($data["group_id"]);
49 $PROJECTGROUP_OBJ["_".$group_project_id."_"]= new ProjectGroup($Group,$group_project_id,$data);
51 return $PROJECTGROUP_OBJ["_".$group_project_id."_"];
54 function projectgroup_get_groupid($group_project_id) {
55 global $PROJECTGROUP_OBJ;
56 if (isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
57 return $PROJECTGROUP_OBJ["_".$group_project_id."_"]->Group->getID() ;
60 $res = db_query_params('SELECT group_id FROM project_group_list WHERE group_project_id=$1',
61 array($group_project_id));
62 if (!$res || db_numrows($res) < 1) {
65 $arr = db_fetch_array($res);
66 return $arr['group_id'];
69 class ProjectGroup extends Error {
72 * Associative array of data from db.
74 * @var array $data_array.
91 * @param object The Group object to which this forum is associated.
92 * @param int The group_project_id.
93 * @param array The associative array of data.
94 * @return boolean success.
96 function ProjectGroup(&$Group, $group_project_id = false, $arr = false) {
98 if (!$Group || !is_object($Group)) {
99 $this->setError('ProjectGroup:: No Valid Group Object');
102 if ($Group->isError()) {
103 $this->setError('ProjectGroup:: '.$Group->getErrorMessage());
106 $this->Group =& $Group;
108 if ($group_project_id) {
109 if (!$arr || !is_array($arr)) {
110 if (!$this->fetchData($group_project_id)) {
114 $this->data_array =& $arr;
115 if ($this->data_array['group_id'] != $this->Group->getID()) {
116 $this->setError('Group_id in db result does not match Group Object');
121 // Make sure they can even access this object
123 if (!forge_check_perm ('pm', $this->getID(), 'read')) {
124 $this->setPermissionDeniedError();
125 $this->data_array = null;
133 * create - create a new ProjectGroup in the database.
135 * @param string The project name.
136 * @param string The project description.
137 * @param string The email address to send new notifications to.
138 * @return boolean success.
140 function create($project_name,$description,$send_all_posts_to='') {
141 if (strlen($project_name) < 3) {
142 $this->setError(_('Title Must Be At Least 5 Characters'));
145 if (strlen($description) < 10) {
146 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
149 if ($send_all_posts_to) {
150 $invalid_mails = validate_emails($send_all_posts_to);
151 if (count($invalid_mails) > 0) {
152 $this->setInvalidEmailError($send_all_posts_to);
157 if (!forge_check_perm ('pm_admin', $this->Group->getID())) {
158 $this->setPermissionDeniedError();
163 $result = db_query_params('INSERT INTO project_group_list (group_id,project_name,description,send_all_posts_to) VALUES ($1,$2,$3,$4)',
164 array($this->Group->getId(),
165 htmlspecialchars($project_name),
166 htmlspecialchars($description),
167 $send_all_posts_to));
169 $this->setError('Error Adding ProjectGroup: '.db_error());
173 $this->group_project_id=db_insertid($result,'project_group_list','group_project_id');
174 $this->fetchData($this->group_project_id);
175 $this->Group->normalizeAllRoles () ;
183 * fetchData - re-fetch the data for this ProjectGroup from the database.
185 * @param int The project group ID.
186 * @return boolean success.
188 function fetchData($group_project_id) {
189 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
190 array ($group_project_id,
191 $this->Group->getID())) ;
192 if (!$res || db_numrows($res) < 1) {
193 $this->setError('ProjectGroup:: Invalid group_project_id');
196 $this->data_array = db_fetch_array($res);
197 db_free_result($res);
202 * getGroup - get the Group object this ProjectGroup is associated with.
204 * @return object The Group object.
206 function &getGroup() {
211 * getID - get this GroupProjectID.
213 * @return int The group_project_id #.
216 return $this->data_array['group_project_id'];
220 * getOpenCount - get the count of open tracker items in this tracker type.
222 * @return int The count.
224 function getOpenCount() {
225 return $this->data_array['open_count'];
229 * getTotalCount - get the total number of tracker items in this tracker type.
231 * @return int The total count.
233 function getTotalCount() {
234 return $this->data_array['count'];
238 * getName - get the name of this projectGroup.
240 * @return string The name of this projectGroup.
243 return $this->data_array['project_name'];
247 * getSendAllPostsTo - an optional email address to send all task updates to.
249 * @return string The email address.
251 function getSendAllPostsTo() {
252 return $this->data_array['send_all_posts_to'];
256 * getDescription - the description of this ProjectGroup.
258 * @return string The description.
260 function getDescription() {
261 return $this->data_array['description'];
265 * getStatuses - Return result set of statuses.
267 * @return object Database result set.
269 function getStatuses() {
270 if (!$this->statuses) {
271 $this->statuses = db_query_params('SELECT * FROM project_status',
274 return $this->statuses;
278 * getCategories - Return result set of categories.
280 * @return object Database result set.
282 function getCategories () {
283 if (!$this->categories) {
284 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
285 array($this->getID()));
287 return $this->categories;
291 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
293 * @return array Of ProjectCategory objects.
295 function &getCategoryObjects() {
296 $res = $this->getCategories();
298 while ($arr = db_fetch_array($res)) {
299 $cats[] = new ProjectCategory($this,$arr);
305 * update - update a ProjectGroup in the database.
307 * @param string The project name.
308 * @param string The project description.
309 * @param string The email address to send new notifications to.
310 * @return boolean success.
312 function update($project_name, $description, $send_all_posts_to = '') {
313 if (strlen($project_name) < 3) {
314 $this->setError(_('Title Must Be At Least 5 Characters'));
317 if (strlen($description) < 10) {
318 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
322 if ($send_all_posts_to) {
323 $invalid_mails = validate_emails($send_all_posts_to);
324 if (count($invalid_mails) > 0) {
325 $this->setInvalidEmailError($send_all_posts_to);
330 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
331 $this->setPermissionDeniedError();
335 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
336 description=$2, send_all_posts_to=$3
337 WHERE group_id=$4 AND group_project_id=$5',
338 array(htmlspecialchars($project_name),
339 htmlspecialchars($description),
341 $this->Group->getID(),
344 if (!$res || db_affected_rows($res) < 1) {
345 $this->setError('Error On Update: '.db_error().$sql);
352 * delete - delete this subproject and all its related data.
354 * @param bool I'm Sure.
355 * @param bool I'm REALLY sure.
356 * @return bool true/false;
358 function delete($sure, $really_sure) {
359 if (!$sure || !$really_sure) {
360 $this->setMissingParamsError(_('Please tick all checkboxes.'));
363 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
364 $this->setPermissionDeniedError();
370 $res = db_query_params('DELETE FROM project_assigned_to
371 WHERE EXISTS (SELECT project_task_id FROM project_task
372 WHERE group_project_id=$1
373 AND project_task.project_task_id=project_assigned_to.project_task_id)',
374 array($this->getID()));
377 $this->setError('DATABASE '.db_error());
381 $res = db_query_params('DELETE FROM project_dependencies
382 WHERE EXISTS (SELECT project_task_id FROM project_task
383 WHERE group_project_id=$1
384 AND project_task.project_task_id=project_dependencies.project_task_id)',
385 array($this->getID()));
388 $this->setError('DATABASE '.db_error());
392 $res = db_query_params('DELETE FROM project_history
393 WHERE EXISTS (SELECT project_task_id FROM project_task
394 WHERE group_project_id=$1
395 AND project_task.project_task_id=project_history.project_task_id)',
396 array($this->getID()));
399 $this->setError('DATABASE '.db_error());
403 $res = db_query_params('DELETE FROM project_messages
404 WHERE EXISTS (SELECT project_task_id FROM project_task
405 WHERE group_project_id=$1
406 AND project_task.project_task_id=project_messages.project_task_id)',
407 array($this->getID()));
410 $this->setError('DATABASE '.db_error());
414 $res = db_query_params('DELETE FROM project_task_artifact
415 WHERE EXISTS (SELECT project_task_id FROM project_task
416 WHERE group_project_id=$1
417 AND project_task.project_task_id=project_task_artifact.project_task_id)',
418 array($this->getID()));
421 $this->setError('DATABASE '.db_error());
425 $res = db_query_params('DELETE FROM rep_time_tracking
426 WHERE EXISTS (SELECT project_task_id FROM project_task
427 WHERE group_project_id=$1
428 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
429 array($this->getID()));
432 $this->setError('DATABASE '.db_error());
436 $res = db_query_params ('DELETE FROM project_task
437 WHERE group_project_id=$1',
438 array ($this->getID()));
441 $this->setError('DATABASE '.db_error());
445 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
446 array ($this->getID()));
449 $this->setError('DATABASE '.db_error());
453 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
454 array ($this->getID()));
457 $this->setError('DATABASE '.db_error());
461 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
462 array ($this->getID()));
465 $this->setError('DATABASE '.db_error());
471 $this->Group->normalizeAllRoles();
479 // c-file-style: "bsd"