[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorCalendarBrowseController
   4    extends PhabricatorCalendarController {
   5  
   6    public function shouldAllowPublic() {
   7      return true;
   8    }
   9  
  10    public function processRequest() {
  11      $now     = time();
  12      $request = $this->getRequest();
  13      $user    = $request->getUser();
  14      $year_d  = phabricator_format_local_time($now, $user, 'Y');
  15      $year    = $request->getInt('year', $year_d);
  16      $month_d = phabricator_format_local_time($now, $user, 'm');
  17      $month   = $request->getInt('month', $month_d);
  18      $day   = phabricator_format_local_time($now, $user, 'j');
  19  
  20  
  21      $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere(
  22        'day BETWEEN %s AND %s',
  23        "{$year}-{$month}-01",
  24        "{$year}-{$month}-31");
  25  
  26      $statuses = id(new PhabricatorCalendarEventQuery())
  27        ->setViewer($user)
  28        ->withDateRange(
  29          strtotime("{$year}-{$month}-01"),
  30          strtotime("{$year}-{$month}-01 next month"))
  31        ->execute();
  32  
  33      if ($month == $month_d && $year == $year_d) {
  34        $month_view = new PHUICalendarMonthView($month, $year, $day);
  35      } else {
  36        $month_view = new PHUICalendarMonthView($month, $year);
  37      }
  38  
  39      $month_view->setBrowseURI($request->getRequestURI());
  40      $month_view->setUser($user);
  41      $month_view->setHolidays($holidays);
  42  
  43      $phids = mpull($statuses, 'getUserPHID');
  44      $handles = $this->loadViewerHandles($phids);
  45  
  46      /* Assign Colors */
  47      $unique = array_unique($phids);
  48      $allblue = false;
  49      $calcolors = CalendarColors::getColors();
  50      if (count($unique) > count($calcolors)) {
  51        $allblue = true;
  52      }
  53      $i = 0;
  54      $eventcolor = array();
  55      foreach ($unique as $phid) {
  56        if ($allblue) {
  57          $eventcolor[$phid] = CalendarColors::COLOR_SKY;
  58        } else {
  59          $eventcolor[$phid] = $calcolors[$i];
  60        }
  61        $i++;
  62      }
  63  
  64      foreach ($statuses as $status) {
  65        $event = new AphrontCalendarEventView();
  66        $event->setEpochRange($status->getDateFrom(), $status->getDateTo());
  67  
  68        $name_text = $handles[$status->getUserPHID()]->getName();
  69        $status_text = $status->getHumanStatus();
  70        $event->setUserPHID($status->getUserPHID());
  71        $event->setDescription(pht('%s (%s)', $name_text, $status_text));
  72        $event->setName($status_text);
  73        $event->setEventID($status->getID());
  74        $event->setColor($eventcolor[$status->getUserPHID()]);
  75        $month_view->addEvent($event);
  76      }
  77  
  78      $date = new DateTime("{$year}-{$month}-01");
  79      $crumbs = $this->buildApplicationCrumbs();
  80      $crumbs->addTextCrumb(pht('All Events'));
  81      $crumbs->addTextCrumb($date->format('F Y'));
  82  
  83      $nav = $this->buildSideNavView();
  84      $nav->selectFilter('all/');
  85      $nav->appendChild(
  86        array(
  87          $crumbs,
  88          $month_view,
  89        ));
  90  
  91      return $this->buildApplicationPage(
  92       $nav,
  93       array(
  94          'title' => pht('Calendar'),
  95        ));
  96    }
  97  
  98  }


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