1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00
phorge-phorge/src/applications/conpherence/ConpherenceTransactionRenderer.php
Bob Trahan 87d360bb1b Conpherence - refactor display classes a bit
Summary:
D12409 made me realize this was a bit janky. `PhabricatorTransactionView` was only being used by Conpherence, so move and rename that class to `ConpherenceTransactionView`. Also, rename the existing `ConpherenceTransactionView` to `ConpherenceTransactionRenderer`, moving the actual view bits into the new `ConpherenceTransactionView`. Resulting code is a bit cleaner IMO.

Diff 1 of 2 (second diff has to be written. =D). Diff 2 will take care of the CSS and possibly clean things up further.

Test Plan: played around in conpherence full and conpherence column and things looked nice

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D12410
2015-04-14 12:25:35 -07:00

127 lines
4.2 KiB
PHP

<?php
final class ConpherenceTransactionRenderer {
public static function renderTransactions(
PhabricatorUser $user,
ConpherenceThread $conpherence,
$full_display = true) {
$transactions = $conpherence->getTransactions();
$oldest_transaction_id = 0;
$too_many = ConpherenceThreadQuery::TRANSACTION_LIMIT + 1;
if (count($transactions) == $too_many) {
$last_transaction = end($transactions);
unset($transactions[$last_transaction->getID()]);
$oldest_transaction = end($transactions);
$oldest_transaction_id = $oldest_transaction->getID();
}
$transactions = array_reverse($transactions);
$handles = $conpherence->getHandles();
$rendered_transactions = array();
$engine = id(new PhabricatorMarkupEngine())
->setViewer($user)
->setContextObject($conpherence);
foreach ($transactions as $key => $transaction) {
if ($transaction->shouldHide()) {
unset($transactions[$key]);
continue;
}
if ($transaction->getComment()) {
$engine->addObject(
$transaction->getComment(),
PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
}
}
$engine->process();
// we're going to insert a dummy date marker transaction for breaks
// between days. some setup required!
$previous_transaction = null;
$date_marker_transaction = id(new ConpherenceTransaction())
->setTransactionType(ConpherenceTransactionType::TYPE_DATE_MARKER)
->makeEphemeral();
$date_marker_transaction_view = id(new ConpherenceTransactionView())
->setUser($user)
->setConpherenceTransaction($date_marker_transaction)
->setConpherenceThread($conpherence)
->setHandles($handles)
->setMarkupEngine($engine);
$transaction_view_template = id(new ConpherenceTransactionView())
->setUser($user)
->setConpherenceThread($conpherence)
->setHandles($handles)
->setMarkupEngine($engine);
foreach ($transactions as $transaction) {
if ($previous_transaction) {
$previous_day = phabricator_format_local_time(
$previous_transaction->getDateCreated(),
$user,
'Ymd');
$current_day = phabricator_format_local_time(
$transaction->getDateCreated(),
$user,
'Ymd');
// date marker transaction time!
if ($previous_day != $current_day) {
$date_marker_transaction->setDateCreated(
$transaction->getDateCreated());
$rendered_transactions[] = $date_marker_transaction_view->render();
}
}
$transaction_view = id(clone $transaction_view_template)
->setConpherenceTransaction($transaction);
if ($full_display) {
$transaction_view
->setAnchor(
$transaction->getID(),
phabricator_time($transaction->getDateCreated(), $user));
$transaction_view->setContentSource($transaction->getContentSource());
$transaction_view->setShowImages(true);
} else {
$transaction_view
->setEpoch(
$transaction->getDateCreated(),
'/'.$conpherence->getMonogram().'#'.$transaction->getID())
->setTimeOnly(true);
$transaction_view->setShowImages(false);
}
$rendered_transactions[] = $transaction_view->render();
$previous_transaction = $transaction;
}
$latest_transaction_id = $transaction->getID();
return array(
'transactions' => $rendered_transactions,
'latest_transaction' => $transaction,
'latest_transaction_id' => $latest_transaction_id,
'oldest_transaction_id' => $oldest_transaction_id,
);
}
public static function renderMessagePaneContent(
array $transactions,
$oldest_transaction_id) {
$scrollbutton = '';
if ($oldest_transaction_id) {
$scrollbutton = javelin_tag(
'a',
array(
'href' => '#',
'mustcapture' => true,
'sigil' => 'show-older-messages',
'class' => 'conpherence-show-older-messages',
'meta' => array(
'oldest_transaction_id' => $oldest_transaction_id,
),
),
pht('Show Older Messages'));
}
return hsprintf('%s%s', $scrollbutton, $transactions);
}
}