00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php5 based project management system (c) 2005-2007 / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004
00014 define('ASSIGNTYPE_UNDEFINED', 0);
00015 define('ASSIGNTYPE_INITIAL', 1);
00016 define('ASSIGNTYPE_CHANGED', 2);
00017 define('ASSIGNTYPE_ADDED', 3);
00018
00019
00020
00021 class TaskPerson extends DbProjectItem {
00022 public $name;
00023 public $project;
00024
00028 function __construct ($id_or_array=NULL)
00029 {
00030 global $g_task_person_fields;
00031 $this->fields= &$g_task_person_fields;
00032
00033 parent::__construct($id_or_array);
00034 if(!$this->type) {
00035 $this->type= ITEM_TASKPERSON;
00036 }
00037 }
00038
00039 static function initFields()
00040 {
00041 global $g_task_person_fields;
00042 $g_task_person_fields=array();
00043 addProjectItemFields(&$g_task_person_fields);
00044
00045 foreach(array(
00046 new FieldInternal(array( 'name'=>'id', # add id to both tables for caching
00047 'default'=>0,
00048 'in_db_object'=>1,
00049 'in_db_item'=>1,
00050 )),
00051 new FieldInternal(array( 'name'=>'task', # id task
00052 )),
00053 new FieldInternal(array( 'name'=>'person', # id of assigned person
00054 )),
00055 new FieldString(array( 'name'=>'comment',
00056 )),
00057 new FieldInternal(array( 'name'=>'assigntype',
00058 'default'=>ASSIGNTYPE_INITIAL,
00059 )),
00060
00061 ) as $f) {
00062 $g_task_person_fields[$f->name]=$f;
00063 }
00064 }
00065
00071 static function getById($id)
00072 {
00073 $tp= new TaskPerson($id);
00074 if($tp->id) {
00075 return $tp;
00076 }
00077 return NULL;
00078 }
00079
00080
00088 static function getVisibleById($id)
00089 {
00090 if($tp= TaskPerson::getById($id)) {
00091 if($p= Project::getById($tp->project)) {
00092 if($p->validateViewItem($tp)) {
00093 return $tp;
00094 }
00095 }
00096 }
00097 return NULL;
00098 }
00099
00103 static function getEditableById($id)
00104 {
00105 if($tp= TaskPerson::getById($id)) {
00106 if($p= Project::getById($tp->project)) {
00107 if($p->validateEditItem($tp)) {
00108 return $tp;
00109 }
00110 }
00111 }
00112 return NULL;
00113 }
00114
00115
00116
00117 static function &getTaskPersons( $args=NULL)
00118 {
00119 global $auth;
00120 $prefix = confGet('DB_TABLE_PREFIX');
00121
00122 ### default params ###
00123 $date_min = NULL;
00124 $date_max = NULL;
00125 $created_by = NULL; # who created assigment...
00126 $person = NULL; # who has was assigned...
00127 $task = NULL;
00128 $project = NULL;
00129
00130 ### filter params ###
00131 if($args) {
00132 foreach($args as $key=>$value) {
00133 if(!isset($$key) && !is_null($$key) && !$$key==="") {
00134 trigger_error("unknown parameter",E_USER_NOTICE);
00135 }
00136 else {
00137 $$key= $value;
00138 }
00139 }
00140 }
00141
00142
00143 $str_project= $project
00144 ? 'AND i.project='.intval($project)
00145 : '';
00146
00147 $str_created_by= $created_by
00148 ? 'AND i.created_by='.intval($created_by)
00149 : '';
00150
00151 $str_date_min= $date_min
00152 ? "AND i.modified >= '".asCleanString($date_min)."'"
00153 : '';
00154
00155 $str_date_max= $date_max
00156 ? "AND i.modified <= '" . asCleanString($date_max) ."'"
00157 : '';
00158
00159 $str_task= $task
00160 ? 'AND tp.task ='.intval($task)
00161 : '';
00162
00163 $str_person= $person
00164 ? 'AND tp.person ='.intval($person)
00165 : '';
00166
00167
00168 ### show all ###
00169 $str_query=
00170 "SELECT tp.*, i.* from {$prefix}taskperson tp, {$prefix}item i
00171 WHERE
00172 i.type = '".ITEM_TASKPERSON."'
00173 $str_project
00174 $str_created_by
00175 AND tp.id = i.id
00176 $str_person
00177 $str_task
00178 $str_date_max
00179 $str_date_min
00180 ";
00181
00182 $dbh = new DB_Mysql;
00183 $sth= $dbh->prepare($str_query);
00184
00185 $sth->execute("",1);
00186 $tmp=$sth->fetchall_assoc();
00187 $tps=array();
00188 foreach($tmp as $t) {
00189 $c=new TaskPerson($t);
00190 $tps[]=$c;
00191 }
00192 return $tps;
00193 }
00194 }
00195
00196 TaskPerson::initFields();
00197
00198
00199
00200 ?>