3 * GForge Project Management Facility
5 * Copyright 2002 GForge, LLC
10 * This file is part of GForge.
12 * GForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
29 By Tim Perdue, Sourceforge, 11/99
30 Heavy rewrite by Tim Perdue April 2000
32 Total rewrite in OO and GForge coding guidelines 12/2002 by Tim Perdue
35 require_once $gfcommon.'include/Error.class.php';
36 require_once $gfcommon.'pm/ProjectTask.class.php';
38 class ProjectTaskFactory extends Error {
41 * The ProjectGroup object.
43 * @var object $ProjectGroup.
48 * The project_tasks array.
50 * @var array project_tasks.
65 * @param object The ProjectGroup object to which this ProjectTask is associated.
66 * @return boolean success.
68 function ProjectTaskFactory(&$ProjectGroup) {
70 if (!$ProjectGroup || !is_object($ProjectGroup)) {
71 $this->setError('ProjectTask:: No Valid ProjectGroup Object');
74 if ($ProjectGroup->isError()) {
75 $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
78 $this->ProjectGroup =& $ProjectGroup;
79 $this->order='project_task_id';
86 * setup - sets up limits and sorts before you call getTasks().
88 * @param int The offset - number of rows to skip.
89 * @param string The way to order - ASC or DESC.
90 * @param int The max number of rows to return.
91 * @param string Whether to set these prefs into the user_prefs table - use "custom".
92 * @param int Include this param if you want to limit to a certain assignee.
93 * @param int Include this param if you want to limit to a certain category.
94 * @param string What view mode the screen should be in.
96 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='') {
97 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
98 if ((!$offset) || ($offset < 0)) {
101 $this->offset=$offset;
104 if (session_loggedin()) {
105 $u =& session_get_user();
109 if ($order=='project_task_id' || $order=='percent_complete'
110 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
111 if (session_loggedin()) {
112 $u->setPreference('pm_task_order', $order);
115 $order = 'project_task_id';
118 if (session_loggedin()) {
119 $order = $u->getPreference('pm_task_order');
123 $order = 'project_task_id';
127 if ($set=='custom') {
129 if this custom set is different than the stored one, reset preference
131 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
132 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID()))) {
133 //echo 'setting pref';
134 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID(),$pref_);
137 if (session_loggedin()) {
138 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID())) {
139 $prf_arr=explode('|',$pref_);
140 $_assigned_to=$prf_arr[0];
141 $_status=$prf_arr[1];
142 $_category_id=$prf_arr[2];
147 $this->status=$_status;
148 $this->assigned_to=$_assigned_to;
149 $this->category=$_category_id;
150 $this->view_type=$_view;
152 if (!$max_rows || $max_rows < 5) {
155 $this->max_rows=$max_rows;
159 * getTasks - get an array of ProjectTask objects.
161 * @return array The array of ProjectTask objects.
163 function &getTasks() {
164 if ($this->project_tasks) {
165 return $this->project_tasks;
168 //if status selected, and more to where clause
169 if ($this->status && ($this->status != 100)) {
170 //for open tasks, add status=100 to make sure we show all
171 $status_str="AND project_task_vw.status_id IN (".$this->status.(($this->status==1)?',100':'').")";
173 //no status was chosen, so don't add it to where clause
177 //if assigned to selected, and more to where clause
178 if ($this->assigned_to) {
179 $assigned_str="AND project_assigned_to.assigned_to_id='".$this->assigned_to."'";
180 $assigned_str2=',project_assigned_to';
181 $assigned_str3='project_task_vw.project_task_id=project_assigned_to.project_task_id AND';
184 //no assigned to was chosen, so don't add it to where clause
190 if ($this->category) {
191 $cat_str="AND project_task_vw.category_id='".$this->category."'";
197 // sort using an external ID useful only to something like MS Project
199 if ($this->order=='external_id') {
200 $ext_str='natural left join project_task_external_order';
201 $ext_fld_str=',project_task_external_order.external_id';
208 select project_task_vw.*,project_assigned_to.* FROM project_task_vw,project_assigned_to
209 WHERE project_assigned_to.project_task_id=project_task_vw.project_task_id;
211 $sql="SELECT project_task_vw.* $ext_fld_str
212 FROM project_task_vw $ext_str $assigned_str2
213 WHERE $assigned_str3 project_task_vw.group_project_id='". $this->ProjectGroup->getID() ."'
214 $assigned_str $status_str $cat_str
215 ORDER BY ".$this->order.(($this->order=='priority') ? ' DESC ':' ');
219 $result=db_query($sql,($this->max_rows),$this->offset);
220 $rows = db_numrows($result);
221 $this->fetched_rows=$rows;
223 $this->setError('Database Error: '.db_error().$sql);
227 $this->project_tasks = array();
228 while ($arr =& db_fetch_array($result)) {
229 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
231 return $this->project_tasks;