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
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'include/Error.class.php';
27 require_once $gfcommon.'pm/ProjectTask.class.php';
29 class ProjectTaskFactory extends Error {
32 * The ProjectGroup object.
34 * @var object $ProjectGroup.
39 * The project_tasks array.
41 * @var array project_tasks.
56 * @param ProjectGroup $ProjectGroup The ProjectGroup object to which this ProjectTask is associated.
57 * @return boolean success.
59 function ProjectTaskFactory(&$ProjectGroup) {
61 if (!$ProjectGroup || !is_object($ProjectGroup)) {
62 $this->setError('ProjectTask:: No Valid ProjectGroup Object');
65 if ($ProjectGroup->isError()) {
66 $this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
69 $this->ProjectGroup =& $ProjectGroup;
70 $this->order='project_task_id';
77 * setup - sets up limits and sorts before you call getTasks().
79 * @param int $offset The offset - number of rows to skip.
80 * @param string $order The way to order - ASC or DESC.
81 * @param int $max_rows The max number of rows to return.
82 * @param string $set Whether to set these prefs into the user_prefs table - use "custom".
83 * @param int $_assigned_to Include this param if you want to limit to a certain assignee.
84 * @param int $_status Include this param if you want to limit to a certain category.
85 * @param $_category_id
86 * @param string $_view
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 ProjectTask[] The array of ProjectTask objects.
154 function &getTasks() {
155 if ($this->project_tasks) {
156 return $this->project_tasks;
158 $qpa = db_construct_qpa();
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) ;
169 $qpa = db_construct_qpa($qpa, '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 $qpa = db_construct_qpa($qpa, 'AND project_task_vw.group_project_id = $1 AND project_assigned_to.assigned_to_id = ANY ($2) ',
173 array ($this->ProjectGroup->getID(), db_int_array_to_any_clause ($tat)));
175 $qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
176 FROM project_task_vw natural left join project_task_external_order ');
177 $qpa = db_construct_qpa($qpa, 'WHERE project_task_vw.group_project_id = $1 ',
178 array ($this->ProjectGroup->getID()));
181 if ($this->status == 1 || $this->status == 2 || $this->status == 3) {
182 $qpa = db_construct_qpa($qpa, ' AND project_task_vw.status_id = $1 ', array($this->status));
185 $qpa = db_construct_qpa($qpa, $order);
186 $result = db_query_qpa($qpa, $this->max_rows, $this->offset);
189 $this->setError('Database Error: '.db_error());
193 $rows = db_numrows($result);
194 $this->fetched_rows = $rows;
195 $this->project_tasks = array();
196 while ($arr = db_fetch_array($result)) {
197 if ($this->category) {
198 if ($arr['category_id'] != $this->category)
201 $this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
203 return $this->project_tasks;
210 // c-file-style: "bsd"