3 * FusionForge project manager
5 * Copyright 1999-2000, Tim Perdue/Sourceforge
6 * Copyright 2002, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2014, Franck Villaume - TrivialDev
9 * Copyright 2014, Stéphane-Eymeric Bredthauer
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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.
58 * @param ProjectGroup $ProjectGroup The ProjectGroup object to which this ProjectTask is associated.
59 * @return boolean success.
61 function ProjectTaskFactory(&$ProjectGroup) {
63 if (!$ProjectGroup || !is_object($ProjectGroup)) {
64 $this->setError('ProjectTask: No Valid ProjectGroup Object');
67 if ($ProjectGroup->isError()) {
68 $this->setError('ProjectTask: '.$ProjectGroup->getErrorMessage());
71 $this->ProjectGroup =& $ProjectGroup;
72 $this->order='project_task_id';
79 * setup - sets up limits and sorts before you call getTasks().
81 * @param int $offset The offset - number of rows to skip.
82 * @param string $order What to order.
83 * @param int $max_rows The max number of rows to return.
84 * @param string $set Whether to set these prefs into the user_prefs table - use "custom".
85 * @param int $_assigned_to Include this param if you want to limit to a certain assignee.
86 * @param int $_status Include this param if you want to limit to a certain category.
87 * @param $_category_id
88 * @param string $_view
89 * @param string $_sort_order The way to order - ASC or DESC.
92 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='',$_sort_order = NULL) {
93 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
94 if ((!$offset) || ($offset < 0)) {
97 $this->offset=$offset;
100 if (session_loggedin()) {
101 $u =& session_get_user();
105 if ($order=='project_task_id' || $order=='percent_complete'
106 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
107 if (session_loggedin()) {
108 $u->setPreference('pm_task_order'.$this->ProjectGroup->getID(), $order);
111 $order = 'project_task_id';
114 if (session_loggedin()) {
115 $order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
119 $order = 'project_task_id';
122 if ($_sort_order=='ASC' || $_sort_order=='DESC') {
123 if (session_loggedin()) {
124 $u->setPreference('pm_task_sort_order'.$this->ProjectGroup->getID(), $_sort_order);
130 if (session_loggedin()) {
131 $_sort_order = $u->getPreference('pm_task_sort_order'.$this->ProjectGroup->getID());
136 $this->sort_order=$_sort_order;
138 if ($set=='custom') {
140 if this custom set is different than the stored one, reset preference
142 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
143 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID()))) {
144 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
147 if (session_loggedin()) {
148 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID())) {
149 $prf_arr=explode('|',$pref_);
150 $_assigned_to=$prf_arr[0];
151 $_status=$prf_arr[1];
152 $_category_id=$prf_arr[2];
157 $this->status=$_status;
158 $this->assigned_to=$_assigned_to;
159 $this->category=$_category_id;
160 $this->view_type=$_view;
162 if (!$max_rows || $max_rows < 5) {
165 $this->max_rows=$max_rows;
169 * getTasks - get an array of ProjectTask objects.
171 * @return array ProjectTask[] The array of ProjectTask objects.
173 function &getTasks() {
174 if ($this->project_tasks) {
175 return $this->project_tasks;
177 $qpa = db_construct_qpa();
178 if ($this->sort_order) {
179 $order = "ORDER BY $this->order $this->sort_order" ;
181 if ($this->order=='priority') {
182 $order = 'ORDER BY priority DESC' ;
184 $order = "ORDER BY $this->order ASC" ;
187 if ($this->assigned_to) {
188 $tat = $this->assigned_to ;
189 if (! is_array ($tat))
190 $tat = array ($tat) ;
191 $qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
192 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
193 WHERE project_task_vw.project_task_id = project_assigned_to.project_task_id ');
194 $qpa = db_construct_qpa($qpa, 'AND project_task_vw.group_project_id = $1 AND project_assigned_to.assigned_to_id = ANY ($2) ',
195 array ($this->ProjectGroup->getID(), db_int_array_to_any_clause ($tat)));
197 $qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
198 FROM project_task_vw natural left join project_task_external_order ');
199 $qpa = db_construct_qpa($qpa, 'WHERE project_task_vw.group_project_id = $1 ',
200 array ($this->ProjectGroup->getID()));
203 if ($this->status == 1 || $this->status == 2 || $this->status == 3) {
204 $qpa = db_construct_qpa($qpa, ' AND project_task_vw.status_id = $1 ', array($this->status));
207 if ($this->category) {
208 $qpa = db_construct_qpa($qpa, ' AND project_task_vw.category_id = $1 ', array($this->category));
211 $qpa = db_construct_qpa($qpa, $order);
212 $result = db_query_qpa($qpa, $this->max_rows, $this->offset);
215 $this->setError('Database Error: '.db_error());
219 $rows = db_numrows($result);
220 $this->fetched_rows = $rows;
221 $this->project_tasks = array();
222 while ($arr = db_fetch_array($result)) {
223 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
225 return $this->project_tasks;
232 // c-file-style: "bsd"