diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9e11af068f..270765dbef 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1317,6 +1317,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarHoliday' => 'applications/calendar/storage/PhabricatorCalendarHoliday.php', 'PhabricatorCalendarHolidayTestCase' => 'applications/calendar/storage/__tests__/PhabricatorCalendarHolidayTestCase.php', 'PhabricatorCalendarPHIDTypeEvent' => 'applications/calendar/phid/PhabricatorCalendarPHIDTypeEvent.php', + 'PhabricatorCalendarViewController' => 'applications/calendar/controller/PhabricatorCalendarViewController.php', 'PhabricatorCampfireProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorCampfireProtocolAdapter.php', 'PhabricatorChangeParserTestCase' => 'applications/repository/worker/__tests__/PhabricatorChangeParserTestCase.php', 'PhabricatorChangesetResponse' => 'infrastructure/diff/PhabricatorChangesetResponse.php', @@ -4032,6 +4033,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarHoliday' => 'PhabricatorCalendarDAO', 'PhabricatorCalendarHolidayTestCase' => 'PhabricatorTestCase', 'PhabricatorCalendarPHIDTypeEvent' => 'PhabricatorPHIDType', + 'PhabricatorCalendarViewController' => 'PhabricatorCalendarController', 'PhabricatorCampfireProtocolAdapter' => 'PhabricatorBotBaseStreamingProtocolAdapter', 'PhabricatorChangeParserTestCase' => 'PhabricatorWorkingCopyTestCase', 'PhabricatorChangesetResponse' => 'AphrontProxyResponse', diff --git a/src/applications/calendar/application/PhabricatorApplicationCalendar.php b/src/applications/calendar/application/PhabricatorApplicationCalendar.php index 9c86af7fde..26196943c1 100644 --- a/src/applications/calendar/application/PhabricatorApplicationCalendar.php +++ b/src/applications/calendar/application/PhabricatorApplicationCalendar.php @@ -35,7 +35,8 @@ final class PhabricatorApplicationCalendar extends PhabricatorApplication { public function getRoutes() { return array( '/calendar/' => array( - '' => 'PhabricatorCalendarBrowseController', + '' => 'PhabricatorCalendarViewController', + 'all/' => 'PhabricatorCalendarBrowseController', 'event/' => array( '(?:query/(?P[^/]+)/)?' => 'PhabricatorCalendarEventListController', diff --git a/src/applications/calendar/controller/PhabricatorCalendarBrowseController.php b/src/applications/calendar/controller/PhabricatorCalendarBrowseController.php index 0a8f329921..c382d1ebb0 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarBrowseController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarBrowseController.php @@ -73,14 +73,14 @@ final class PhabricatorCalendarBrowseController $date = new DateTime("{$year}-{$month}-01"); $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('All Events')); $crumbs->addTextCrumb($date->format('F Y')); $nav = $this->buildSideNavView(); - $nav->selectFilter('/'); + $nav->selectFilter('all/'); $nav->appendChild( array( $crumbs, - $this->getNoticeView(), $month_view, )); @@ -92,25 +92,4 @@ final class PhabricatorCalendarBrowseController )); } - private function getNoticeView() { - $request = $this->getRequest(); - $view = null; - - if ($request->getExists('created')) { - $view = id(new AphrontErrorView()) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) - ->setTitle(pht('Successfully created your status.')); - } else if ($request->getExists('updated')) { - $view = id(new AphrontErrorView()) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) - ->setTitle(pht('Successfully updated your status.')); - } else if ($request->getExists('deleted')) { - $view = id(new AphrontErrorView()) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) - ->setTitle(pht('Successfully deleted your status.')); - } - - return $view; - } - } diff --git a/src/applications/calendar/controller/PhabricatorCalendarController.php b/src/applications/calendar/controller/PhabricatorCalendarController.php index c9328cab2f..b191ef2d94 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarController.php @@ -8,7 +8,8 @@ abstract class PhabricatorCalendarController extends PhabricatorController { $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->addLabel(pht('Calendar')); - $nav->addFilter('/', pht('View All')); + $nav->addFilter('/', pht('My Events')); + $nav->addFilter('all/', pht('View All')); $nav->addFilter('event/create/', pht('Create Event')); if ($status && $status->getID()) { diff --git a/src/applications/calendar/controller/PhabricatorCalendarViewController.php b/src/applications/calendar/controller/PhabricatorCalendarViewController.php new file mode 100644 index 0000000000..16cd41dffa --- /dev/null +++ b/src/applications/calendar/controller/PhabricatorCalendarViewController.php @@ -0,0 +1,97 @@ +getRequest()->getUser(); + + $now = time(); + $request = $this->getRequest(); + $year_d = phabricator_format_local_time($now, $user, 'Y'); + $year = $request->getInt('year', $year_d); + $month_d = phabricator_format_local_time($now, $user, 'm'); + $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"); + + $statuses = id(new PhabricatorCalendarEventQuery()) + ->setViewer($user) + ->withInvitedPHIDs(array($user->getPHID())) + ->withDateRange( + strtotime("{$year}-{$month}-01"), + strtotime("{$year}-{$month}-01 next month")) + ->execute(); + + if ($month == $month_d && $year == $year_d) { + $month_view = new PHUICalendarMonthView($month, $year, $day); + } else { + $month_view = new PHUICalendarMonthView($month, $year); + } + + $month_view->setBrowseURI($request->getRequestURI()); + $month_view->setUser($user); + $month_view->setHolidays($holidays); + + $phids = mpull($statuses, 'getUserPHID'); + $handles = $this->loadViewerHandles($phids); + + foreach ($statuses as $status) { + $event = new AphrontCalendarEventView(); + $event->setEpochRange($status->getDateFrom(), $status->getDateTo()); + $event->setUserPHID($status->getUserPHID()); + $event->setName($status->getHumanStatus()); + $event->setDescription($status->getDescription()); + $event->setEventID($status->getID()); + $month_view->addEvent($event); + } + + $date = new DateTime("{$year}-{$month}-01"); + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb(pht('My Events')); + $crumbs->addTextCrumb($date->format('F Y')); + + $nav = $this->buildSideNavView(); + $nav->selectFilter('/'); + $nav->appendChild( + array( + $crumbs, + $this->getNoticeView(), + $month_view, + )); + + return $this->buildApplicationPage( + $nav, + array( + 'title' => pht('Calendar'), + 'device' => true, + )); + } + + private function getNoticeView() { + $request = $this->getRequest(); + $view = null; + + if ($request->getExists('created')) { + $view = id(new AphrontErrorView()) + ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) + ->setTitle(pht('Successfully created your status.')); + } else if ($request->getExists('updated')) { + $view = id(new AphrontErrorView()) + ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) + ->setTitle(pht('Successfully updated your status.')); + } else if ($request->getExists('deleted')) { + $view = id(new AphrontErrorView()) + ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) + ->setTitle(pht('Successfully deleted your status.')); + } + + return $view; + } + +}