diff --git a/src/applications/people/controller/PhabricatorPeopleCalendarController.php b/src/applications/people/controller/PhabricatorPeopleCalendarController.php --- a/src/applications/people/controller/PhabricatorPeopleCalendarController.php +++ b/src/applications/people/controller/PhabricatorPeopleCalendarController.php @@ -35,12 +35,6 @@ $month = $request->getInt('month', $month_d); $day = phabricator_format_local_time($now, $user, 'j'); - - $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere( - 'day BETWEEN %s AND %s', - "{$year}-{$month}-01", - "{$year}-{$month}-31"); - $start_epoch = strtotime("{$year}-{$month}-01"); $end_epoch = strtotime("{$year}-{$month}-01 next month"); @@ -76,7 +70,6 @@ $month_view->setBrowseURI($request->getRequestURI()); $month_view->setUser($user); - $month_view->setHolidays($holidays); $month_view->setImage($picture); $phids = mpull($statuses, 'getUserPHID'); diff --git a/src/view/phui/calendar/PHUICalendarMonthView.php b/src/view/phui/calendar/PHUICalendarMonthView.php --- a/src/view/phui/calendar/PHUICalendarMonthView.php +++ b/src/view/phui/calendar/PHUICalendarMonthView.php @@ -7,7 +7,6 @@ private $day; private $month; private $year; - private $holidays = array(); private $events = array(); private $browseURI; private $image; @@ -36,12 +35,6 @@ return $this; } - public function setHolidays(array $holidays) { - assert_instances_of($holidays, 'PhabricatorCalendarHoliday'); - $this->holidays = mpull($holidays, null, 'getDay'); - return $this; - } - public function __construct( $range_start, $range_end, @@ -71,7 +64,7 @@ $first = reset($days); $empty = $first->format('w'); - $markup = array(); + $cell_lists = array(); $empty_cell = array( 'list' => null, 'date' => null, @@ -81,47 +74,28 @@ ); for ($ii = 0; $ii < $empty; $ii++) { - $markup[] = $empty_cell; + $cell_lists[] = $empty_cell; } - $show_events = array(); - foreach ($days as $day) { $day_number = $day->format('j'); - $holiday = idx($this->holidays, $day->format('Y-m-d')); $class = 'phui-calendar-month-day'; $weekday = $day->format('w'); - if ($holiday || $weekday == 0 || $weekday == 6) { - $class .= ' phui-calendar-not-work-day'; - } - $day->setTime(0, 0, 0); - $epoch_start = $day->format('U'); - - - $epoch_end = id(clone $day)->modify('+1 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', - "\xC2\xA0")); //   - } + $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() >= $epoch_end) { - // This list is sorted, so we can stop looking. + if ($event->getEpochStart() >= $day_end_epoch) { break; } - if ($event->getEpochStart() < $epoch_end && - $event->getEpochEnd() > $epoch_start) { + if ($event->getEpochStart() < $day_end_epoch && + $event->getEpochEnd() > $day_start_epoch) { if ($event->getIsAllDay()) { $all_day_events[] = $event; } else { @@ -144,7 +118,7 @@ $day->format('m').'/'. $day->format('d').'/'; - $markup[] = array( + $cell_lists[] = array( 'list' => $list, 'date' => $day, 'uri' => $uri, @@ -153,149 +127,34 @@ ); } - $table = array(); - $rows = array_chunk($markup, 7); + $rows = array(); + $cell_lists_by_week = array_chunk($cell_lists, 7); - foreach ($rows as $row) { + foreach ($cell_lists_by_week as $week_of_cell_lists) { $cells = array(); - $event_count_badge = null; - - while (count($row) < 7) { - $row[] = $empty_cell; + while (count($week_of_cell_lists) < 7) { + $week_of_cell_lists[] = $empty_cell; } - foreach ($row as $cell) { - $cell_list = $cell['list']; - $class = $cell['class']; - $uri = $cell['uri']; - $count = $cell['count']; - - $event_count = null; - if ($count > 0) { - $event_count = phutil_tag( - 'div', - array( - 'class' => 'phui-calendar-month-count-badge', - ), - $count); - } - - $event_count_badge = phutil_tag( - 'div', - array( - 'class' => 'phui-calendar-month-event-count', - ), - $event_count); - - $cell_day_secret_link = phutil_tag( - 'a', - array( - 'class' => 'phui-calendar-month-secret-link', - 'href' => $uri, - ), - null); - - $cell_div = phutil_tag( - 'div', - array( - 'class' => 'phui-calendar-month-cell-div', - ), - array( - $cell_day_secret_link, - $event_count_badge, - $cell_list, - )); - - $cells[] = phutil_tag( - 'td', - array( - 'class' => 'phui-calendar-month-event-list '.$class, - ), - $cell_div); + foreach ($week_of_cell_lists as $cell_list) { + $cells[] = $this->getEventListCell($cell_list); } - $table[] = phutil_tag('tr', array(), $cells); + $rows[] = phutil_tag('tr', array(), $cells); $cells = array(); - foreach ($row as $cell) { - $class = $cell['class']; - $cell_day_secret_link = null; - - if ($cell['date']) { - $cell_day = $cell['date']; - $uri = $cell['uri']; - - $cell_day_secret_link = phutil_tag( - 'a', - array( - 'class' => 'phui-calendar-month-secret-link', - 'href' => $uri, - ), - null); - - $cell_day = phutil_tag( - 'a', - array( - 'class' => 'phui-calendar-date-number', - 'href' => $uri, - ), - $cell_day->format('j')); - - } else { - $cell_day = null; - } - - if ($cell['date'] && $cell['date']->format('j') == $this->day) { - $today_class = 'phui-calendar-today-slot phui-calendar-today'; - } else { - $today_class = 'phui-calendar-today-slot'; - } - - $today_slot = phutil_tag ( - 'div', - array( - 'class' => $today_class, - ), - null); - - $cell_div = phutil_tag( - 'div', - array( - 'class' => 'phui-calendar-month-cell-div', - ), - array( - $cell_day_secret_link, - $cell_day, - $today_slot, - )); - - $cells[] = phutil_tag( - 'td', - array( - 'class' => 'phui-calendar-date-number-container '.$class, - ), - $cell_div); + foreach ($week_of_cell_lists as $cell_list) { + $cells[] = $this->getDayNumberCell($cell_list); } - $table[] = phutil_tag('tr', array(), $cells); + $rows[] = 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')), - )); + $header = $this->getDayNamesHeader(); $table = phutil_tag( 'table', array('class' => 'phui-calendar-view'), array( $header, - phutil_implode_html("\n", $table), + $rows, )); $warnings = $this->getQueryRangeWarning(); @@ -312,6 +171,130 @@ return $box; } + private function getEventListCell($event_list) { + $list = $event_list['list']; + $class = $event_list['class']; + $uri = $event_list['uri']; + $count = $event_list['count']; + + $event_count_badge = $this->getEventCountBadge($count); + $cell_day_secret_link = $this->getHiddenDayLink($uri); + + $cell_data_div = phutil_tag( + 'div', + array( + 'class' => 'phui-calendar-month-cell-div', + ), + array( + $cell_day_secret_link, + $event_count_badge, + $list, + )); + + return phutil_tag( + 'td', + array( + 'class' => 'phui-calendar-month-event-list '.$class, + ), + $cell_data_div); + } + + private function getDayNumberCell($event_list) { + $class = $event_list['class']; + $date = $event_list['date']; + $cell_day_secret_link = null; + + if ($date) { + $uri = $event_list['uri']; + $cell_day_secret_link = $this->getHiddenDayLink($uri); + + $cell_day = phutil_tag( + 'a', + array( + 'class' => 'phui-calendar-date-number', + 'href' => $uri, + ), + $date->format('j')); + } else { + $cell_day = null; + } + + if ($date && $date->format('j') == $this->day) { + $today_class = 'phui-calendar-today-slot phui-calendar-today'; + } else { + $today_class = 'phui-calendar-today-slot'; + } + + $today_slot = phutil_tag ( + 'div', + array( + 'class' => $today_class, + ), + null); + + $cell_div = phutil_tag( + 'div', + array( + 'class' => 'phui-calendar-month-cell-div', + ), + array( + $cell_day_secret_link, + $cell_day, + $today_slot, + )); + + return phutil_tag( + 'td', + array( + 'class' => 'phui-calendar-date-number-container '.$class, + ), + $cell_div); + } + + private function getEventCountBadge($count) { + $event_count = null; + if ($count > 0) { + $event_count = phutil_tag( + 'div', + array( + 'class' => 'phui-calendar-month-count-badge', + ), + $count); + } + + return phutil_tag( + 'div', + array( + 'class' => 'phui-calendar-month-event-count', + ), + $event_count); + } + + private function getHiddenDayLink($uri) { + return phutil_tag( + 'a', + array( + 'class' => 'phui-calendar-month-secret-link', + 'href' => $uri, + ), + null); + } + + private function getDayNamesHeader() { + return 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')), + )); + } + private function renderCalendarHeader(DateTime $date) { $button_bar = null;