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 array $group_project_id 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.
92 * @param bool $group_project_id
94 * @internal param \The $object Group object to which this forum is associated.
95 * @internal param \The $int group_project_id.
96 * @internal param \The $array associative array of data.
97 * @return \ProjectGroup
99 function ProjectGroup(&$Group, $group_project_id = false, $arr = false) {
101 if (!$Group || !is_object($Group)) {
102 $this->setError(_('No Valid Group Object'));
105 if ($Group->isError()) {
106 $this->setError('ProjectGroup: '.$Group->getErrorMessage());
109 $this->Group =& $Group;
111 if ($group_project_id) {
112 if (!$arr || !is_array($arr)) {
113 if (!$this->fetchData($group_project_id)) {
117 $this->data_array =& $arr;
118 if ($this->data_array['group_id'] != $this->Group->getID()) {
119 $this->setError('Group_id in db result does not match Group Object');
124 // Make sure they can even access this object
126 if (!forge_check_perm ('pm', $this->getID(), 'read')) {
127 $this->setPermissionDeniedError();
128 $this->data_array = null;
135 * create - create a new ProjectGroup in the database.
137 * @param string $project_name The project name.
138 * @param string $description The project description. * @param string The email address to send new notifications to.
139 * @param string $send_all_posts_to The email address to send new notifications to.
140 * @return bool success.
142 function create($project_name,$description,$send_all_posts_to='') {
143 if (strlen($project_name) < 3) {
144 $this->setError(_('Title Must Be At Least 5 Characters'));
147 if (strlen($description) < 10) {
148 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
151 if ($send_all_posts_to) {
152 $invalid_mails = validate_emails($send_all_posts_to);
153 if (count($invalid_mails) > 0) {
154 $this->setInvalidEmailError($send_all_posts_to);
159 if (!forge_check_perm ('pm_admin', $this->Group->getID())) {
160 $this->setPermissionDeniedError();
165 $result = db_query_params('INSERT INTO project_group_list (group_id,project_name,description,send_all_posts_to) VALUES ($1,$2,$3,$4)',
166 array($this->Group->getId(),
167 htmlspecialchars($project_name),
168 htmlspecialchars($description),
169 $send_all_posts_to));
171 $this->setError('Error Adding ProjectGroup: '.db_error());
175 $this->group_project_id=db_insertid($result,'project_group_list','group_project_id');
176 $this->fetchData($this->group_project_id);
177 $this->Group->normalizeAllRoles () ;
185 * fetchData - re-fetch the data for this ProjectGroup from the database.
187 * @param int $group_project_id The project group ID.
188 * @return bool success.
190 function fetchData($group_project_id) {
191 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
192 array ($group_project_id,
193 $this->Group->getID())) ;
194 if (!$res || db_numrows($res) < 1) {
195 $this->setError(_('Invalid group_project_id'));
198 $this->data_array = db_fetch_array($res);
199 db_free_result($res);
204 * getGroup - get the Group object this ProjectGroup is associated with.
206 * @return Group The Group object.
208 function &getGroup() {
213 * getID - get this GroupProjectID.
215 * @return int The group_project_id #.
218 return $this->data_array['group_project_id'];
222 * getOpenCount - get the count of open tracker items in this tracker type.
224 * @return int The count.
226 function getOpenCount() {
227 return $this->data_array['open_count'];
231 * getTotalCount - get the total number of tracker items in this tracker type.
233 * @return int The total count.
235 function getTotalCount() {
236 return $this->data_array['count'];
240 * getName - get the name of this projectGroup.
242 * @return string The name of this projectGroup.
245 return $this->data_array['project_name'];
249 * getSendAllPostsTo - an optional email address to send all task updates to.
251 * @return string The email address.
253 function getSendAllPostsTo() {
254 return $this->data_array['send_all_posts_to'];
258 * getDescription - the description of this ProjectGroup.
260 * @return string The description.
262 function getDescription() {
263 return $this->data_array['description'];
267 * getStatuses - Return result set of statuses.
269 * @return object Database result set.
271 function getStatuses() {
272 if (!$this->statuses) {
273 $this->statuses = db_query_params('SELECT * FROM project_status',
276 return $this->statuses;
280 * getCategories - Return result set of categories.
282 * @return object Database result set.
284 function getCategories () {
285 if (!$this->categories) {
286 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
287 array($this->getID()));
289 return $this->categories;
293 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
295 * @return array Of ProjectCategory objects.
297 function &getCategoryObjects() {
298 $res = $this->getCategories();
300 while ($arr = db_fetch_array($res)) {
301 $cats[] = new ProjectCategory($this,$arr);
307 * update - update a ProjectGroup in the database.
309 * @param string The project name.
310 * @param string The project description.
311 * @param string The email address to send new notifications to.
312 * @return boolean success.
314 function update($project_name, $description, $send_all_posts_to = '') {
315 if (strlen($project_name) < 3) {
316 $this->setError(_('Title Must Be At Least 5 Characters'));
319 if (strlen($description) < 10) {
320 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
324 if ($send_all_posts_to) {
325 $invalid_mails = validate_emails($send_all_posts_to);
326 if (count($invalid_mails) > 0) {
327 $this->setInvalidEmailError($send_all_posts_to);
332 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
333 $this->setPermissionDeniedError();
337 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
338 description=$2, send_all_posts_to=$3
339 WHERE group_id=$4 AND group_project_id=$5',
340 array(htmlspecialchars($project_name),
341 htmlspecialchars($description),
343 $this->Group->getID(),
346 if (!$res || db_affected_rows($res) < 1) {
347 $this->setError(sprintf(_('Error On Update: %s'), db_error()));
354 * delete - delete this subproject and all its related data.
356 * @param bool $sure I'm Sure.
357 * @param bool $really_sure I'm REALLY sure.
358 * @return bool true/false;
360 function delete($sure, $really_sure) {
361 if (!$sure || !$really_sure) {
362 $this->setMissingParamsError(_('Please tick all checkboxes.'));
365 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
366 $this->setPermissionDeniedError();
372 $res = db_query_params('DELETE FROM project_assigned_to
373 WHERE EXISTS (SELECT project_task_id FROM project_task
374 WHERE group_project_id=$1
375 AND project_task.project_task_id=project_assigned_to.project_task_id)',
376 array($this->getID()));
379 $this->setError('DATABASE '.db_error());
383 $res = db_query_params('DELETE FROM project_dependencies
384 WHERE EXISTS (SELECT project_task_id FROM project_task
385 WHERE group_project_id=$1
386 AND project_task.project_task_id=project_dependencies.project_task_id)',
387 array($this->getID()));
390 $this->setError('DATABASE '.db_error());
394 $res = db_query_params('DELETE FROM project_history
395 WHERE EXISTS (SELECT project_task_id FROM project_task
396 WHERE group_project_id=$1
397 AND project_task.project_task_id=project_history.project_task_id)',
398 array($this->getID()));
401 $this->setError('DATABASE '.db_error());
405 $res = db_query_params('DELETE FROM project_messages
406 WHERE EXISTS (SELECT project_task_id FROM project_task
407 WHERE group_project_id=$1
408 AND project_task.project_task_id=project_messages.project_task_id)',
409 array($this->getID()));
412 $this->setError('DATABASE '.db_error());
416 $res = db_query_params('DELETE FROM project_task_artifact
417 WHERE EXISTS (SELECT project_task_id FROM project_task
418 WHERE group_project_id=$1
419 AND project_task.project_task_id=project_task_artifact.project_task_id)',
420 array($this->getID()));
423 $this->setError('DATABASE '.db_error());
427 $res = db_query_params('DELETE FROM rep_time_tracking
428 WHERE EXISTS (SELECT project_task_id FROM project_task
429 WHERE group_project_id=$1
430 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
431 array($this->getID()));
434 $this->setError('DATABASE '.db_error());
438 $res = db_query_params ('DELETE FROM project_task
439 WHERE group_project_id=$1',
440 array ($this->getID()));
443 $this->setError('DATABASE '.db_error());
447 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
448 array ($this->getID()));
451 $this->setError('DATABASE '.db_error());
455 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
456 array ($this->getID()));
459 $this->setError('DATABASE '.db_error());
463 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
464 array ($this->getID()));
467 $this->setError('DATABASE '.db_error());
473 $this->Group->normalizeAllRoles();
480 // c-file-style: "bsd"