std/class_rss.inc.php

Go to the documentation of this file.
00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 
00003 
00009 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00010 require_once(confGet('DIR_STREBER') . 'db/class_person.inc.php');
00011 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00012 require_once(confGet('DIR_STREBER') . 'lists/list_changes.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'lib/class_feedcreator.inc.php');
00014 
00015 
00021 class RSS
00022 {
00023 
00032     static function updateRSS(&$project)
00033     {
00034         if(!$project) {
00035             return NULL;
00036         }
00037 
00038         ### get all the changes (array of history items) ##
00039         $changes= DbProjectItem::getAll(array(
00040             'project'           => $project->id,        # query only this project history
00041             'alive_only'        => false,               # get deleted entries
00042             'visible_only'      => false,               # ignore user viewing rights
00043             'limit'             => 20,                  # show only last 20 entries in rss feed
00044             #'show_assignments'  => false,              # ignore simple assignment events
00045         ));
00046 
00047         $url= confGet('SELF_PROTOCOL').'://'.confGet('SELF_URL');   # url part of the link to the task
00048         $from_domain = confGet('SELF_DOMAIN');                      # domain url
00049 
00050 
00051         ### define general rss file settings ###
00052         $rss = new UniversalFeedCreator();
00053         $rss->title = "StreberPM: ".$project->name;
00054         $rss->description = "Latest Project News";
00055         $rss->link = "$url?go=projView&prj={$project->id}";
00056         $rss->syndicationURL = $url;
00057 
00058 
00059         # go through all retrieved changes and create rss feed
00060 
00061         foreach($changes as $ch) {
00062 
00063             ### analyze history entries:
00064             {
00065 
00066                 ### person name
00067                 $date_created=$ch->created;
00068                 $date_modified=$ch->modified;
00069                 $date_deleted=$ch->deleted;
00070 
00071                 $prs=NULL;
00072                 $person=NULL;
00073                 $str="";
00074                 if($date_deleted >= $date_modified) {
00075                     $prs= Person::getById($ch->deleted_by);
00076                 }
00077                 else if($date_modified > $date_created) {
00078                     $prs= Person::getById($ch->modified_by);
00079                 }
00080                 else {
00081                     $prs= Person::getById($ch->created_by);
00082                 }
00083                 $person_name = $prs->name;
00084 
00085 
00086                 ### action
00087                 $date_created=$ch->created;
00088                 $date_modified=$ch->modified;
00089                 $date_deleted=$ch->deleted;
00090                 $action="";
00091                 if($date_deleted >= $date_modified) {
00092                     $action= "Deleted";
00093                 }
00094                 else if($date_modified > $date_created) {
00095                     $action= "Modified";
00096                 }
00097                 else {
00098                     $action= "New";
00099                 }
00100 
00101 
00102                 ### type of item
00103                 $item_names =array(
00104                     ITEM_PROJECT        => 'Project',
00105                     ITEM_TASK           =>'Task',
00106                     ITEM_PERSON         =>'Person',
00107                     ITEM_PROJECTPERSON  =>'Team Member',
00108                     ITEM_COMPANY        =>'Company',
00109                     ITEM_EMPLOYMENT     =>'Employment',
00110                     ITEM_ISSUE          =>'Issue',
00111                     ITEM_EFFORT         =>'Effort',
00112                     ITEM_TASK_EFFORT    =>'Effort',
00113                     ITEM_COMMENT        =>'Comment',
00114                     ITEM_FILE           =>'File',
00115                     ITEM_TASKPERSON     =>'Task assignment'
00116                 );
00117                 if(!$typename= $item_names[$ch->type]) {
00118                     $typename="?";
00119                 }
00120 
00121 
00122                 ### item name - consists of
00123                 #       str_url (direct link),
00124                 #       str_name (name as string)
00125                 #       str_addon (extra link description)
00126                 global $PH;
00127                 $str_url="";
00128                 $str_name="";
00129                 $str_addon="";
00130                 switch($ch->type) {
00131                     case ITEM_TASK:
00132                         if($task= Task::getById($ch->id)) {
00133                             $str_name= $task->name;
00134                             $str_url= "$url?go=taskView&tsk={$task->id}";
00135                         }
00136                         break;
00137 
00138                     case ITEM_COMMENT:
00139                         require_once("db/class_comment.inc.php");
00140                         if($comment= Comment::getById($ch->id)) {
00141                             $str_name= $comment->name;
00142                             if($comment->comment) {
00143                                 $str_url= "$url?go=taskView&tsk={$comment->task}";
00144                                 $str_addon="(on comment)";
00145                             }
00146 
00147                             else if($comment->task) {
00148                                 $str_url= "$url?go=taskView&tsk={$comment->task}";
00149                                 $str_addon="(on task)";
00150 
00151                             }
00152 
00153                             else {
00154                                 $str_url= "$url?go=projView&prj={$comment->project}";
00155                                 $str_addon="(on project)";
00156                             }
00157                         }
00158                         break;
00159 
00160                     case ITEM_PROJECTPERSON:
00161                         if($pp= Person::getById(ProjectPerson::getById($ch->id)->person)) {
00162                             $str_name= $pp->name;
00163                             $str_url= "$url?go=personView&person={$pp->id}";
00164                         }
00165                         break;
00166 
00167                     case ITEM_EFFORT:
00168                         require_once("db/class_effort.inc.php");
00169                         if($e= Effort::getById($ch->id)) {
00170                             $str_name= $e->name;
00171                             $str_url= "$url?go=effortEdit&effort={$e->id}";
00172                         }
00173                         break;
00174                     case ITEM_FILE:
00175                         require_once("db/class_file.inc.php");
00176                         if($f= File::getById($ch->id)) {
00177                             $str_name= $f->org_filename;
00178                             $str_url= "$url?go=fileView&file={$f->id}";
00179                         }
00180                     default:
00181                         break;
00182                 }
00183 
00184 
00185                 ### modified at which time
00186                 $modified = strtotime($ch->modified);
00187             }
00188 
00189 
00190             ### adding rss item
00191             {
00192 
00193                 $item = new FeedItem();
00194                 $item->title = $str_name;
00195                 $item->link = $str_url;
00196                 $item->description = $person_name." - ".$action." ".$typename.": ".$str_name;
00197                 $item->date = $modified;
00198                 $item->source = $url;
00199                 $item->author = "StreberPM";
00200 
00201                 $rss->addItem($item);
00202             }
00203         }
00204 
00210         $rss->saveFeed("RSS2.0", "_rss/proj_$project->id.xml", false);
00211     }
00212 }
00213 
00214 ?>

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