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); }
public function render() { if (empty($this->user)) { throw new PhutilInvalidStateException('setUser'); } $events = msort($this->events, 'getEpochStart'); $days = $this->getDatesInMonth(); $cell_lists = array(); require_celerity_resource('phui-calendar-month-css'); foreach ($days as $day) { $day_number = $day->format('j'); $class = 'phui-calendar-month-day'; $weekday = $day->format('w'); $day->setTime(0, 0, 0); $day_start_epoch = $day->format('U'); $day_end_epoch = id(clone $day)->modify('+1 day')->format('U'); $list_events = array(); $all_day_events = array(); foreach ($events as $event) { if ($event->getEpochStart() >= $day_end_epoch) { break; } if ($event->getEpochStart() < $day_end_epoch && $event->getEpochEnd() > $day_start_epoch) { if ($event->getIsAllDay()) { $all_day_events[] = $event; } else { $list_events[] = $event; } } } $max_daily = 15; $counter = 0; $list = new PHUICalendarListView(); $list->setUser($this->user); foreach ($all_day_events as $item) { if ($counter <= $max_daily) { $list->addEvent($item); } $counter++; } foreach ($list_events as $item) { if ($counter <= $max_daily) { $list->addEvent($item); } $counter++; } $uri = $this->getBrowseURI(); $uri = $uri . $day->format('Y') . '/' . $day->format('m') . '/' . $day->format('d') . '/'; $cell_lists[] = array('list' => $list, 'date' => $day, 'uri' => $uri, 'count' => count($all_day_events) + count($list_events), 'class' => $class); } $rows = array(); $cell_lists_by_week = array_chunk($cell_lists, 7); foreach ($cell_lists_by_week as $week_of_cell_lists) { $cells = array(); $max_count = $this->getMaxDailyEventsForWeek($week_of_cell_lists); foreach ($week_of_cell_lists as $cell_list) { $cells[] = $this->getEventListCell($cell_list, $max_count); } $rows[] = phutil_tag('tr', array(), $cells); $cells = array(); foreach ($week_of_cell_lists as $cell_list) { $cells[] = $this->getDayNumberCell($cell_list); } $rows[] = phutil_tag('tr', array(), $cells); } $header = $this->getDayNamesHeader(); $table = phutil_tag('table', array('class' => 'phui-calendar-view'), array($header, $rows)); $warnings = $this->getQueryRangeWarning(); $box = id(new PHUIObjectBoxView())->setHeader($this->renderCalendarHeader($this->getDateTime()))->appendChild($table)->setFormErrors($warnings); if ($this->error) { $box->setInfoView($this->error); } return $box; }
public function render() { if (empty($this->user)) { throw new Exception('Call setUser() before render()!'); } $events = msort($this->events, 'getEpochStart'); $days = $this->getDatesInMonth(); require_celerity_resource('phui-calendar-month-css'); $first = reset($days); $empty = $first->format('w'); $markup = array(); $empty_box = phutil_tag('div', array('class' => 'phui-calendar-day phui-calendar-empty'), ''); for ($ii = 0; $ii < $empty; $ii++) { $markup[] = $empty_box; } $show_events = array(); foreach ($days as $day) { $day_number = $day->format('j'); $holiday = idx($this->holidays, $day->format('Y-m-d')); $class = 'phui-calendar-day'; $weekday = $day->format('w'); if ($day_number == $this->day) { $class .= ' phui-calendar-today'; } if ($holiday || $weekday == 0 || $weekday == 6) { $class .= ' phui-calendar-not-work-day'; } $day->setTime(0, 0, 0); $epoch_start = $day->format('U'); $day->modify('+1 day'); $epoch_end = $day->format('U'); if ($weekday == 0) { $show_events = array(); } else { $show_events = array_fill_keys(array_keys($show_events), phutil_tag_div('phui-calendar-event phui-calendar-event-empty', " ")); // } $list_events = array(); foreach ($events as $event) { if ($event->getEpochStart() >= $epoch_end) { // This list is sorted, so we can stop looking. break; } if ($event->getEpochStart() < $epoch_end && $event->getEpochEnd() > $epoch_start) { $list_events[] = $event; } } $list = new PHUICalendarListView(); $list->setUser($this->user); foreach ($list_events as $item) { $list->addEvent($item); } $holiday_markup = null; if ($holiday) { $name = $holiday->getName(); $holiday_markup = phutil_tag('div', array('class' => 'phui-calendar-holiday', 'title' => $name), $name); } $markup[] = phutil_tag_div($class, array(phutil_tag_div('phui-calendar-date-number', $day_number), $holiday_markup, $list)); } $table = array(); $rows = array_chunk($markup, 7); foreach ($rows as $row) { $cells = array(); while (count($row) < 7) { $row[] = $empty_box; } $j = 0; foreach ($row as $cell) { if ($j == 0) { $cells[] = phutil_tag('td', array('class' => 'phui-calendar-month-weekstart'), $cell); } else { $cells[] = phutil_tag('td', array(), $cell); } $j++; } $table[] = phutil_tag('tr', array(), $cells); } $header = phutil_tag('tr', array('class' => 'phui-calendar-day-of-week-header'), array(phutil_tag('th', array(), pht('Sun')), phutil_tag('th', array(), pht('Mon')), phutil_tag('th', array(), pht('Tue')), phutil_tag('th', array(), pht('Wed')), phutil_tag('th', array(), pht('Thu')), phutil_tag('th', array(), pht('Fri')), phutil_tag('th', array(), pht('Sat')))); $table = phutil_tag('table', array('class' => 'phui-calendar-view'), array($header, phutil_implode_html("\n", $table))); $box = id(new PHUIObjectBoxView())->setHeader($this->renderCalendarHeader($first))->appendChild($table); return $box; }