db/class_comment.inc.php

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 
00020     global $comment_fields;
00021     global $COMMENTTYPE_VALUES;
00022     $comment_fields= array();
00023     addProjectItemFields(&$comment_fields);
00024 
00025     foreach(array(
00026         new FieldInternal(array(    'name'=>'id',
00027             'default'=>0,
00028             'in_db_object'=>1,
00029             'in_db_item'=>1,
00030         )),
00031             new FieldString(array(      'name'=>'name',
00032                 'title'=>__('Summary'),
00033                 'log_changes'=>true,
00034             )),
00035             new FieldDatetime(array(    'name'=>'time',
00036                 'default'=>FINIT_NOW,
00037                 'view_in_forms'=>false,
00038             )),
00039             new FieldHidden(array(      'name'=>'person',
00040                 'view_in_forms'=>true
00041             )),
00042             new FieldHidden(array(      'name'=>'comment',
00043                 'view_in_forms'=>true
00044             )),
00045             new FieldHidden(array(      'name'=>'task',
00046                 'view_in_forms'=>true
00047             )),
00048             new FieldHidden(array(      'name'=>'effort'
00049             )),
00050             new FieldInternal(array(      'name'=>'view_collapsed'
00051             )),
00052 
00053             new FieldHidden(array(      'name'=>'file'
00054             )),
00055             new FieldBool(array(        'name'=>'starts_discussion',
00056                 'title'=>'Starts Project Discussion',
00057                 'view_in_forms'=>false,         # save discussions as a later feature
00058 
00059             )),
00060             new FieldText(array(        'name'=>'description',
00061                 'title'=>__('Details'),
00062                 'log_changes'=>true,
00063 
00064             )),
00065             new FieldHidden(array(         'name'=>'occasion',
00066                 'default'=>$COMMENTTYPE_VALUES['Comment'],
00067                 'view_in_forms'=>true,         # save discussions as a later feature
00068 
00069             )),
00070     ) as $f) {
00071         $comment_fields[$f->name]=$f;
00072     }
00073 
00074 
00078 class Comment extends DbProjectItem
00079 {
00080     public $level;              # level if child of parent-tasks
00081     public $type;
00082     public $path;               # used for hierarchical sorting of comments
00083     public $num_children;       # displayed when viewed collapsed (folded)
00084 
00085     //=== constructor ================================================
00086     function __construct ($id_or_array=false)
00087     {
00088         global $comment_fields;
00089         $this->fields= &$comment_fields;
00090 
00091         parent::__construct($id_or_array);
00092         if(!$this->type) {
00093             $this->type= ITEM_COMMENT;
00094         }
00095         $this->num_children=0;
00096     }
00097 
00098 
00104     static function getById($id)
00105     {
00106         $c= new Comment($id);
00107         if($c->id) {
00108             return $c;
00109         }
00110         return NULL;
00111     }
00112 
00113 
00121     static function getVisibleById($id)
00122     {
00123         if($c= Comment::getById($id)) {
00124             if($c->id) {
00125                 if($p= Project::getById($c->project)) {
00126                     if($p->validateViewItem($c)) {
00127                         return $c;
00128                     }
00129                 }
00130             }
00131         }
00132         return NULL;
00133     }
00134 
00138     static function getEditableById($id)
00139     {
00140         if($c= Comment::getById($id)) {
00141             if($p= Project::getById($c->project)) {
00142                 if($p->validateEditItem($c)) {
00143                     return $c;
00144                 }
00145             }
00146         }
00147         return NULL;
00148     }
00149 
00150 
00156     public function getSubComments()
00157     {
00158         if(!$project= Project::getById($this->project)) {
00159             return array();
00160         }
00161         
00162         $comments= Comment::getAll(array(
00163             'parent_comment'=> $this->id        
00164         ));
00165         
00166         return $comments;
00167     }
00168 
00169 
00173     static function &getAll($args=Array())
00174     {
00175         global $auth;
00176         $prefix = confGet('DB_TABLE_PREFIX');
00177         require_once(confGet('DIR_STREBER') . 'db/class_comment.inc.php');
00178 
00179         ### default params ###
00180         $order_by=      'c.name';
00181         $visible_only=  true;   # use project rights settings
00182         $alive_only=    true;   # ignore deleted
00183         $project=       NULL;
00184         $task=          NULL;
00185         $person=        NULL;
00186         $date_min=      NULL;
00187         $date_max=      NULL;
00188         $search=        NULL;
00189         $parent_comment= NULL;
00190 
00191         ### filter params ###
00192         if($args) {
00193             foreach($args as $key=>$value) {
00194                 if(!isset($$key) && !is_null($$key) && !$$key==="") {
00195                     trigger_error("unknown parameter",E_USER_NOTICE);
00196                 }
00197                 else {
00198                     $$key= $value;
00199                 }
00200             }
00201         }
00202 
00203         $dbh = new DB_Mysql;
00204 
00205         $str_is_alive= $alive_only
00206         ? 'AND i.state=1'
00207         : '';
00208 
00209         $AND_person= $person
00210         ? 'AND i.created_by='. intval($person)
00211         : '';
00212 
00213         $AND_task= $task
00214         ? 'AND c.task='. intval($task)
00215         : '';
00216 
00217         $AND_match= $search
00218         ? "AND (MATCH (c.name,c.description) AGAINST ('". asCleanString($search)."*'  IN BOOLEAN MODE))"
00219         : '';
00220 
00221         $AND_project1= $project
00222         ? "AND upp.project= $project"
00223         : "";
00224 
00225         $AND_project2= $project
00226         ? "AND i.project= $project"
00227         : "";
00228 
00229         $AND_date_min= $date_min
00230             ? "AND i.modified >= '". asCleanString($date_min)."'"
00231             : '';
00232 
00233         $AND_date_max= $date_max
00234             ? "AND i.modified <= '". asCleanString($date_max)."'"
00235             : '';
00236 
00237         if(!is_null($parent_comment)) {
00238             $AND_comment= 'AND c.comment = ' . intval($parent_comment);
00239         }
00240         else {
00241             $AND_comment= '';
00242         }
00243 
00244         if($visible_only) {
00245             $str_query=
00246             "SELECT i.*, c.* from {$prefix}item i, {$prefix}comment c, {$prefix}projectperson upp
00247             WHERE
00248                     upp.person = {$auth->cur_user->id}
00249                 $AND_project1
00250                 AND upp.state = 1
00251 
00252                 AND i.type = '".ITEM_COMMENT."'
00253                 AND i.project = upp.project
00254                 $AND_project2
00255                 $str_is_alive
00256                 $AND_person
00257                 $AND_date_min
00258                 $AND_date_max
00259                 AND ( i.pub_level >= upp.level_view
00260                       OR
00261                       i.created_by = {$auth->cur_user->id}
00262                 )
00263 
00264                 AND c.id = i.id
00265                 $AND_task
00266                 $AND_match
00267                 $AND_comment
00268 
00269             ". getOrderByString($order_by);
00270         }
00271         else {
00272             $str_query=
00273             "SELECT i.*, c.* from {$prefix}item i, {$prefix}comment c
00274             WHERE
00275                     i.type = '".ITEM_COMMENT."'
00276                 $AND_project2
00277                 $str_is_alive
00278                 $AND_person
00279                 $AND_date_min
00280                 $AND_date_max
00281 
00282                 AND c.id = i.id
00283                 $AND_task
00284                 $AND_comment
00285                 $AND_match
00286 
00287             ". getOrderByString($order_by);
00288 
00289         }
00290 
00291         $sth= $dbh->prepare($str_query);
00292         $sth->execute("",1);
00293         $tmp=$sth->fetchall_assoc();
00294         $comments=array();
00295         foreach($tmp as $n) {
00296             $comment=new Comment($n);
00297             $comments[]= $comment;
00298         }
00299         return $comments;
00300 
00301     }
00302 }
00303 
00304 
00305 ?>

Generated on Sun Mar 4 17:19:27 2007 for streber by  doxygen 1.5.1-p1