2012-11-22 02:24:56 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
final class PHUITimelineExample extends PhabricatorUIExample {
|
2012-11-22 02:24:56 +01:00
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return 'Timeline View';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
2013-02-08 21:07:44 +01:00
|
|
|
return hsprintf(
|
2014-02-12 18:02:05 +01:00
|
|
|
'Use <tt>PHUITimelineView</tt> to comments and transactions.');
|
2012-11-22 02:24:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function renderExample() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-09-11 21:27:28 +02:00
|
|
|
$handle = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($user->getPHID()))
|
|
|
|
->executeOne();
|
2012-11-22 02:24:56 +01:00
|
|
|
|
|
|
|
$events = array();
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('A major event.')
|
|
|
|
->appendChild('This is a major timeline event.');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('A minor event.');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->appendChild('A major event with no title.');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Another minor event.');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle);
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Major Red Event')
|
2012-12-11 22:59:35 +01:00
|
|
|
->setIcon('love')
|
2012-11-22 02:24:56 +01:00
|
|
|
->appendChild('This event is red!')
|
2012-12-11 22:59:35 +01:00
|
|
|
->setColor(PhabricatorTransactions::COLOR_RED);
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Minor Red Event')
|
2012-12-11 22:59:35 +01:00
|
|
|
->setColor(PhabricatorTransactions::COLOR_RED);
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Minor Not-Red Event');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Minor Red Event')
|
2012-12-11 22:59:35 +01:00
|
|
|
->setColor(PhabricatorTransactions::COLOR_RED);
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle('Minor Not-Red Event');
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
2012-12-11 22:59:35 +01:00
|
|
|
->setTitle('Major Green Event')
|
|
|
|
->appendChild('This event is green!')
|
|
|
|
->setColor(PhabricatorTransactions::COLOR_GREEN);
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-12-11 23:02:51 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(str_repeat('Long Text Title ', 64))
|
|
|
|
->appendChild(str_repeat('Long Text Body ', 64))
|
|
|
|
->setColor(PhabricatorTransactions::COLOR_ORANGE);
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-12-11 23:02:51 +01:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(str_repeat('LongTextEventNoSpaces', 1024))
|
|
|
|
->appendChild(str_repeat('LongTextNoSpaces', 1024))
|
|
|
|
->setColor(PhabricatorTransactions::COLOR_RED);
|
|
|
|
|
2012-12-11 22:59:35 +01:00
|
|
|
$colors = array(
|
|
|
|
PhabricatorTransactions::COLOR_RED,
|
|
|
|
PhabricatorTransactions::COLOR_ORANGE,
|
|
|
|
PhabricatorTransactions::COLOR_YELLOW,
|
|
|
|
PhabricatorTransactions::COLOR_GREEN,
|
|
|
|
PhabricatorTransactions::COLOR_SKY,
|
|
|
|
PhabricatorTransactions::COLOR_BLUE,
|
|
|
|
PhabricatorTransactions::COLOR_INDIGO,
|
|
|
|
PhabricatorTransactions::COLOR_VIOLET,
|
|
|
|
PhabricatorTransactions::COLOR_GREY,
|
|
|
|
PhabricatorTransactions::COLOR_BLACK,
|
|
|
|
);
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-11-22 02:24:56 +01:00
|
|
|
->setUserHandle($handle)
|
2013-01-29 03:09:33 +01:00
|
|
|
->setTitle("Colorless")
|
2012-12-11 22:59:35 +01:00
|
|
|
->setIcon('lock');
|
|
|
|
|
|
|
|
foreach ($colors as $color) {
|
2014-02-12 18:02:05 +01:00
|
|
|
$events[] = id(new PHUITimelineEventView())
|
2012-12-11 22:59:35 +01:00
|
|
|
->setUserHandle($handle)
|
2013-01-29 03:09:33 +01:00
|
|
|
->setTitle("Color '{$color}'")
|
2012-12-11 22:59:35 +01:00
|
|
|
->setIcon('lock')
|
|
|
|
->setColor($color);
|
|
|
|
}
|
2012-11-22 02:24:56 +01:00
|
|
|
|
2013-09-24 23:35:35 +02:00
|
|
|
$vhandle = $handle->renderLink();
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$group_event = id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s went to the store.', $vhandle));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s bought an apple.', $vhandle))
|
|
|
|
->setColor('green')
|
|
|
|
->setIcon('check'));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s bought a banana.', $vhandle))
|
|
|
|
->setColor('yellow')
|
|
|
|
->setIcon('check'));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s bought a cherry.', $vhandle))
|
|
|
|
->setColor('red')
|
|
|
|
->setIcon('check'));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s paid for his goods.', $vhandle)));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s returned home.', $vhandle))
|
|
|
|
->setIcon('home')
|
|
|
|
->setColor('blue'));
|
|
|
|
|
|
|
|
$group_event->addEventToGroup(
|
2014-02-12 18:02:05 +01:00
|
|
|
id(new PHUITimelineEventView())
|
2013-09-24 23:35:35 +02:00
|
|
|
->setUserHandle($handle)
|
|
|
|
->setTitle(pht('%s related on his adventures.', $vhandle))
|
|
|
|
->appendChild(
|
|
|
|
pht(
|
|
|
|
'Today, I went to the store. I bought an apple. I bought a '.
|
|
|
|
'banana. I bought a cherry. I paid for my goods, then I returned '.
|
|
|
|
'home.')));
|
|
|
|
|
|
|
|
$events[] = $group_event;
|
|
|
|
|
2012-12-11 22:59:51 +01:00
|
|
|
$anchor = 0;
|
2013-09-24 23:35:35 +02:00
|
|
|
foreach ($events as $group) {
|
|
|
|
foreach ($group->getEventGroup() as $event) {
|
|
|
|
$event->setUser($user);
|
|
|
|
$event->setDateCreated(time() + ($anchor * 60 * 8));
|
|
|
|
$event->setAnchor(++$anchor);
|
|
|
|
}
|
2012-12-11 22:59:51 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 18:02:05 +01:00
|
|
|
$timeline = id(new PHUITimelineView());
|
2012-11-22 02:24:56 +01:00
|
|
|
foreach ($events as $event) {
|
|
|
|
$timeline->addEvent($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
}
|