[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ConpherenceWidgetController extends ConpherenceController { 4 5 private $conpherenceID; 6 private $conpherence; 7 private $userPreferences; 8 9 public function setUserPreferences(PhabricatorUserPreferences $pref) { 10 $this->userPreferences = $pref; 11 return $this; 12 } 13 14 public function getUserPreferences() { 15 return $this->userPreferences; 16 } 17 18 public function setConpherence(ConpherenceThread $conpherence) { 19 $this->conpherence = $conpherence; 20 return $this; 21 } 22 23 public function getConpherence() { 24 return $this->conpherence; 25 } 26 27 public function setConpherenceID($conpherence_id) { 28 $this->conpherenceID = $conpherence_id; 29 return $this; 30 } 31 32 public function getConpherenceID() { 33 return $this->conpherenceID; 34 } 35 36 public function willProcessRequest(array $data) { 37 $this->setConpherenceID(idx($data, 'id')); 38 } 39 40 public function processRequest() { 41 $request = $this->getRequest(); 42 $user = $request->getUser(); 43 44 $conpherence_id = $this->getConpherenceID(); 45 if (!$conpherence_id) { 46 return new Aphront404Response(); 47 } 48 $conpherence = id(new ConpherenceThreadQuery()) 49 ->setViewer($user) 50 ->withIDs(array($conpherence_id)) 51 ->needWidgetData(true) 52 ->executeOne(); 53 $this->setConpherence($conpherence); 54 55 $this->setUserPreferences($user->loadPreferences()); 56 57 $widgets = $this->renderWidgetPaneContent(); 58 $content = $widgets; 59 return id(new AphrontAjaxResponse())->setContent($content); 60 } 61 62 private function renderWidgetPaneContent() { 63 require_celerity_resource('sprite-conpherence-css'); 64 $conpherence = $this->getConpherence(); 65 66 $widgets = array(); 67 $new_icon = id(new PHUIIconView()) 68 ->setIconFont('fa-plus') 69 ->setHref($this->getWidgetURI()) 70 ->setMetadata(array('widget' => null)) 71 ->addSigil('conpherence-widget-adder'); 72 $widgets[] = phutil_tag( 73 'div', 74 array( 75 'class' => 'widgets-header', 76 ), 77 id(new PHUIActionHeaderView()) 78 ->setHeaderColor(PHUIActionHeaderView::HEADER_GREY) 79 ->setHeaderTitle(pht('Participants')) 80 ->setHeaderHref('#') 81 ->setDropdown(true) 82 ->addAction($new_icon) 83 ->addHeaderSigil('widgets-selector')); 84 $user = $this->getRequest()->getUser(); 85 // now the widget bodies 86 $widgets[] = javelin_tag( 87 'div', 88 array( 89 'class' => 'widgets-body', 90 'id' => 'widgets-people', 91 'sigil' => 'widgets-people', 92 ), 93 id(new ConpherencePeopleWidgetView()) 94 ->setUser($user) 95 ->setConpherence($conpherence) 96 ->setUpdateURI($this->getWidgetURI())); 97 $widgets[] = javelin_tag( 98 'div', 99 array( 100 'class' => 'widgets-body', 101 'id' => 'widgets-files', 102 'sigil' => 'widgets-files', 103 'style' => 'display: none;', 104 ), 105 id(new ConpherenceFileWidgetView()) 106 ->setUser($user) 107 ->setConpherence($conpherence) 108 ->setUpdateURI($this->getWidgetURI())); 109 $widgets[] = phutil_tag( 110 'div', 111 array( 112 'class' => 'widgets-body', 113 'id' => 'widgets-calendar', 114 'style' => 'display: none;', 115 ), 116 $this->renderCalendarWidgetPaneContent()); 117 $widgets[] = phutil_tag( 118 'div', 119 array( 120 'class' => 'widgets-body', 121 'id' => 'widgets-settings', 122 'style' => 'display: none', 123 ), 124 $this->renderSettingsWidgetPaneContent()); 125 126 // without this implosion we get "," between each element in our widgets 127 // array 128 return array('widgets' => phutil_implode_html('', $widgets)); 129 } 130 131 private function renderSettingsWidgetPaneContent() { 132 $user = $this->getRequest()->getUser(); 133 $conpherence = $this->getConpherence(); 134 $participants = $conpherence->getParticipants(); 135 $participant = $participants[$user->getPHID()]; 136 $default = ConpherenceSettings::EMAIL_ALWAYS; 137 $preference = $this->getUserPreferences(); 138 if ($preference) { 139 $default = $preference->getPreference( 140 PhabricatorUserPreferences::PREFERENCE_CONPH_NOTIFICATIONS, 141 ConpherenceSettings::EMAIL_ALWAYS); 142 } 143 $settings = $participant->getSettings(); 144 $notifications = idx( 145 $settings, 146 'notifications', 147 $default); 148 $options = id(new AphrontFormRadioButtonControl()) 149 ->addButton( 150 ConpherenceSettings::EMAIL_ALWAYS, 151 ConpherenceSettings::getHumanString( 152 ConpherenceSettings::EMAIL_ALWAYS), 153 '') 154 ->addButton( 155 ConpherenceSettings::NOTIFICATIONS_ONLY, 156 ConpherenceSettings::getHumanString( 157 ConpherenceSettings::NOTIFICATIONS_ONLY), 158 '') 159 ->setName('notifications') 160 ->setValue($notifications); 161 162 $layout = array( 163 $options, 164 phutil_tag( 165 'input', 166 array( 167 'type' => 'hidden', 168 'name' => 'action', 169 'value' => 'notifications', 170 )), 171 phutil_tag( 172 'button', 173 array( 174 'type' => 'submit', 175 'class' => 'notifications-update', 176 ), 177 pht('Save')), 178 ); 179 180 return phabricator_form( 181 $user, 182 array( 183 'method' => 'POST', 184 'action' => $this->getWidgetURI(), 185 'sigil' => 'notifications-update', 186 ), 187 $layout); 188 } 189 190 private function renderCalendarWidgetPaneContent() { 191 $user = $this->getRequest()->getUser(); 192 193 $conpherence = $this->getConpherence(); 194 $participants = $conpherence->getParticipants(); 195 $widget_data = $conpherence->getWidgetData(); 196 $statuses = $widget_data['statuses']; 197 $handles = $conpherence->getHandles(); 198 $content = array(); 199 $layout = id(new AphrontMultiColumnView()) 200 ->setFluidLayout(true); 201 $timestamps = CalendarTimeUtil::getCalendarWidgetTimestamps($user); 202 $today = $timestamps['today']; 203 $epoch_stamps = $timestamps['epoch_stamps']; 204 $one_day = 24 * 60 * 60; 205 $is_today = false; 206 $calendar_columns = 0; 207 $list_days = 0; 208 foreach ($epoch_stamps as $day) { 209 // build a header for the new day 210 if ($day->format('Ymd') == $today->format('Ymd')) { 211 $active_class = 'today'; 212 $is_today = true; 213 } else { 214 $active_class = ''; 215 $is_today = false; 216 } 217 218 $should_draw_list = $list_days < 7; 219 $list_days++; 220 221 if ($should_draw_list) { 222 $content[] = phutil_tag( 223 'div', 224 array( 225 'class' => 'day-header '.$active_class, 226 ), 227 array( 228 phutil_tag( 229 'div', 230 array( 231 'class' => 'day-name', 232 ), 233 $day->format('l')), 234 phutil_tag( 235 'div', 236 array( 237 'class' => 'day-date', 238 ), 239 $day->format('m/d/y')), 240 )); 241 } 242 243 $week_day_number = $day->format('w'); 244 245 $epoch_start = $day->format('U'); 246 $next_day = clone $day; 247 $next_day->modify('+1 day'); 248 $epoch_end = $next_day->format('U'); 249 250 $first_status_of_the_day = true; 251 $statuses_of_the_day = array(); 252 // keep looking through statuses where we last left off 253 foreach ($statuses as $status) { 254 if ($status->getDateFrom() >= $epoch_end) { 255 // This list is sorted, so we can stop looking. 256 break; 257 } 258 259 if ($status->getDateFrom() < $epoch_end && 260 $status->getDateTo() > $epoch_start) { 261 $statuses_of_the_day[$status->getUserPHID()] = $status; 262 if ($should_draw_list) { 263 $top_border = ''; 264 if (!$first_status_of_the_day) { 265 $top_border = ' top-border'; 266 } 267 $timespan = $status->getDateTo() - $status->getDateFrom(); 268 if ($timespan > $one_day) { 269 $time_str = 'm/d'; 270 } else { 271 $time_str = 'h:i A'; 272 } 273 $epoch_range = 274 phabricator_format_local_time( 275 $status->getDateFrom(), 276 $user, 277 $time_str). 278 ' - '. 279 phabricator_format_local_time( 280 $status->getDateTo(), 281 $user, 282 $time_str); 283 284 $secondary_info = pht('%s, %s', 285 $handles[$status->getUserPHID()]->getName(), $epoch_range); 286 287 $content[] = phutil_tag( 288 'div', 289 array( 290 'class' => 'user-status '.$status->getTextStatus().$top_border, 291 ), 292 array( 293 phutil_tag( 294 'div', 295 array( 296 'class' => 'icon', 297 ), 298 ''), 299 phutil_tag( 300 'div', 301 array( 302 'class' => 'description', 303 ), 304 array( 305 $status->getTerseSummary($user), 306 phutil_tag( 307 'div', 308 array( 309 'class' => 'participant', 310 ), 311 $secondary_info), 312 )), 313 )); 314 } 315 $first_status_of_the_day = false; 316 } 317 } 318 319 // we didn't get a status on this day so add a spacer 320 if ($first_status_of_the_day && $should_draw_list) { 321 $content[] = phutil_tag( 322 'div', 323 array('class' => 'no-events pm'), 324 pht('No Events Scheduled.')); 325 } 326 if ($is_today || ($calendar_columns && $calendar_columns < 3)) { 327 $active_class = ''; 328 if ($is_today) { 329 $active_class = '-active'; 330 } 331 $inner_layout = array(); 332 foreach ($participants as $phid => $participant) { 333 $status = idx($statuses_of_the_day, $phid, false); 334 if ($status) { 335 $inner_layout[] = phutil_tag( 336 'div', 337 array( 338 'class' => $status->getTextStatus(), 339 ), 340 ''); 341 } else { 342 $inner_layout[] = phutil_tag( 343 'div', 344 array( 345 'class' => 'present', 346 ), 347 ''); 348 } 349 } 350 $layout->addColumn( 351 phutil_tag( 352 'div', 353 array( 354 'class' => 'day-column'.$active_class, 355 ), 356 array( 357 phutil_tag( 358 'div', 359 array( 360 'class' => 'day-name', 361 ), 362 $day->format('D')), 363 phutil_tag( 364 'div', 365 array( 366 'class' => 'day-number', 367 ), 368 $day->format('j')), 369 $inner_layout, 370 ))); 371 $calendar_columns++; 372 } 373 } 374 375 return array( 376 $layout, 377 $content, 378 ); 379 } 380 381 private function getWidgetURI() { 382 $conpherence = $this->getConpherence(); 383 return $this->getApplicationURI('update/'.$conpherence->getID().'/'); 384 } 385 386 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |