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/FFError.class.php';
28 require_once $gfcommon.'pm/ProjectTask.class.php';
30 class ProjectTaskFactory extends FFError {
33 * The ProjectGroup object.
35 * @var object $ProjectGroup.
40 * The project_tasks array.
42 * @var array project_tasks.
56 * @param ProjectGroup $ProjectGroup The ProjectGroup object to which this ProjectTask is associated.
58 function __construct(&$ProjectGroup) {
59 parent::__construct();
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 What to order.
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
86 * @param string $_sort_order The way to order - ASC or DESC.
89 function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='',$_sort_order = NULL) {
90 //echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
91 if ((!$offset) || ($offset < 0)) {
94 $this->offset=$offset;
97 if (session_loggedin()) {
98 $u =& session_get_user();
102 if ($order=='project_task_id' || $order=='percent_complete'
103 || $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
104 if (session_loggedin()) {
105 $u->setPreference('pm_task_order'.$this->ProjectGroup->getID(), $order);
108 $order = 'project_task_id';
111 if (session_loggedin()) {
112 $order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
116 $order = 'project_task_id';
119 if ($_sort_order=='ASC' || $_sort_order=='DESC') {
120 if (session_loggedin()) {
121 $u->setPreference('pm_task_sort_order'.$this->ProjectGroup->getID(), $_sort_order);
127 if (session_loggedin()) {
128 $_sort_order = $u->getPreference('pm_task_sort_order'.$this->ProjectGroup->getID());
133 $this->sort_order=$_sort_order;
135 if ($set=='custom') {
137 if this custom set is different than the stored one, reset preference
139 $pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
140 if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID()))) {
141 $u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
144 if (session_loggedin()) {
145 if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID())) {
146 $prf_arr=explode('|',$pref_);
147 $_assigned_to=$prf_arr[0];
148 $_status=$prf_arr[1];
149 $_category_id=$prf_arr[2];
154 $this->status=$_status;
155 $this->assigned_to=$_assigned_to;
156 $this->category=$_category_id;
157 $this->view_type=$_view;
159 if (!$max_rows || $max_rows < 5) {
162 $this->max_rows=$max_rows;
166 * getTasks - get an array of ProjectTask objects.
168 * @return array|bool ProjectTask[] The array of ProjectTask objects.
170 function &getTasks() {
171 if ($this->project_tasks) {
172 return $this->project_tasks;
174 $qpa = db_construct_qpa();
175 if ($this->sort_order) {
176 $order = "ORDER BY $this->order $this->sort_order" ;
178 if ($this->order=='priority') {
179 $order = 'ORDER BY priority DESC' ;
181 $order = "ORDER BY $this->order ASC" ;
184 if ($this->assigned_to) {
185 $tat = $this->assigned_to ;
186 if (! is_array ($tat))
187 $tat = array ($tat) ;
188 $qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
189 FROM project_task_vw natural left join project_task_external_order, project_assigned_to
190 WHERE project_task_vw.project_task_id = project_assigned_to.project_task_id ');
191 $qpa = db_construct_qpa($qpa, 'AND project_task_vw.group_project_id = $1 AND project_assigned_to.assigned_to_id = ANY ($2) ',
192 array ($this->ProjectGroup->getID(), db_int_array_to_any_clause ($tat)));
194 $qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
195 FROM project_task_vw natural left join project_task_external_order ');
196 $qpa = db_construct_qpa($qpa, 'WHERE project_task_vw.group_project_id = $1 ',
197 array ($this->ProjectGroup->getID()));
200 if ($this->status && ($this->status != 100)) {
201 $qpa = db_construct_qpa($qpa, ' AND project_task_vw.status_id = $1 ', array($this->status));
204 if ($this->category) {
205 $qpa = db_construct_qpa($qpa, ' AND project_task_vw.category_id = $1 ', array($this->category));
208 $qpa = db_construct_qpa($qpa, $order);
209 $result = db_query_qpa($qpa, $this->max_rows, $this->offset);
212 $this->setError('Database Error: '.db_error());
216 $rows = db_numrows($result);
217 $this->fetched_rows = $rows;
218 $this->project_tasks = array();
219 while ($arr = db_fetch_array($result)) {
220 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
222 return $this->project_tasks;
229 // c-file-style: "bsd"