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.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation; either version 2 of the License,
14 * or (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 require_once $gfcommon.'include/Error.class.php';
28 require_once $gfcommon.'pm/ProjectTask.class.php';
30 class ProjectTaskFactory extends Error {
33 * The ProjectGroup object.
35 * @var object $ProjectGroup.
40 * The project_tasks array.
42 * @var array project_tasks.
57 * @param object The ProjectGroup object to which this ProjectTask is associated.
58 * @return boolean success.
60 function ProjectTaskFactory(&$ProjectGroup) {
62 if (!$ProjectGroup || !is_object($ProjectGroup)) {
63 $this->setError('ProjectTask:: No Valid ProjectGroup Object');
66 if ($ProjectGroup->isError()) {
67 $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
70 $this->ProjectGroup =& $ProjectGroup;
71 $this->order='project_task_id';
78 * setup - sets up limits and sorts before you call getTasks().
80 * @param int The offset - number of rows to skip.
81 * @param string The way to order - ASC or DESC.
82 * @param int The max number of rows to return.
83 * @param string Whether to set these prefs into the user_prefs table - use "custom".
84 * @param int Include this param if you want to limit to a certain assignee.
85 * @param int Include this param if you want to limit to a certain category.
86 * @param string What view mode the screen should be in.
88 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='') {
89 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
90 if ((!$offset) || ($offset < 0)) {
93 $this->offset=$offset;
96 if (session_loggedin()) {
97 $u =& session_get_user();
101 if ($order=='project_task_id' || $order=='percent_complete'
102 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
103 if (session_loggedin()) {
104 $u->setPreference('pm_task_order', $order);
107 $order = 'project_task_id';
110 if (session_loggedin()) {
111 $order = $u->getPreference('pm_task_order');
115 $order = 'project_task_id';
119 if ($set=='custom') {
121 if this custom set is different than the stored one, reset preference
123 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
124 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID()))) {
125 //echo 'setting pref';
126 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID(),$pref_);
129 if (session_loggedin()) {
130 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->Group->getID())) {
131 $prf_arr=explode('|',$pref_);
132 $_assigned_to=$prf_arr[0];
133 $_status=$prf_arr[1];
134 $_category_id=$prf_arr[2];
139 $this->status=$_status;
140 $this->assigned_to=$_assigned_to;
141 $this->category=$_category_id;
142 $this->view_type=$_view;
144 if (!$max_rows || $max_rows < 5) {
147 $this->max_rows=$max_rows;
151 * getTasks - get an array of ProjectTask objects.
153 * @return array The array of ProjectTask objects.
155 function &getTasks() {
156 if ($this->project_tasks) {
157 return $this->project_tasks;
160 if ($this->order=='priority') {
161 $order = 'ORDER BY priority DESC' ;
163 $order = "ORDER BY $this->order ASC" ;
166 if ($this->assigned_to) {
167 $tat = $this->assigned_to ;
168 if (! is_array ($tat))
169 $tat = array ($tat) ;
171 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
172 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
173 WHERE project_task_vw.project_task_id=project_assigned_to.project_task_id
174 AND project_task_vw.group_project_id = $1
175 AND project_assigned_to.assigned_to_id = ANY ($2)' . $order,
176 array ($this->ProjectGroup->getID(),
177 db_int_array_to_any_clause ($tat)),
181 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
182 FROM project_task_vw natural left join project_task_external_order
183 WHERE project_task_vw.group_project_id = $1' . $order,
184 array ($this->ProjectGroup->getID()),
189 $rows = db_numrows($result);
190 $this->fetched_rows=$rows;
192 $this->setError('Database Error: '.db_error().$sql);
196 $this->project_tasks = array();
197 while ($arr =& db_fetch_array($result)) {
198 if ($this->status && ($this->status != 100)) {
199 if ($this->status == 1) {
200 if ($arr['status_id'] != 1 && $arr['status_id'] != 100)
203 if ($arr['status_id'] != $this->status)
208 if ($this->category) {
209 if ($arr['category_id'] != $this->category_id)
213 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
215 return $this->project_tasks;
222 // c-file-style: "bsd"