Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / view / phui / calendar / PHUICalendarListView.php
blob9ce03bcd84eea04281919dc9ad9e121a279d8710
1 <?php
3 final class PHUICalendarListView extends AphrontTagView {
5 private $events = array();
6 private $blankState;
7 private $view;
8 private $moreLink;
10 public function setMoreLink($more_link) {
11 $this->moreLink = $more_link;
12 return $this;
15 public function getMoreLink() {
16 return $this->moreLink;
19 private function getView() {
20 return $this->view;
23 public function setView($view) {
24 $this->view = $view;
25 return $this;
28 public function addEvent(AphrontCalendarEventView $event) {
29 $this->events[] = $event;
30 return $this;
33 public function showBlankState($state) {
34 $this->blankState = $state;
35 return $this;
38 protected function getTagName() {
39 return 'div';
42 protected function getTagAttributes() {
43 require_celerity_resource('phui-calendar-css');
44 require_celerity_resource('phui-calendar-list-css');
46 return array(
47 'sigil' => 'calendar-event-list',
48 'class' => 'phui-calendar-event-list',
52 protected function getTagContent() {
53 if (!$this->blankState && empty($this->events)) {
54 return '';
57 Javelin::initBehavior('phabricator-tooltips');
59 $singletons = array();
60 foreach ($this->events as $event) {
61 $start_epoch = $event->getEpochStart();
63 if ($event->getIsAllDay()) {
64 $timelabel = pht('All Day');
65 } else {
66 $timelabel = phabricator_time(
67 $event->getEpochStart(),
68 $this->getUser());
71 $icon_icon = $event->getIcon();
72 $icon_color = $event->getIconColor();
74 $icon = id(new PHUIIconView())
75 ->setIcon($icon_icon, $icon_color)
76 ->addClass('phui-calendar-list-item-icon');
78 $title = phutil_tag(
79 'span',
80 array(
81 'class' => 'phui-calendar-list-title',
83 $this->getEventTitle($event));
84 $time = phutil_tag(
85 'span',
86 array(
87 'class' => 'phui-calendar-list-time',
89 $timelabel);
91 $event_classes = array();
92 $event_classes[] = 'phui-calendar-list-item';
93 if ($event->getIsAllDay()) {
94 $event_classes[] = 'all-day';
97 if ($event->getIsCancelled()) {
98 $event_classes[] = 'event-cancelled';
101 $tip = $event->getDateTimeSummary();
102 if ($this->getView() == 'day') {
103 $tip_align = 'E';
104 } else if ($this->getView() == 'month') {
105 $tip_align = 'N';
106 } else {
107 $tip_align = 'W';
110 $content = javelin_tag(
111 'a',
112 array(
113 'href' => $event->getURI(),
114 'sigil' => 'has-tooltip',
115 'meta' => array(
116 'tip' => $tip,
117 'size' => 200,
118 'align' => $tip_align,
121 array(
122 $icon,
123 $time,
124 $title,
127 $singletons[] = phutil_tag(
128 'li',
129 array(
130 'class' => implode(' ', $event_classes),
132 $content);
135 if ($this->moreLink) {
136 $singletons[] = phutil_tag(
137 'li',
138 array(
139 'class' => 'phui-calendar-list-item',
141 phutil_tag(
142 'a',
143 array(
144 'href' => $this->moreLink,
145 'class' => 'phui-calendar-list-more',
147 array(
148 id(new PHUIIconView())->setIcon('fa-ellipsis-h grey'),
149 phutil_tag(
150 'span',
151 array(
152 'class' => 'phui-calendar-list-title',
154 pht('View More...')),
155 )));
158 if (empty($singletons)) {
159 $singletons[] = phutil_tag(
160 'li',
161 array(
162 'class' => 'phui-calendar-list-item-empty',
164 pht('Clear sailing ahead.'));
167 $list = phutil_tag(
168 'ul',
169 array(
170 'class' => 'phui-calendar-list',
172 $singletons);
174 return $list;
177 private function getEventTitle($event) {
178 $class = 'phui-calendar-item';
179 return phutil_tag(
180 'span',
181 array(
182 'class' => $class,
184 $event->getName());
187 public function getIsViewerInvitedOnList() {
188 foreach ($this->events as $event) {
189 if ($event->getViewerIsInvited()) {
190 return true;
193 return false;