websiteWebsite
codingteam CodingTeam
A free forge, lightweight and extensible.

 

Browse the code

Revision log Information on the revision
Revision: 233 (differences)
Author: xbright
Log message: * Updated project.news
* Updated MUCkl configuration files (it's recommend to use binding)
Change revision:
<?php
#    This file is a part of CodingTeam. See <http://www.codingteam.net>.
#    Copyright (C) 2007-2009 CodingTeam (See AUTHORS and THANKS for details)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, version 3 only.
#
#    This program 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
class Timeline {
    private $ct_db;
 
    function __construct($db)
    {
        $this->ct_db = $db;
    }
 
    function getTimeline($projectid)
    {
        $project = getClass('projects.projects', $this->ct_db);
        $projects = $project->load($projectid);
 
        if ($projects)
            $dbname = htmlspecialchars($project->getDbname());
        else
            exit('Error.');
 
        $timeline = array();
 
        $feeds = array('atom/project/'.$dbname.'/download' => 'download',
                       'atom/project/'.$dbname.'/bugs'     => 'bugs',
                       'atom/project/'.$dbname.'/news'     => 'news',
                       'atom/project/'.$dbname.'/doc'      => 'doc'
                      );
 
        if (is_dir(CT_BASEDIR.'/public/svn/'.$dbname))
            $feeds['atom/project/'.$dbname.'/browse'] = 'browse';
 
        // Fetch all feeds
        foreach ($feeds as $feed => $type)
        {
            if ($file = simplexml_load_file(CT_BASEURL.$feed))
            {
                foreach ($file->entry as $item)
                {
                    $title = (string)$item->title;
                    $date = date('Y-m-d H:i:s', strtotime($item->published));
                    $link = (string)$item->link['href'];
                    $author = (string)$item->author->name;
                    $text = (string)$item->content;
 
                    $global_date = explode(' ', $date);
                    // Array for date
                    if (!isset($timeline[$global_date[0]]))
                        $timeline[$global_date[0]] = array($global_date[0]);
                    // Array for datas
                    if (!isset($timeline[$global_date[0]][1]))
                         $timeline[$global_date[0]][1] = array();
 
                    if ($type == 'doc')
                    {
                        $title_ = explode(' - ', $title);
                        $title = $title_[0];
                    }
 
                    $timestamp = convertDate($date, 'datetime', 'timestamp');
 
                    if (!isset($timeline[$global_date[0]][1][$timestamp]))
                        $timeline[$global_date[0]][1][$timestamp] = array();
 
                    array_push($timeline[$global_date[0]][1][$timestamp], array('title'  => $title,
                                                                                'time'   => $global_date[1],
                                                                                'link'   => $link,
                                                                                'author' => $author,
                                                                                'text'   => map_str($text, 50),
                                                                                'type'   => $type
                                                                               ));
                }
            }
        }
 
        // Add bugs log to the timeline
        $bugs = getClass('project.bugs', $this->ct_db);
        $bugs_log = $bugs->timelineGetLog($projectid);
 
        // Arrays
        $type = array('bugreport' => i18n('Bug report'),
                      'featurerequest' => i18n('Feature request')
                     );
        $status = array('unconfirmed' => i18n('Unconfirmed'),
                        'confirmed' => i18n('Confirmed'),
                        'working' => i18n('Working'),
                        'needinformations' => i18n('Need informations'),
                        'needcontributors' => i18n('Need contributors'),
                        'needtests' => i18n('Need tests'),
                        'resolved' => i18n('Resolved'),
                        'rejected' => i18n('Rejected')
                       );
        $priority = array('blocker' => i18n('Blocker'),
                          'critical' => i18n('Critical'),
                          'major' => i18n('Major'),
                          'normal' => i18n('Normal'),
                          'minor' => i18n('Minor'),
                          'trivial' => i18n('Trivial')
                         );
 
        foreach ($bugs_log as $bug)
        {
            $global_date = explode(' ', $bug['datetime']);
            // Array for date
            if (!isset($timeline[$global_date[0]]))
                $timeline[$global_date[0]] = array($global_date[0]);
            // Array for datas
            if (!isset($timeline[$global_date[0]][1]))
                $timeline[$global_date[0]][1] = array();
 
            $user = getUser($bug['authorid'], $this->ct_db);
            $author = htmlspecialchars($user->getNickname());
 
            $editlist = '';
            if ($bug['type'] != '!nochange!')
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('type changed to %(type)s',
                                                                    array('type' => $type[$bug['type']]));
 
            if ($bug['priority'] != '!nochange!')
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('priority changed to %(priority)s',
                                                                    array('priority' => $priority[$bug['priority']]));
 
            if ($bug['status'] != '!nochange!')
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('status changed to %(status)s',
                                                                    array('status' => $status[$bug['status']]));
 
            if ($bug['version'] != '!nochange!')
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('version changed to %(version)s',
                                                                    array('version' => $bug['version']));
 
            if ($bug['assignedid'] != 0)
            {
                $user = getUser($bug['assignedid'], $this->ct_db);
                $nick = htmlspecialchars($user->getNickname());
 
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('assign to %(nick)s', array('nick' => $nick));
            }
 
            if ($bug['attachement'] != 0)
            {
                $attach = $bugs->getAttachementById($bug['attachement']);
 
                if (!empty($attach[0]['file']))
                    $type = i18n('file');
                else
                    $type = i18n('paste');
 
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('attached a %(type)s', array('type' => $type));
            }
 
            if ($bug['answer'] != 0)
                $editlist .= ((!empty($editlist)) ? ', ' : '').i18n('added an answer');
 
            $timestamp = convertDate($bug['datetime'], 'datetime', 'timestamp');
 
            if (!isset($timeline[$global_date[0]][1][$timestamp]))
                $timeline[$global_date[0]][1][$timestamp] = array();
 
            array_push($timeline[$global_date[0]][1][$timestamp], array('title'  => i18n('Changes on #%(bugid)d', array('bugid' => $bug['bugid'])),
                                                                        'time'   => $global_date[1],
                                                                        'link'   => CT_BASEURL.'project/'.$dbname.'/bugs/show/'.$bug['bugid'],
                                                                        'author' => $author,
                                                                        'text'   => map_str($editlist, 50),
                                                                        'type'   => 'bugs'
                                                                       ));
        }
 
        return $timeline;
    }
}
?>