Path: blob/master/src/applications/conpherence/view/ConpherenceTransactionView.php
12256 views
<?php12final class ConpherenceTransactionView extends AphrontView {34private $conpherenceThread;5private $conpherenceTransaction;6private $handles;7private $markupEngine;8private $classes = array();9private $searchResult;10private $timeOnly;1112public function setConpherenceThread(ConpherenceThread $t) {13$this->conpherenceThread = $t;14return $this;15}1617private function getConpherenceThread() {18return $this->conpherenceThread;19}2021public function setConpherenceTransaction(ConpherenceTransaction $tx) {22$this->conpherenceTransaction = $tx;23return $this;24}2526private function getConpherenceTransaction() {27return $this->conpherenceTransaction;28}2930public function setHandles(array $handles) {31assert_instances_of($handles, 'PhabricatorObjectHandle');32$this->handles = $handles;33return $this;34}3536public function getHandles() {37return $this->handles;38}3940public function setMarkupEngine(PhabricatorMarkupEngine $markup_engine) {41$this->markupEngine = $markup_engine;42return $this;43}4445private function getMarkupEngine() {46return $this->markupEngine;47}4849public function addClass($class) {50$this->classes[] = $class;51return $this;52}5354public function setSearchResult($result) {55$this->searchResult = $result;56return $this;57}5859public function render() {60$viewer = $this->getUser();61if (!$viewer) {62throw new PhutilInvalidStateException('setUser');63}6465require_celerity_resource('conpherence-transaction-css');6667$transaction = $this->getConpherenceTransaction();68switch ($transaction->getTransactionType()) {69case ConpherenceThreadDateMarkerTransaction::TRANSACTIONTYPE:70return javelin_tag(71'div',72array(73'class' => 'conpherence-transaction-view date-marker',74'sigil' => 'conpherence-transaction-view',75'meta' => array(76'id' => $transaction->getID() + 0.5,77),78),79array(80phutil_tag(81'span',82array(83'class' => 'date',84),85phabricator_format_local_time(86$transaction->getDateCreated(),87$viewer,88'M jS, Y')),89));90break;91}9293$info = $this->renderTransactionInfo();94$actions = $this->renderTransactionActions();95$image = $this->renderTransactionImage();96$content = $this->renderTransactionContent();97$classes = implode(' ', $this->classes);98$transaction_dom_id = 'anchor-'.$transaction->getID();99100$header = phutil_tag_div(101'conpherence-transaction-header grouped',102array($actions, $info));103104return javelin_tag(105'div',106array(107'class' => 'conpherence-transaction-view '.$classes,108'id' => $transaction_dom_id,109'sigil' => 'conpherence-transaction-view',110'meta' => array(111'id' => $transaction->getID(),112),113),114array(115$image,116phutil_tag_div('conpherence-transaction-detail grouped',117array($header, $content)),118));119}120121private function renderTransactionInfo() {122$viewer = $this->getUser();123$thread = $this->getConpherenceThread();124$transaction = $this->getConpherenceTransaction();125$info = array();126127Javelin::initBehavior('phabricator-tooltips');128$tip = phabricator_datetime($transaction->getDateCreated(), $viewer);129$label = phabricator_time($transaction->getDateCreated(), $viewer);130$width = 360;131132Javelin::initBehavior('phabricator-watch-anchor');133$anchor = id(new PhabricatorAnchorView())134->setAnchorName($transaction->getID())135->render();136137if ($this->searchResult) {138$uri = $thread->getMonogram();139$info[] = hsprintf(140'%s',141javelin_tag(142'a',143array(144'href' => '/'.$uri.'#'.$transaction->getID(),145'class' => 'transaction-date',146'sigil' => 'conpherence-search-result-jump',147),148$tip));149} else {150$info[] = hsprintf(151'%s%s',152$anchor,153javelin_tag(154'a',155array(156'href' => '#'.$transaction->getID(),157'class' => 'transaction-date anchor-link',158'sigil' => 'has-tooltip',159'meta' => array(160'tip' => $tip,161'size' => $width,162),163),164$label));165}166167return phutil_tag(168'span',169array(170'class' => 'conpherence-transaction-info',171),172$info);173}174175private function renderTransactionActions() {176$transaction = $this->getConpherenceTransaction();177178switch ($transaction->getTransactionType()) {179case PhabricatorTransactions::TYPE_COMMENT:180$handles = $this->getHandles();181$author = $handles[$transaction->getAuthorPHID()];182$actions = array($author->renderLink());183break;184default:185$actions = null;186break;187}188189return $actions;190}191192private function renderTransactionImage() {193$image = null;194$transaction = $this->getConpherenceTransaction();195switch ($transaction->getTransactionType()) {196case PhabricatorTransactions::TYPE_COMMENT:197$handles = $this->getHandles();198$author = $handles[$transaction->getAuthorPHID()];199$image_uri = $author->getImageURI();200$image = phutil_tag(201'span',202array(203'class' => 'conpherence-transaction-image',204'style' => 'background-image: url('.$image_uri.');',205));206break;207}208return $image;209}210211private function renderTransactionContent() {212$transaction = $this->getConpherenceTransaction();213$content = null;214$content_class = null;215$content = null;216$handles = $this->getHandles();217switch ($transaction->getTransactionType()) {218case PhabricatorTransactions::TYPE_COMMENT:219$this->addClass('conpherence-comment');220$author = $handles[$transaction->getAuthorPHID()];221$comment = $transaction->getComment();222$content = $this->getMarkupEngine()->getOutput(223$comment,224PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);225$content_class = 'conpherence-message';226break;227default:228$content = $transaction->getTitle();229$this->addClass('conpherence-edited');230break;231}232233$view = phutil_tag(234'div',235array(236'class' => $content_class,237),238$content);239240return phutil_tag_div('conpherence-transaction-content', $view);241}242243}244245246