1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<?php
/**
* FusionForge project manager
*
* Copyright 1999-2000, Tim Perdue/Sourceforge
* Copyright 2002, Tim Perdue/GForge, LLC
* Copyright 2009, Roland Mas
* Copyright 2014, Franck Villaume - TrivialDev
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or (at your option)
* any later version.
*
* FusionForge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with FusionForge; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once $gfcommon.'include/Error.class.php';
require_once $gfcommon.'pm/ProjectTask.class.php';
class ProjectTaskFactory extends Error {
/**
* The ProjectGroup object.
*
* @var object $ProjectGroup.
*/
var $ProjectGroup;
/**
* The project_tasks array.
*
* @var array project_tasks.
*/
var $project_tasks;
var $order;
var $status;
var $category;
var $assigned_to;
var $offset;
var $max_rows;
var $fetched_rows;
var $view_type;
/**
* Constructor.
*
* @param ProjectGroup $ProjectGroup The ProjectGroup object to which this ProjectTask is associated.
* @return boolean success.
*/
function ProjectTaskFactory(&$ProjectGroup) {
$this->Error();
if (!$ProjectGroup || !is_object($ProjectGroup)) {
$this->setError('ProjectTask:: No Valid ProjectGroup Object');
return false;
}
if ($ProjectGroup->isError()) {
$this->setError('ProjectTask:: '.$ProjectGroup->getErrorMessage());
return false;
}
$this->ProjectGroup =& $ProjectGroup;
$this->order='project_task_id';
$this->offset=0;
return true;
}
/**
* setup - sets up limits and sorts before you call getTasks().
*
* @param int $offset The offset - number of rows to skip.
* @param string $order The way to order - ASC or DESC.
* @param int $max_rows The max number of rows to return.
* @param string $set Whether to set these prefs into the user_prefs table - use "custom".
* @param int $_assigned_to Include this param if you want to limit to a certain assignee.
* @param int $_status Include this param if you want to limit to a certain category.
* @param $_category_id
* @param string $_view
*/
function setup($offset,$order,$max_rows,$set,$_assigned_to,$_status,$_category_id,$_view='') {
//echo "<br />offset: $offset| order: $order|max_rows: $max_rows|_assigned_to: $_assigned_to|_status: $_status|_category_id: $_category_id +";
if ((!$offset) || ($offset < 0)) {
$this->offset=0;
} else {
$this->offset=$offset;
}
if (session_loggedin()) {
$u =& session_get_user();
}
if ($order) {
if ($order=='project_task_id' || $order=='percent_complete'
|| $order=='summary' || $order=='start_date' || $order=='end_date' || $order=='priority') {
if (session_loggedin()) {
$u->setPreference('pm_task_order'.$this->ProjectGroup->getID(), $order);
}
} else {
$order = 'project_task_id';
}
} else {
if (session_loggedin()) {
$order = $u->getPreference('pm_task_order'.$this->ProjectGroup->getID());
}
}
if (!$order) {
$order = 'project_task_id';
}
$this->order=$order;
if ($set=='custom') {
/*
if this custom set is different than the stored one, reset preference
*/
$pref_=$_assigned_to.'|'.$_status.'|'.$_category_id.'|'.$_view;
if (session_loggedin() && ($pref_ != $u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID()))) {
$u->setPreference('pm_brow_cust'.$this->ProjectGroup->getID(),$pref_);
}
} else {
if (session_loggedin()) {
if ($pref_=$u->getPreference('pm_brow_cust'.$this->ProjectGroup->getID())) {
$prf_arr=explode('|',$pref_);
$_assigned_to=$prf_arr[0];
$_status=$prf_arr[1];
$_category_id=$prf_arr[2];
$_view=$prf_arr[3];
}
}
}
$this->status=$_status;
$this->assigned_to=$_assigned_to;
$this->category=$_category_id;
$this->view_type=$_view;
if (!$max_rows || $max_rows < 5) {
$max_rows=50;
}
$this->max_rows=$max_rows;
}
/**
* getTasks - get an array of ProjectTask objects.
*
* @return array ProjectTask[] The array of ProjectTask objects.
*/
function &getTasks() {
if ($this->project_tasks) {
return $this->project_tasks;
}
$qpa = db_construct_qpa();
if ($this->order=='priority') {
$order = 'ORDER BY priority DESC' ;
} else {
$order = "ORDER BY $this->order ASC" ;
}
if ($this->assigned_to) {
$tat = $this->assigned_to ;
if (! is_array ($tat))
$tat = array ($tat) ;
$qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
FROM project_task_vw natural left join project_task_external_order, project_assigned_to
WHERE project_task_vw.project_task_id = project_assigned_to.project_task_id ');
$qpa = db_construct_qpa($qpa, 'AND project_task_vw.group_project_id = $1 AND project_assigned_to.assigned_to_id = ANY ($2) ',
array ($this->ProjectGroup->getID(), db_int_array_to_any_clause ($tat)));
} else {
$qpa = db_construct_qpa($qpa, 'SELECT project_task_vw.*, project_task_external_order.external_id
FROM project_task_vw natural left join project_task_external_order ');
$qpa = db_construct_qpa($qpa, 'WHERE project_task_vw.group_project_id = $1 ',
array ($this->ProjectGroup->getID()));
}
if ($this->status == 1 || $this->status == 2 || $this->status == 3) {
$qpa = db_construct_qpa($qpa, ' AND project_task_vw.status_id = $1 ', array($this->status));
}
if ($this->category) {
$qpa = db_construct_qpa($qpa, ' AND project_task_vw.category_id = $1 ', array($this->category));
}
$qpa = db_construct_qpa($qpa, $order);
$result = db_query_qpa($qpa, $this->max_rows, $this->offset);
if (db_error()) {
$this->setError('Database Error: '.db_error());
return false;
}
$rows = db_numrows($result);
$this->fetched_rows = $rows;
$this->project_tasks = array();
while ($arr = db_fetch_array($result)) {
$this->project_tasks[] = new ProjectTask($this->ProjectGroup, $arr['project_task_id'], $arr);
}
return $this->project_tasks;
}
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
|