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. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 require_once $gfcommon.'include/Error.class.php';
26 require_once $gfcommon.'pm/ProjectTask.class.php';
28 class ProjectTaskFactory extends Error {
31 * The ProjectGroup object.
33 * @var object $ProjectGroup.
38 * The project_tasks array.
40 * @var array project_tasks.
55 * @param object The ProjectGroup object to which this ProjectTask is associated.
56 * @return boolean success.
58 function ProjectTaskFactory(&$ProjectGroup) {
60 if (!$ProjectGroup || !is_object($ProjectGroup)) {
61 $this->setError('ProjectTask:: No Valid ProjectGroup Object');
64 if ($ProjectGroup->isError()) {
65 $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
68 $this->ProjectGroup =& $ProjectGroup;
69 $this->order='project_task_id';
76 * setup - sets up limits and sorts before you call getTasks().
78 * @param int The offset - number of rows to skip.
79 * @param string The way to order - ASC or DESC.
80 * @param int The max number of rows to return.
81 * @param string Whether to set these prefs into the user_prefs table - use "custom".
82 * @param int Include this param if you want to limit to a certain assignee.
83 * @param int Include this param if you want to limit to a certain category.
84 * @param string What view mode the screen should be in.
86 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='') {
87 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
88 if ((!$offset) || ($offset < 0)) {
91 $this->offset=$offset;
94 if (session_loggedin()) {
95 $u =& session_get_user();
99 if ($order=='project_task_id' || $order=='percent_complete'
100 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
101 if (session_loggedin()) {
102 $u->setPreference('pm_task_order'.$this->ProjectGroup->getID(), $order);
105 $order = 'project_task_id';
108 if (session_loggedin()) {
109 $order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
113 $order = 'project_task_id';
117 if ($set=='custom') {
119 if this custom set is different than the stored one, reset preference
121 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
122 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID()))) {
123 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
126 if (session_loggedin()) {
127 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID())) {
128 $prf_arr=explode('|',$pref_);
129 $_assigned_to=$prf_arr[0];
130 $_status=$prf_arr[1];
131 $_category_id=$prf_arr[2];
136 $this->status=$_status;
137 $this->assigned_to=$_assigned_to;
138 $this->category=$_category_id;
139 $this->view_type=$_view;
141 if (!$max_rows || $max_rows < 5) {
144 $this->max_rows=$max_rows;
148 * getTasks - get an array of ProjectTask objects.
150 * @return array The array of ProjectTask objects.
152 function &getTasks() {
153 if ($this->project_tasks) {
154 return $this->project_tasks;
157 if ($this->order=='priority') {
158 $order = 'ORDER BY priority DESC' ;
160 $order = "ORDER BY $this->order ASC" ;
163 if ($this->assigned_to) {
164 $tat = $this->assigned_to ;
165 if (! is_array ($tat))
166 $tat = array ($tat) ;
168 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
169 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
170 WHERE project_task_vw.project_task_id=project_assigned_to.project_task_id
171 AND project_task_vw.group_project_id = $1
172 AND project_assigned_to.assigned_to_id = ANY ($2)' . $order,
173 array ($this->ProjectGroup->getID(),
174 db_int_array_to_any_clause ($tat)),
178 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
179 FROM project_task_vw natural left join project_task_external_order
180 WHERE project_task_vw.group_project_id = $1' . $order,
181 array ($this->ProjectGroup->getID()),
186 $rows = db_numrows($result);
187 $this->fetched_rows=$rows;
189 $this->setError('Database Error: '.db_error().$sql);
193 $this->project_tasks = array();
194 while ($arr = db_fetch_array($result)) {
195 if ($this->status && ($this->status != 100)) {
196 if ($this->status == 1) {
197 if ($arr['status_id'] != 1 && $arr['status_id'] != 100)
200 if ($arr['status_id'] != $this->status)
205 if ($this->category) {
206 if ($arr['category_id'] != $this->category)
210 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
212 return $this->project_tasks;
219 // c-file-style: "bsd"