[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/conpherence/view/ -> ConpherenceThreadListView.php (source)

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


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1