[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/calendar/controller/ -> PhabricatorCalendarViewController.php (source)

   1  <?php
   2  
   3  final class PhabricatorCalendarViewController
   4    extends PhabricatorCalendarController {
   5  
   6    public function shouldAllowPublic() {
   7      return true;
   8    }
   9  
  10    public function processRequest() {
  11      $user = $this->getRequest()->getUser();
  12  
  13      $now     = time();
  14      $request = $this->getRequest();
  15      $year_d  = phabricator_format_local_time($now, $user, 'Y');
  16      $year    = $request->getInt('year', $year_d);
  17      $month_d = phabricator_format_local_time($now, $user, 'm');
  18      $month   = $request->getInt('month', $month_d);
  19      $day   = phabricator_format_local_time($now, $user, 'j');
  20  
  21  
  22      $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere(
  23        'day BETWEEN %s AND %s',
  24        "{$year}-{$month}-01",
  25        "{$year}-{$month}-31");
  26  
  27      $statuses = id(new PhabricatorCalendarEventQuery())
  28        ->setViewer($user)
  29        ->withInvitedPHIDs(array($user->getPHID()))
  30        ->withDateRange(
  31          strtotime("{$year}-{$month}-01"),
  32          strtotime("{$year}-{$month}-01 next month"))
  33        ->execute();
  34  
  35      if ($month == $month_d && $year == $year_d) {
  36        $month_view = new PHUICalendarMonthView($month, $year, $day);
  37      } else {
  38        $month_view = new PHUICalendarMonthView($month, $year);
  39      }
  40  
  41      $month_view->setBrowseURI($request->getRequestURI());
  42      $month_view->setUser($user);
  43      $month_view->setHolidays($holidays);
  44  
  45      $phids = mpull($statuses, 'getUserPHID');
  46      $handles = $this->loadViewerHandles($phids);
  47  
  48      foreach ($statuses as $status) {
  49        $event = new AphrontCalendarEventView();
  50        $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
  51        $event->setUserPHID($status->getUserPHID());
  52        $event->setName($status->getHumanStatus());
  53        $event->setDescription($status->getDescription());
  54        $event->setEventID($status->getID());
  55        $month_view->addEvent($event);
  56      }
  57  
  58      $date = new DateTime("{$year}-{$month}-01");
  59      $crumbs = $this->buildApplicationCrumbs();
  60      $crumbs->addTextCrumb(pht('My Events'));
  61      $crumbs->addTextCrumb($date->format('F Y'));
  62  
  63      $nav = $this->buildSideNavView();
  64      $nav->selectFilter('/');
  65      $nav->appendChild(
  66        array(
  67          $crumbs,
  68          $this->getNoticeView(),
  69          $month_view,
  70        ));
  71  
  72      return $this->buildApplicationPage(
  73       $nav,
  74       array(
  75          'title' => pht('Calendar'),
  76        ));
  77    }
  78  
  79    private function getNoticeView() {
  80      $request = $this->getRequest();
  81      $view    = null;
  82  
  83      if ($request->getExists('created')) {
  84        $view = id(new AphrontErrorView())
  85          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
  86          ->setTitle(pht('Successfully created your status.'));
  87      } else if ($request->getExists('updated')) {
  88        $view = id(new AphrontErrorView())
  89          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
  90          ->setTitle(pht('Successfully updated your status.'));
  91      } else if ($request->getExists('deleted')) {
  92        $view = id(new AphrontErrorView())
  93          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
  94          ->setTitle(pht('Successfully deleted your status.'));
  95      } else if (!$request->getUser()->isLoggedIn()) {
  96        $login_uri = id(new PhutilURI('/auth/start/'))
  97          ->setQueryParam('next', '/calendar/');
  98        $view = id(new AphrontErrorView())
  99          ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
 100          ->setTitle(
 101            pht(
 102              'You are not logged in. %s to see your calendar events.',
 103              phutil_tag(
 104                'a',
 105                array(
 106                  'href' => $login_uri,
 107                ),
 108                pht('Log in'))));
 109      }
 110  
 111      return $view;
 112    }
 113  
 114  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1