PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/applications/conpherence/view/ConpherenceThreadListView.php

https://github.com/navyuginfo/phabricator
PHP | 168 lines | 137 code | 31 blank | 0 comment | 8 complexity | ee97bd868124f6b4435d5db215965e0c MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, LGPL-3.0, MIT, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. final class ConpherenceThreadListView extends AphrontView {
  3. private $baseURI;
  4. private $threads;
  5. private $scrollUpParticipant;
  6. private $scrollDownParticipant;
  7. public function setThreads(array $threads) {
  8. assert_instances_of($threads, 'ConpherenceThread');
  9. $this->threads = $threads;
  10. return $this;
  11. }
  12. public function setScrollUpParticipant(
  13. ConpherenceParticipant $participant) {
  14. $this->scrollUpParticipant = $participant;
  15. return $this;
  16. }
  17. public function setScrollDownParticipant(
  18. ConpherenceParticipant $participant) {
  19. $this->scrollDownParticipant = $participant;
  20. return $this;
  21. }
  22. public function setBaseURI($base_uri) {
  23. $this->baseURI = $base_uri;
  24. return $this;
  25. }
  26. public function render() {
  27. require_celerity_resource('conpherence-menu-css');
  28. $menu = id(new PHUIListView())
  29. ->addClass('conpherence-menu')
  30. ->setID('conpherence-menu');
  31. $this->addThreadsToMenu($menu, $this->threads);
  32. return $menu;
  33. }
  34. public function renderSingleThread(ConpherenceThread $thread) {
  35. return $this->renderThread($thread);
  36. }
  37. public function renderThreadsHTML() {
  38. $thread_html = array();
  39. if ($this->scrollUpParticipant->getID()) {
  40. $thread_html[] = $this->getScrollMenuItem(
  41. $this->scrollUpParticipant,
  42. 'up');
  43. }
  44. foreach ($this->threads as $thread) {
  45. $thread_html[] = $this->renderSingleThread($thread);
  46. }
  47. if ($this->scrollDownParticipant->getID()) {
  48. $thread_html[] = $this->getScrollMenuItem(
  49. $this->scrollDownParticipant,
  50. 'down');
  51. }
  52. return phutil_implode_html('', $thread_html);
  53. }
  54. private function renderThreadItem(ConpherenceThread $thread) {
  55. return id(new PHUIListItemView())
  56. ->setType(PHUIListItemView::TYPE_CUSTOM)
  57. ->setName($this->renderThread($thread));
  58. }
  59. private function renderThread(ConpherenceThread $thread) {
  60. $user = $this->getUser();
  61. $uri = $this->baseURI.$thread->getID().'/';
  62. $data = $thread->getDisplayData($user);
  63. $title = $data['title'];
  64. $subtitle = $data['subtitle'];
  65. $unread_count = $data['unread_count'];
  66. $epoch = $data['epoch'];
  67. $image = $data['image'];
  68. $dom_id = $thread->getPHID().'-nav-item';
  69. return id(new ConpherenceMenuItemView())
  70. ->setUser($user)
  71. ->setTitle($title)
  72. ->setSubtitle($subtitle)
  73. ->setHref($uri)
  74. ->setEpoch($epoch)
  75. ->setImageURI($image)
  76. ->setUnreadCount($unread_count)
  77. ->setID($thread->getPHID().'-nav-item')
  78. ->addSigil('conpherence-menu-click')
  79. ->setMetadata(
  80. array(
  81. 'title' => $data['js_title'],
  82. 'id' => $dom_id,
  83. 'threadID' => $thread->getID(),
  84. ));
  85. }
  86. private function addThreadsToMenu(
  87. PHUIListView $menu,
  88. array $conpherences) {
  89. if ($this->scrollUpParticipant->getID()) {
  90. $item = $this->getScrollMenuItem($this->scrollUpParticipant, 'up');
  91. $menu->addMenuItem($item);
  92. }
  93. foreach ($conpherences as $conpherence) {
  94. $item = $this->renderThreadItem($conpherence);
  95. $menu->addMenuItem($item);
  96. }
  97. if (empty($conpherences)) {
  98. $menu->addMenuItem($this->getNoConpherencesMenuItem());
  99. }
  100. if ($this->scrollDownParticipant->getID()) {
  101. $item = $this->getScrollMenuItem($this->scrollDownParticipant, 'down');
  102. $menu->addMenuItem($item);
  103. }
  104. return $menu;
  105. }
  106. public function getScrollMenuItem(
  107. ConpherenceParticipant $participant,
  108. $direction) {
  109. if ($direction == 'up') {
  110. $name = pht('Load Newer Threads');
  111. } else {
  112. $name = pht('Load Older Threads');
  113. }
  114. $item = id(new PHUIListItemView())
  115. ->addSigil('conpherence-menu-scroller')
  116. ->setName($name)
  117. ->setHref($this->baseURI)
  118. ->setType(PHUIListItemView::TYPE_BUTTON)
  119. ->setMetadata(array(
  120. 'participant_id' => $participant->getID(),
  121. 'conpherence_phid' => $participant->getConpherencePHID(),
  122. 'date_touched' => $participant->getDateTouched(),
  123. 'direction' => $direction));
  124. return $item;
  125. }
  126. private function getNoConpherencesMenuItem() {
  127. $message = phutil_tag(
  128. 'div',
  129. array(
  130. 'class' => 'no-conpherences-menu-item'
  131. ),
  132. pht('No conpherences.'));
  133. return id(new PHUIListItemView())
  134. ->setType(PHUIListItemView::TYPE_CUSTOM)
  135. ->setName($message);
  136. }
  137. }