3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2014, Franck Villaume - TrivialDev
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/FFError.class.php';
29 * Fetches a ProjectGroup object from the database
31 * @param array $group_project_id whether or not the db result handle is passed in
33 * @return ProjectGroup the ProjectGroup object
35 function &projectgroup_get_object($group_project_id, $data = false) {
36 global $PROJECTGROUP_OBJ;
37 if (!isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
39 //the db result handle was passed in
41 $res = db_query_params('SELECT * FROM project_group_list_vw WHERE group_project_id=$1',
42 array($group_project_id));
43 if (db_numrows($res) <1 ) {
44 $PROJECTGROUP_OBJ["_".$group_project_id."_"]=false;
47 $data = db_fetch_array($res);
49 $Group = group_get_object($data["group_id"]);
50 $PROJECTGROUP_OBJ["_".$group_project_id."_"]= new ProjectGroup($Group,$group_project_id,$data);
52 return $PROJECTGROUP_OBJ["_".$group_project_id."_"];
55 function projectgroup_get_groupid($group_project_id) {
56 global $PROJECTGROUP_OBJ;
57 if (isset($PROJECTGROUP_OBJ["_".$group_project_id."_"])) {
58 return $PROJECTGROUP_OBJ["_".$group_project_id."_"]->Group->getID() ;
61 $res = db_query_params('SELECT group_id FROM project_group_list WHERE group_project_id=$1',
62 array($group_project_id));
63 if (!$res || db_numrows($res) < 1) {
66 $arr = db_fetch_array($res);
67 return $arr['group_id'];
70 class ProjectGroup extends FFError {
73 * Associative array of data from db.
75 * @var array $data_array.
93 * @param bool $group_project_id
95 * @internal param \The $object Group object to which this forum is associated.
96 * @internal param \The $int group_project_id.
97 * @internal param \The $array associative array of data.
98 * @return \ProjectGroup
100 function ProjectGroup(&$Group, $group_project_id = false, $arr = false) {
101 parent::__construct();
102 if (!$Group || !is_object($Group)) {
103 $this->setError(_('No Valid Group Object'));
106 if ($Group->isError()) {
107 $this->setError('ProjectGroup: '.$Group->getErrorMessage());
110 $this->Group =& $Group;
112 if ($group_project_id) {
113 if (!$arr || !is_array($arr)) {
114 if (!$this->fetchData($group_project_id)) {
118 $this->data_array =& $arr;
119 if ($this->data_array['group_id'] != $this->Group->getID()) {
120 $this->setError('Group_id in db result does not match Group Object');
125 // Make sure they can even access this object
127 if (!forge_check_perm ('pm', $this->getID(), 'read')) {
128 $this->setPermissionDeniedError();
129 $this->data_array = null;
136 * create - create a new ProjectGroup in the database.
138 * @param string $project_name The project name.
139 * @param string $description The project description.
140 * @param string $send_all_posts_to The email address to send new notifications to.
141 * @return bool success.
143 function create($project_name,$description,$send_all_posts_to='') {
144 if (strlen($project_name) < 3) {
145 $this->setError(_('Title Must Be At Least 5 Characters'));
148 if (strlen($description) < 10) {
149 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
152 if ($send_all_posts_to) {
153 $invalid_mails = validate_emails($send_all_posts_to);
154 if (count($invalid_mails) > 0) {
155 $this->setInvalidEmailError($send_all_posts_to);
160 if (!forge_check_perm ('pm_admin', $this->Group->getID())) {
161 $this->setPermissionDeniedError();
166 $result = db_query_params('INSERT INTO project_group_list (group_id,project_name,description,send_all_posts_to) VALUES ($1,$2,$3,$4)',
167 array($this->Group->getId(),
168 htmlspecialchars($project_name),
169 htmlspecialchars($description),
170 $send_all_posts_to));
172 $this->setError('Error Adding ProjectGroup: '.db_error());
176 $this->group_project_id=db_insertid($result,'project_group_list','group_project_id');
177 $this->fetchData($this->group_project_id);
178 $this->Group->normalizeAllRoles () ;
186 * fetchData - re-fetch the data for this ProjectGroup from the database.
188 * @param int $group_project_id The project group ID.
189 * @return bool success.
191 function fetchData($group_project_id) {
192 $res = db_query_params ('SELECT * FROM project_group_list_vw WHERE group_project_id=$1 AND group_id=$2',
193 array ($group_project_id,
194 $this->Group->getID())) ;
195 if (!$res || db_numrows($res) < 1) {
196 $this->setError(_('Invalid group_project_id'));
199 $this->data_array = db_fetch_array($res);
200 db_free_result($res);
205 * getGroup - get the Group object this ProjectGroup is associated with.
207 * @return Group The Group object.
209 function &getGroup() {
214 * getID - get this GroupProjectID.
216 * @return int The group_project_id #.
219 return $this->data_array['group_project_id'];
223 * getOpenCount - get the count of open tracker items in this tracker type.
225 * @return int The count.
227 function getOpenCount() {
228 return $this->data_array['open_count'];
232 * getTotalCount - get the total number of tracker items in this tracker type.
234 * @return int The total count.
236 function getTotalCount() {
237 return $this->data_array['count'];
241 * getCount - get the number of tasks item in this pm type per status and category
243 * @param int $status_id the status id
244 * @param int $category_id the category id
245 * @return int the count
247 function getCount($status_id, $category_id) {
248 $qpa = db_construct_qpa();
249 $qpa = db_construct_qpa($qpa, 'SELECT count(project_task_id) FROM project_task WHERE group_project_id = $1', array($this->getID()));
251 $qpa = db_construct_qpa($qpa, ' AND category_id = $1 ', array($category_id));
253 if (is_int($status_id) && $status_id != 100) {
254 $qpa = db_construct_qpa($qpa, ' AND status_id = $1 ', array($status_id));
256 $res = db_query_qpa($qpa);
257 $arr = db_fetch_array($res);
262 * getName - get the name of this projectGroup.
264 * @return string The name of this projectGroup.
267 return $this->data_array['project_name'];
271 * getSendAllPostsTo - an optional email address to send all task updates to.
273 * @return string The email address.
275 function getSendAllPostsTo() {
276 return $this->data_array['send_all_posts_to'];
280 * getDescription - the description of this ProjectGroup.
282 * @return string The description.
284 function getDescription() {
285 return $this->data_array['description'];
289 * getStatuses - Return result set of statuses.
291 * @return object Database result set.
293 function getStatuses() {
294 if (!$this->statuses) {
295 $this->statuses = db_query_params('SELECT * FROM project_status',
298 return $this->statuses;
302 * getCategories - Return result set of categories.
304 * @return object Database result set.
306 function getCategories() {
307 if (!$this->categories) {
308 $this->categories = db_query_params('SELECT category_id,category_name FROM project_category WHERE group_project_id=$1',
309 array($this->getID()));
311 return $this->categories;
315 * getCategoryObjects - Array of ProjectCategory objects set up for this artifact type.
317 * @return array Of ProjectCategory objects.
319 function &getCategoryObjects() {
320 $res = $this->getCategories();
322 while ($arr = db_fetch_array($res)) {
323 $cats[] = new ProjectCategory($this,$arr);
329 * update - update a ProjectGroup in the database.
331 * @param string $project_name The project name.
332 * @param string $description The project description.
333 * @param string $send_all_posts_to The email address to send new notifications to.
334 * @return boolean success.
336 function update($project_name, $description, $send_all_posts_to = '') {
337 if (strlen($project_name) < 3) {
338 $this->setError(_('Title Must Be At Least 5 Characters'));
341 if (strlen($description) < 10) {
342 $this->setError(_('Subproject Description Must Be At Least 10 Characters'));
346 if ($send_all_posts_to) {
347 $invalid_mails = validate_emails($send_all_posts_to);
348 if (count($invalid_mails) > 0) {
349 $this->setInvalidEmailError($send_all_posts_to);
354 if (!forge_check_perm ('pm', $this->getID(), 'manager')) {
355 $this->setPermissionDeniedError();
359 $res = db_query_params('UPDATE project_group_list SET project_name=$1,
360 description=$2, send_all_posts_to=$3
361 WHERE group_id=$4 AND group_project_id=$5',
362 array(htmlspecialchars($project_name),
363 htmlspecialchars($description),
365 $this->Group->getID(),
368 if (!$res || db_affected_rows($res) < 1) {
369 $this->setError(_('Error On Update')._(': ').db_error());
376 * delete - delete this subproject and all its related data.
378 * @param bool $sure I'm Sure.
379 * @param bool $really_sure I'm REALLY sure.
380 * @return bool true/false;
382 function delete($sure, $really_sure) {
383 if (!$sure || !$really_sure) {
384 $this->setMissingParamsError(_('Please tick all checkboxes.'));
387 if (!forge_check_perm('pm', $this->getID(), 'manager')) {
388 $this->setPermissionDeniedError();
394 $res = db_query_params('DELETE FROM project_assigned_to
395 WHERE EXISTS (SELECT project_task_id FROM project_task
396 WHERE group_project_id=$1
397 AND project_task.project_task_id=project_assigned_to.project_task_id)',
398 array($this->getID()));
401 $this->setError('DATABASE '.db_error());
405 $res = db_query_params('DELETE FROM project_dependencies
406 WHERE EXISTS (SELECT project_task_id FROM project_task
407 WHERE group_project_id=$1
408 AND project_task.project_task_id=project_dependencies.project_task_id)',
409 array($this->getID()));
412 $this->setError('DATABASE '.db_error());
416 $res = db_query_params('DELETE FROM project_history
417 WHERE EXISTS (SELECT project_task_id FROM project_task
418 WHERE group_project_id=$1
419 AND project_task.project_task_id=project_history.project_task_id)',
420 array($this->getID()));
423 $this->setError('DATABASE '.db_error());
427 $res = db_query_params('DELETE FROM project_messages
428 WHERE EXISTS (SELECT project_task_id FROM project_task
429 WHERE group_project_id=$1
430 AND project_task.project_task_id=project_messages.project_task_id)',
431 array($this->getID()));
434 $this->setError('DATABASE '.db_error());
438 $res = db_query_params('DELETE FROM project_task_artifact
439 WHERE EXISTS (SELECT project_task_id FROM project_task
440 WHERE group_project_id=$1
441 AND project_task.project_task_id=project_task_artifact.project_task_id)',
442 array($this->getID()));
445 $this->setError('DATABASE '.db_error());
449 $res = db_query_params('DELETE FROM rep_time_tracking
450 WHERE EXISTS (SELECT project_task_id FROM project_task
451 WHERE group_project_id=$1
452 AND project_task.project_task_id=rep_time_tracking.project_task_id)',
453 array($this->getID()));
456 $this->setError('DATABASE '.db_error());
460 $res = db_query_params ('DELETE FROM project_task
461 WHERE group_project_id=$1',
462 array ($this->getID()));
465 $this->setError('DATABASE '.db_error());
469 $res = db_query_params ('DELETE FROM project_category WHERE group_project_id=$1',
470 array ($this->getID()));
473 $this->setError('DATABASE '.db_error());
477 $res = db_query_params ('DELETE FROM project_group_list WHERE group_project_id=$1',
478 array ($this->getID()));
481 $this->setError('DATABASE '.db_error());
485 $res = db_query_params ('DELETE FROM project_counts_agg WHERE group_project_id=$1',
486 array ($this->getID()));
489 $this->setError('DATABASE '.db_error());
495 $this->Group->normalizeAllRoles();
502 // c-file-style: "bsd"