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
00005
00020 class Issue extends DbProjectItem {
00021
00022
00023 function __construct ($id_or_array=NULL)
00024 {
00025 global $g_issue_fields;
00026 $this->fields= &$g_issue_fields;
00027
00028 parent::__construct($id_or_array);
00029 if(!$this->type) {
00030 $this->type= ITEM_ISSUE;
00031 }
00032 }
00033
00034 static function initFields()
00035 {
00036 global $g_issue_fields;
00037 $g_issue_fields=array();
00038
00039 global $REPRODUCIBILITY_VALUES;
00040 global $SEVERITY_VALUES;
00041
00042
00043 addProjectItemFields(&$g_issue_fields);
00044
00045 foreach(array(
00046 new FieldInternal(array( 'name'=>'id',
00047 'default'=>0,
00048 'in_db_object'=>1,
00049 'in_db_item'=>1,
00050 )),
00051 new FieldInternal(array( 'name'=>'task', # backlink to task item
00052 'default'=>0,
00053 )),
00054
00055 new FieldInt(array( 'name'=>'reproducibility',
00056 'default'=> REPRODUCIBILITY_HAVE_NOT_TRIED,
00057 'view_in_forms'=>false,
00058 )),
00059 new FieldInt(array( 'name'=>'severity',
00060 'default'=> SEVERITY_MINOR,
00061 'view_in_forms'=>false,
00062 )),
00063 new FieldString(array( 'name'=>'plattform',
00064 )),
00065 new FieldString(array( 'name'=>'os',
00066 'view_in_forms'=>false,
00067 )),
00068 new FieldString(array( 'name'=>'version',
00069 )),
00070 new FieldString(array( 'name'=>'production_build',
00071 'title'=>__('Production build'),
00072 'view_in_forms'=>true,
00073 )),
00074 new FieldText(array( 'name'=>'steps_to_reproduce',
00075 'title'=>__('Steps to reproduce'),
00076 )),
00077 new FieldText(array( 'name'=>'expected_result',
00078 'title'=>__('Expected result'),
00079 )),
00080 new FieldText(array( 'name'=>'suggested_solution',
00081 'title'=>__('Suggested Solution'),
00082 )),
00083 ) as $f) {
00084 $g_issue_fields[$f->name]=$f;
00085 }
00086 }
00087
00088
00089
00090
00096 static function getById($id)
00097 {
00098 $i= new Issue($id);
00099 if($i->id) {
00100 return $i;
00101 }
00102 return NULL;
00103 }
00104
00105
00113 static function getVisibleById($id)
00114 {
00115 if($i= Issue::getById($id)) {
00116 if($p= Project::getById($i->project)) {
00117 if($p->validateViewItem($i)) {
00118 return $i;
00119 }
00120 }
00121 else {
00122 trigger_error("issue without project?",E_USER_WARNING);
00123 }
00124 }
00125 return NULL;
00126 }
00127
00131 static function getEditableById($id)
00132 {
00133 if($i= Issue::getById($id)) {
00134 if($p= Project::getById($i->project)) {
00135 if($p->validateEditItem($i)) {
00136 return $i;
00137 }
00138 }
00139 else {
00140 trigger_error("issue without project?",E_USER_WARNING);
00141 }
00142 }
00143 return NULL;
00144 }
00145
00146
00150 static function &getAll($args=Array())
00151 {
00152 global $auth;
00153 $prefix = confGet('DB_TABLE_PREFIX');
00154
00155 ### default params ###
00156 $order_by= "";
00157 $visible_only= true; # use project rights settings
00158 $alive_only= true; # ignore deleted
00159 $project= NULL;
00160 $search= NULL;
00161
00162 ### filter params ###
00163 if($args) {
00164 foreach($args as $key=>$value) {
00165 if(!isset($$key) && !is_null($$key) && !$$key==="") {
00166 trigger_error("unknown parameter",E_USER_NOTICE);
00167 }
00168 else {
00169 $$key= $value;
00170 }
00171 }
00172 }
00173
00174 $dbh = new DB_Mysql;
00175
00176 $str_is_alive= $alive_only
00177 ? 'AND i.state=' . ITEM_STATE_OK
00178 : '';
00179
00180 $AND_match= $search
00181 ? "AND (MATCH (iss.plattform,iss.os,iss.version,iss.production_build,iss.steps_to_reproduce,iss.expected_result,iss.suggested_solution) AGAINST ('". asCleanString($search). "*' IN BOOLEAN MODE))"
00182 : "";
00183
00184 $AND_project1= $project
00185 ? 'AND upp.project='. intval($project)
00186 : '';
00187
00188 $AND_project2= $project
00189 ? 'AND i.project='. intval($project)
00190 : '';
00191
00192 if($visible_only) {
00193 $str_query=
00194 "SELECT i.*, iss.* from {$prefix}item i, {$prefix}issue iss, {$prefix}projectperson upp
00195 WHERE
00196 upp.person = {$auth->cur_user->id}
00197 $AND_project1
00198 AND upp.state = 1
00199
00200 AND i.type = '".ITEM_ISSUE."'
00201 AND i.project = upp.project
00202 $AND_project2
00203 $str_is_alive
00204 AND ( i.pub_level >= upp.level_view
00205 OR
00206 i.created_by = {$auth->cur_user->id}
00207 )
00208
00209 AND iss.id = i.id
00210 $AND_match
00211 ";
00212
00213 }
00214 else {
00215 $str_query=
00216 "SELECT i.*, iss.* from {$prefix}item i, {$prefix}issue iss
00217 WHERE
00218 i.type = '".ITEM_ISSUE."'
00219 $AND_project2
00220 $str_is_alive
00221
00222 AND iss.id = i.id
00223 $AND_match
00224 ";
00225
00226
00227 }
00228
00229 $sth= $dbh->prepare($str_query);
00230 $sth->execute("",1);
00231 $tmp=$sth->fetchall_assoc();
00232 $issues=array();
00233 foreach($tmp as $n) {
00234 $issue=new Issue($n);
00235 $issues[]= $issue;
00236 }
00237 return $issues;
00238
00239 }
00240
00241 static function getCreatedRecently($person_id=NULL)
00242 {
00243 if(!$person_id) {
00244 global $auth;
00245 $person_id= $auth->cur_user->id;
00246 }
00247
00248 $prefix= confGet('DB_TABLE_PREFIX');
00249
00250 require_once(confGet('DIR_STREBER') . 'db/class_issue.inc.php');
00251 $dbh = new DB_Mysql;
00252 $sth= $dbh->prepare(
00253 "SELECT i.*, iss.*
00254 from {$prefix}item i, {$prefix}issue iss
00255 WHERE i.created_by={$person_id}
00256 AND i.type = '".ITEM_ISSUE."'
00257 AND iss.id = i.id
00258 AND i.state = 1
00259 ORDER BY i.created DESC
00260 "
00261 )->execute();
00262 $tmp=$sth->fetchall_assoc();
00263 $issues=array();
00264 foreach($tmp as $n) {
00265 $issue=new Issue($n);
00266 $issues[]= $issue;
00267 }
00268 return $issues;
00269 }
00270
00271 }
00272 Issue::initFields();
00273
00274
00275 ?>