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 ProjectGroup $ProjectGroup 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 $offset The offset - number of rows to skip.
79 * @param string $order The way to order - ASC or DESC.
80 * @param int $max_rows The max number of rows to return.
81 * @param string $set Whether to set these prefs into the user_prefs table - use "custom".
82 * @param int $_assigned_to Include this param if you want to limit to a certain assignee.
83 * @param int $_status Include this param if you want to limit to a certain category.
84 * @param $_category_id
85 * @param string $_view
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'.$this->ProjectGroup->getID(), $order);
106 $order = 'project_task_id';
109 if (session_loggedin()) {
110 $order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
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->getID()))) {
124 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
127 if (session_loggedin()) {
128 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID())) {
129 $prf_arr=explode('|',$pref_);
130 $_assigned_to=$prf_arr[0];
131 $_status=$prf_arr[1];
132 $_category_id=$prf_arr[2];
137 $this->status=$_status;
138 $this->assigned_to=$_assigned_to;
139 $this->category=$_category_id;
140 $this->view_type=$_view;
142 if (!$max_rows || $max_rows < 5) {
145 $this->max_rows=$max_rows;
149 * getTasks - get an array of ProjectTask objects.
151 * @return ProjectTask[] The array of ProjectTask objects.
153 function &getTasks() {
154 if ($this->project_tasks) {
155 return $this->project_tasks;
158 if ($this->order=='priority') {
159 $order = 'ORDER BY priority DESC' ;
161 $order = "ORDER BY $this->order ASC" ;
164 if ($this->assigned_to) {
165 $tat = $this->assigned_to ;
166 if (! is_array ($tat))
167 $tat = array ($tat) ;
169 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
170 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
171 WHERE project_task_vw.project_task_id=project_assigned_to.project_task_id
172 AND project_task_vw.group_project_id = $1
173 AND project_assigned_to.assigned_to_id = ANY ($2)' . $order,
174 array ($this->ProjectGroup->getID(),
175 db_int_array_to_any_clause ($tat)),
179 $result = db_query_params ('SELECT project_task_vw.*, project_task_external_order.external_id
180 FROM project_task_vw natural left join project_task_external_order
181 WHERE project_task_vw.group_project_id = $1' . $order,
182 array ($this->ProjectGroup->getID()),
187 $rows = db_numrows($result);
188 $this->fetched_rows=$rows;
190 $this->setError('Database Error: '.db_error());
194 $this->project_tasks = array();
195 while ($arr = db_fetch_array($result)) {
196 if ($this->status && ($this->status != 100)) {
197 if ($this->status == 1) {
198 if ($arr['status_id'] != 1 && $arr['status_id'] != 100)
201 if ($arr['status_id'] != $this->status)
206 if ($this->category) {
207 if ($arr['category_id'] != $this->category)
211 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
213 return $this->project_tasks;
220 // c-file-style: "bsd"