3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 require_once $gfcommon.'include/Error.class.php';
27 require_once $gfcommon.'pm/ProjectTask.class.php';
29 class ProjectTaskFactory extends Error {
32 * The ProjectGroup object.
34 * @var object $ProjectGroup.
39 * The project_tasks array.
41 * @var array project_tasks.
56 * @param object The ProjectGroup object to which this ProjectTask is associated.
57 * @return boolean success.
59 function ProjectTaskFactory(&$ProjectGroup) {
61 if (!$ProjectGroup || !is_object($ProjectGroup)) {
62 $this->setError('ProjectTask:: No Valid ProjectGroup Object');
65 if ($ProjectGroup->isError()) {
66 $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
69 $this->ProjectGroup =& $ProjectGroup;
70 $this->order='project_task_id';
77 * setup - sets up limits and sorts before you call getTasks().
79 * @param int The offset - number of rows to skip.
80 * @param string The way to order - ASC or DESC.
81 * @param int The max number of rows to return.
82 * @param string Whether to set these prefs into the user_prefs table - use "custom".
83 * @param int Include this param if you want to limit to a certain assignee.
84 * @param int Include this param if you want to limit to a certain category.
85 * @param string What view mode the screen should be in.
87 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='') {
88 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
89 if ((!$offset) || ($offset < 0)) {
92 $this->offset=$offset;
95 if (session_loggedin()) {
96 $u =& session_get_user();
100 if ($order=='project_task_id' || $order=='percent_complete'
101 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
102 if (session_loggedin()) {
103 $u->setPreference('pm_task_order', $order);
106 $order = 'project_task_id';
109 if (session_loggedin()) {
110 $order = $u->getPreference('pm_task_order');
114 $order = 'project_task_id';
118 if ($set=='custom') {
120 if this custom set is different than the stored one, reset preference
122 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
123 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID()))) {
124 //echo 'setting pref';
125 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID(),$pref_);
128 if (session_loggedin()) {
129 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID())) {
130 $prf_arr=explode('|',$pref_);
131 $_assigned_to=$prf_arr[0];
132 $_status=$prf_arr[1];
133 $_category_id=$prf_arr[2];
138 $this->status=$_status;
139 $this->assigned_to=$_assigned_to;
140 $this->category=$_category_id;
141 $this->view_type=$_view;
143 if (!$max_rows || $max_rows < 5) {
146 $this->max_rows=$max_rows;
150 * getTasks - get an array of ProjectTask objects.
152 * @return array The array of ProjectTask objects.
154 function &getTasks() {
155 if ($this->project_tasks) {
156 return $this->project_tasks;
159 //if status selected, and more to where clause
160 if ($this->status && ($this->status != 100)) {
161 //for open tasks, add status=100 to make sure we show all
162 $status_str="AND project_task_vw.status_id IN (".$this->status.(($this->status==1)?',100':'').")";
164 //no status was chosen, so don't add it to where clause
168 //if assigned to selected, and more to where clause
169 if ($this->assigned_to) {
170 if (is_array ($this->assigned_to)) {
171 $assigned_str="AND project_assigned_to.assigned_to_id IN (".join ($this->assigned_to,', ').")";
173 $assigned_str="AND project_assigned_to.assigned_to_id='".$this->assigned_to."'";
175 $assigned_str2=',project_assigned_to';
176 $assigned_str3='project_task_vw.project_task_id=project_assigned_to.project_task_id AND';
179 //no assigned to was chosen, so don't add it to where clause
185 if ($this->category) {
186 $cat_str="AND project_task_vw.category_id='".$this->category."'";
192 // sort using an external ID useful only to something like MS Project
194 if ($this->order=='external_id') {
195 $ext_str='natural left join project_task_external_order';
196 $ext_fld_str=',project_task_external_order.external_id';
203 select project_task_vw.*,project_assigned_to.* FROM project_task_vw,project_assigned_to
204 WHERE project_assigned_to.project_task_id=project_task_vw.project_task_id;
206 $sql="SELECT project_task_vw.* $ext_fld_str
207 FROM project_task_vw $ext_str $assigned_str2
208 WHERE $assigned_str3 project_task_vw.group_project_id='". $this->ProjectGroup->getID() ."'
209 $assigned_str $status_str $cat_str
210 ORDER BY ".$this->order.(($this->order=='priority') ? ' DESC ':' ');
214 $result=db_query($sql,($this->max_rows),$this->offset);
215 $rows = db_numrows($result);
216 $this->fetched_rows=$rows;
218 $this->setError('Database Error: '.db_error().$sql);
222 $this->project_tasks = array();
223 while ($arr =& db_fetch_array($result)) {
224 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
226 return $this->project_tasks;
233 // c-file-style: "bsd"