private function renderUserCalendar(PhabricatorUser $user)
 {
     $viewer = $this->getRequest()->getUser();
     $epochs = CalendarTimeUtil::getCalendarEventEpochs($viewer, 'today', 7);
     $start_epoch = $epochs['start_epoch'];
     $end_epoch = $epochs['end_epoch'];
     $statuses = id(new PhabricatorCalendarEventQuery())->setViewer($viewer)->withInvitedPHIDs(array($user->getPHID()))->withDateRange($start_epoch, $end_epoch)->execute();
     $timestamps = CalendarTimeUtil::getCalendarWeekTimestamps($viewer);
     $today = $timestamps['today'];
     $epoch_stamps = $timestamps['epoch_stamps'];
     $events = array();
     foreach ($epoch_stamps as $day) {
         $epoch_start = $day->format('U');
         $next_day = clone $day;
         $next_day->modify('+1 day');
         $epoch_end = $next_day->format('U');
         foreach ($statuses as $status) {
             if ($status->getDateTo() < $epoch_start) {
                 continue;
             }
             if ($status->getDateFrom() >= $epoch_end) {
                 continue;
             }
             $event = new AphrontCalendarEventView();
             $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
             $status_text = $status->getHumanStatus();
             $event->setUserPHID($status->getUserPHID());
             $event->setName($status_text);
             $event->setDescription($status->getDescription());
             $event->setEventID($status->getID());
             $events[$epoch_start][] = $event;
         }
     }
     $week = array();
     foreach ($epoch_stamps as $day) {
         $epoch = $day->format('U');
         $headertext = phabricator_format_local_time($epoch, $user, 'l, M d');
         $list = new PHUICalendarListView();
         $list->setUser($viewer);
         $list->showBlankState(true);
         if (isset($events[$epoch])) {
             foreach ($events[$epoch] as $event) {
                 $list->addEvent($event);
             }
         }
         $header = phutil_tag('a', array('href' => $this->getRequest()->getRequestURI() . 'calendar/'), $headertext);
         $calendar = new PHUICalendarWidgetView();
         $calendar->setHeader($header);
         $calendar->setCalendarList($list);
         $week[] = $calendar;
     }
     return phutil_tag_div('profile-calendar', $week);
 }
Пример #2
0
 private function loadWidgetData(array $conpherences)
 {
     $participant_phids = array();
     $file_phids = array();
     foreach ($conpherences as $conpherence) {
         $participant_phids[] = array_keys($conpherence->getParticipants());
         $file_phids[] = $conpherence->getFilePHIDs();
     }
     $participant_phids = array_mergev($participant_phids);
     $file_phids = array_mergev($file_phids);
     $epochs = CalendarTimeUtil::getCalendarEventEpochs($this->getViewer());
     $start_epoch = $epochs['start_epoch'];
     $end_epoch = $epochs['end_epoch'];
     $events = array();
     if ($participant_phids) {
         $events = id(new PhabricatorCalendarEventQuery())->setViewer($this->getViewer())->withInvitedPHIDs($participant_phids)->withIsCancelled(false)->withDateRange($start_epoch, $end_epoch)->execute();
         $events = mpull($events, null, 'getPHID');
     }
     $invitees = array();
     foreach ($events as $event_phid => $event) {
         foreach ($event->getInvitees() as $invitee) {
             $invitees[$invitee->getInviteePHID()][$event_phid] = true;
         }
     }
     // attached files
     $files = array();
     $file_author_phids = array();
     $authors = array();
     if ($file_phids) {
         $files = id(new PhabricatorFileQuery())->setViewer($this->getViewer())->withPHIDs($file_phids)->execute();
         $files = mpull($files, null, 'getPHID');
         $file_author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
         $authors = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs($file_author_phids)->execute();
         $authors = mpull($authors, null, 'getPHID');
     }
     foreach ($conpherences as $phid => $conpherence) {
         $participant_phids = array_keys($conpherence->getParticipants());
         $widget_data = array();
         $event_phids = array();
         $participant_invites = array_select_keys($invitees, $participant_phids);
         foreach ($participant_invites as $invite_set) {
             $event_phids += $invite_set;
         }
         $thread_events = array_select_keys($events, array_keys($event_phids));
         $thread_events = msort($thread_events, 'getDateFrom');
         $widget_data['events'] = $thread_events;
         $conpherence_files = array();
         $files_authors = array();
         foreach ($conpherence->getFilePHIDs() as $curr_phid) {
             $curr_file = idx($files, $curr_phid);
             if (!$curr_file) {
                 // this file was deleted or user doesn't have permission to see it
                 // this is generally weird
                 continue;
             }
             $conpherence_files[$curr_phid] = $curr_file;
             // some files don't have authors so be careful
             $current_author = null;
             $current_author_phid = idx($file_author_phids, $curr_phid);
             if ($current_author_phid) {
                 $current_author = $authors[$current_author_phid];
             }
             $files_authors[$curr_phid] = $current_author;
         }
         $widget_data += array('files' => $conpherence_files, 'files_authors' => $files_authors);
         $conpherence->attachWidgetData($widget_data);
     }
     return $this;
 }