1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
7 require_once 'MTrack/Attachment.php';
8 require_once 'MTrackWeb.php';
10 class MTrackWeb_Timeline extends MTrackWeb
13 var $template = 'wiki.html';
14 var $title = 'Timeline';
16 var $start_time = '-2 weeks';
18 // fixme = this should be alot more efficient...
20 $events = mtrack_get_timeline('-2 weeks', $user, $limit);
25 MTrackACL::requireAllRights('Timeline', 'read');
29 function get($only_users)
32 if (is_string($this->start_time)) {
33 $date_limit = strtotime($this->start_time);
35 $date_limit = $this->start_time; // assume that it's a timestamp
37 /* round back to earlier minute (aids caching) */
38 $date_limit -= $date_limit % 60;
39 $db_date_limit = MTrackDB::unixtime($date_limit);
43 /*if (is_string($only_users)) { FIXME
44 $filter_users = array(mtrack_canon_username($only_users));
45 } else if (is_array($only_users)) { // will not happen....
46 $filter_users = array();
47 foreach ($only_users as $user) {
48 $filter_users[] = mtrack_canon_username($user);
52 $proj_by_id = array();
53 foreach (MTrackDB::q('select projid from projects')->fetchAll() as $r) {
54 $proj_by_id[$r[0]] = MTrackProject::loadById($r[0]);
59 foreach (MTrackDB::q('select repoid from repos')->fetchAll() as $row) {
61 $repo = MTrackRepo::loadById($repoid);
62 $reponame = $repo->getBrowseRootName();
63 if ($reponame == 'default/wiki') continue;
64 $checker = new MTrackCommitChecker($repo);
66 $hist = $repo->history(null, $db_date_limit);
67 if (is_array($hist)) foreach ($hist as $e) {
68 if (is_array($filter_users)) {
70 foreach ($filter_users as $fuser) {
71 if (mtrack_canon_username($e->changeby) === $fuser) {
80 /* we want to include changesets that do not reference tickets */
81 $pid = $repo->projectFromPath($e->files);
83 $proj = $proj_by_id[$pid];
84 $e->changelog = $proj->adjust_links($e->changelog, true);
86 $actions = $checker->parseCommitMessage($e->changelog);
88 foreach ($actions as $act) {
90 $tickets[$tkt] = $tkt;
91 $repo_changes_by_ticket[$tkt][$reponame][$e->rev] = $e->rev;
93 if (count($tickets) == 0) {
95 'changedate' => $e->ctime,
96 'who' => $e->changeby,
97 'object' => "changeset:$reponame:$e->rev",
98 'reason' => $e->changelog,
104 foreach (MTrackDB::q("select
105 changedate, who, object, reason from changes
107 order by changedate desc
108 ", $db_date_limit)->fetchAll(PDO::FETCH_ASSOC) as $row) {
109 if (is_array($filter_users)) {
110 $wanted_user = false;
111 foreach ($filter_users as $fuser) {
112 if (mtrack_canon_username($row['who']) === $fuser) {
124 usort($events, function ($a, $b) {
125 return strcmp($b['changedate'], $a['changedate']);
129 foreach($events as $e) {
130 $d = date_create($e['changedate'], new DateTimeZone('UTC'));
131 date_timezone_set($d, new DateTimeZone(date_default_timezone_get()));
132 $e['time'] = $d->format('H:i');
133 $day = $d->format('D, M d Y');
134 if ($last_date != $day) {
135 $this->events[] = (object) array(
143 $this->events[] = (object)$e;
151 function is_repo_visible($reponame)
153 static $cache = array();
154 $me = MTrackAuth::whoami();
155 if (isset($cache[$me][$reponame])) {
156 return $cache[$me][$reponame];
159 if (ctype_digit($reponame)) {
160 $oid = "repo:$reponame";
162 $repo = MTrackRepo::loadByName($reponame);
164 $oid = "repo:$repo->repoid";
170 $ok = MTrackACL::hasAnyRights($oid, array(
171 'read', 'checkout'));
175 $cache[$me][$reponame] = $ok;