[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/people/controller/ -> PhabricatorPeopleCalendarController.php (source)

   1  <?php
   2  
   3  final class PhabricatorPeopleCalendarController
   4    extends PhabricatorPeopleController {
   5  
   6    private $username;
   7  
   8    public function shouldRequireAdmin() {
   9      return false;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->username = idx($data, 'username');
  14    }
  15  
  16    public function processRequest() {
  17      $viewer = $this->getRequest()->getUser();
  18      $user = id(new PhabricatorPeopleQuery())
  19        ->setViewer($viewer)
  20        ->withUsernames(array($this->username))
  21        ->needProfileImage(true)
  22        ->executeOne();
  23  
  24      if (!$user) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $picture = $user->loadProfileImageURI();
  29  
  30      $now     = time();
  31      $request = $this->getRequest();
  32      $year_d  = phabricator_format_local_time($now, $user, 'Y');
  33      $year    = $request->getInt('year', $year_d);
  34      $month_d = phabricator_format_local_time($now, $user, 'm');
  35      $month   = $request->getInt('month', $month_d);
  36      $day   = phabricator_format_local_time($now, $user, 'j');
  37  
  38  
  39      $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere(
  40        'day BETWEEN %s AND %s',
  41        "{$year}-{$month}-01",
  42        "{$year}-{$month}-31");
  43  
  44      $statuses = id(new PhabricatorCalendarEventQuery())
  45        ->setViewer($user)
  46        ->withInvitedPHIDs(array($user->getPHID()))
  47        ->withDateRange(
  48          strtotime("{$year}-{$month}-01"),
  49          strtotime("{$year}-{$month}-01 next month"))
  50        ->execute();
  51  
  52      if ($month == $month_d && $year == $year_d) {
  53        $month_view = new PHUICalendarMonthView($month, $year, $day);
  54      } else {
  55        $month_view = new PHUICalendarMonthView($month, $year);
  56      }
  57  
  58      $month_view->setBrowseURI($request->getRequestURI());
  59      $month_view->setUser($user);
  60      $month_view->setHolidays($holidays);
  61      $month_view->setImage($picture);
  62  
  63      $phids = mpull($statuses, 'getUserPHID');
  64      $handles = $this->loadViewerHandles($phids);
  65  
  66      foreach ($statuses as $status) {
  67        $event = new AphrontCalendarEventView();
  68        $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
  69        $event->setUserPHID($status->getUserPHID());
  70        $event->setName($status->getHumanStatus());
  71        $event->setDescription($status->getDescription());
  72        $event->setEventID($status->getID());
  73        $month_view->addEvent($event);
  74      }
  75  
  76      $date = new DateTime("{$year}-{$month}-01");
  77      $crumbs = $this->buildApplicationCrumbs();
  78      $crumbs->addTextCrumb(
  79        $user->getUsername(),
  80        '/p/'.$user->getUsername().'/');
  81      $crumbs->addTextCrumb($date->format('F Y'));
  82  
  83      return $this->buildApplicationPage(
  84        array(
  85          $crumbs,
  86          $month_view,
  87       ),
  88       array(
  89         'title' => pht('Calendar'),
  90       ));
  91    }
  92  }


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