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'.$this->ProjectGroup->getID(), $order);
107 $order = 'project_task_id';
110 if (session_loggedin()) {
111 $order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
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->getID()))) {
125 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
128 if (session_loggedin()) {
129 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->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 ($this->order=='priority') {
160 $order = 'ORDER BY priority DESC' ;
162 $order = "ORDER BY $this->order ASC" ;
165 if ($this->assigned_to) {
166 $tat = $this->assigned_to ;
167 if (! is_array ($tat))
168 $tat = array ($tat) ;
170 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
171 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
172 WHERE project_task_vw.project_task_id=project_assigned_to.project_task_id
173 AND project_task_vw.group_project_id = $1
174 AND project_assigned_to.assigned_to_id = ANY ($2)' . $order,
175 array ($this->ProjectGroup->getID(),
176 db_int_array_to_any_clause ($tat)),
180 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
181 FROM project_task_vw natural left join project_task_external_order
182 WHERE project_task_vw.group_project_id = $1' . $order,
183 array ($this->ProjectGroup->getID()),
188 $rows = db_numrows($result);
189 $this->fetched_rows=$rows;
191 $this->setError('Database Error: '.db_error().$sql);
195 $this->project_tasks = array();
196 while ($arr =& db_fetch_array($result)) {
197 if ($this->status && ($this->status != 100)) {
198 if ($this->status == 1) {
199 if ($arr['status_id'] != 1 && $arr['status_id'] != 100)
202 if ($arr['status_id'] != $this->status)
207 if ($this->category) {
208 if ($arr['category_id'] != $this->category)
212 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
214 return $this->project_tasks;
221 // c-file-style: "bsd"