Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontCalendarMonthView extends AphrontView {
|
|
|
|
|
|
|
|
private $month;
|
|
|
|
private $year;
|
2012-05-03 09:21:47 +02:00
|
|
|
private $holidays = array();
|
2012-05-21 19:24:23 +02:00
|
|
|
private $events = array();
|
2012-10-24 22:22:24 +02:00
|
|
|
private $browseURI;
|
|
|
|
|
|
|
|
public function setBrowseURI($browse_uri) {
|
|
|
|
$this->browseURI = $browse_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
private function getBrowseURI() {
|
|
|
|
return $this->browseURI;
|
|
|
|
}
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
|
2012-05-21 19:24:23 +02:00
|
|
|
public function addEvent(AphrontCalendarEventView $event) {
|
|
|
|
$this->events[] = $event;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-05-03 09:21:47 +02:00
|
|
|
public function setHolidays(array $holidays) {
|
|
|
|
assert_instances_of($holidays, 'PhabricatorCalendarHoliday');
|
|
|
|
$this->holidays = mpull($holidays, null, 'getDay');
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
public function __construct($month, $year) {
|
|
|
|
$this->month = $month;
|
|
|
|
$this->year = $year;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
if (empty($this->user)) {
|
|
|
|
throw new Exception("Call setUser() before render()!");
|
|
|
|
}
|
|
|
|
|
2012-05-21 19:24:23 +02:00
|
|
|
$events = msort($this->events, 'getEpochStart');
|
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
$days = $this->getDatesInMonth();
|
|
|
|
|
|
|
|
require_celerity_resource('aphront-calendar-view-css');
|
|
|
|
|
|
|
|
$first = reset($days);
|
|
|
|
$empty = $first->format('w');
|
|
|
|
|
|
|
|
$markup = array();
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$empty_box = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array('class' => 'aphront-calendar-day aphront-calendar-empty'),
|
|
|
|
'');
|
2012-05-21 19:24:23 +02:00
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
for ($ii = 0; $ii < $empty; $ii++) {
|
2012-05-21 19:24:23 +02:00
|
|
|
$markup[] = $empty_box;
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 20:59:12 +02:00
|
|
|
$show_events = array();
|
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
foreach ($days as $day) {
|
2012-06-28 19:24:33 +02:00
|
|
|
$day_number = $day->format('j');
|
|
|
|
|
2012-05-03 09:21:47 +02:00
|
|
|
$holiday = idx($this->holidays, $day->format('Y-m-d'));
|
2012-05-21 19:24:23 +02:00
|
|
|
$class = 'aphront-calendar-day';
|
2012-05-03 09:21:47 +02:00
|
|
|
$weekday = $day->format('w');
|
|
|
|
if ($holiday || $weekday == 0 || $weekday == 6) {
|
|
|
|
$class .= ' aphront-calendar-not-work-day';
|
|
|
|
}
|
2012-05-21 19:24:23 +02:00
|
|
|
|
|
|
|
$day->setTime(0, 0, 0);
|
|
|
|
$epoch_start = $day->format('U');
|
|
|
|
|
2012-06-28 19:24:33 +02:00
|
|
|
$day->modify('+1 day');
|
2012-05-21 19:24:23 +02:00
|
|
|
$epoch_end = $day->format('U');
|
|
|
|
|
2012-05-21 20:59:12 +02:00
|
|
|
if ($weekday == 0) {
|
|
|
|
$show_events = array();
|
|
|
|
} else {
|
|
|
|
$show_events = array_fill_keys(
|
|
|
|
array_keys($show_events),
|
2013-02-13 23:50:15 +01:00
|
|
|
hsprintf(
|
|
|
|
'<div class="aphront-calendar-event aphront-calendar-event-empty">'.
|
|
|
|
' '.
|
|
|
|
'</div>'));
|
2012-05-21 20:59:12 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 19:24:23 +02:00
|
|
|
foreach ($events as $event) {
|
2012-05-21 20:59:12 +02:00
|
|
|
if ($event->getEpochStart() >= $epoch_end) {
|
2012-05-21 19:24:23 +02:00
|
|
|
// This list is sorted, so we can stop looking.
|
|
|
|
break;
|
|
|
|
}
|
2012-05-21 20:59:12 +02:00
|
|
|
if ($event->getEpochStart() < $epoch_end &&
|
|
|
|
$event->getEpochEnd() > $epoch_start) {
|
|
|
|
$show_events[$event->getUserPHID()] = $this->renderEvent(
|
2012-05-21 19:24:23 +02:00
|
|
|
$event,
|
|
|
|
$epoch_start,
|
|
|
|
$epoch_end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$holiday_markup = null;
|
|
|
|
if ($holiday) {
|
2013-02-13 23:50:15 +01:00
|
|
|
$name = $holiday->getName();
|
|
|
|
$holiday_markup = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-calendar-holiday',
|
|
|
|
'title' => $name,
|
|
|
|
),
|
|
|
|
$name);
|
2012-05-21 19:24:23 +02:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$markup[] = hsprintf(
|
|
|
|
'<div class="%s">'.
|
|
|
|
'<div class="aphront-calendar-date-number">%s</div>'.
|
|
|
|
'%s%s'.
|
|
|
|
'</div>',
|
|
|
|
$class,
|
|
|
|
$day_number,
|
|
|
|
$holiday_markup,
|
|
|
|
phutil_implode_html("\n", $show_events));
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = array();
|
|
|
|
$rows = array_chunk($markup, 7);
|
|
|
|
foreach ($rows as $row) {
|
2013-02-13 23:50:15 +01:00
|
|
|
$table[] = hsprintf('<tr>');
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
while (count($row) < 7) {
|
2012-05-21 19:24:23 +02:00
|
|
|
$row[] = $empty_box;
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|
|
|
|
foreach ($row as $cell) {
|
2013-02-15 17:14:31 +01:00
|
|
|
$table[] = phutil_tag('td', array(), $cell);
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|
2013-02-13 23:50:15 +01:00
|
|
|
$table[] = hsprintf('</tr>');
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|
2013-02-13 23:50:15 +01:00
|
|
|
$table = hsprintf(
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
'<table class="aphront-calendar-view">'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'%s'.
|
2012-10-24 22:22:24 +02:00
|
|
|
'<tr class="aphront-calendar-day-of-week-header">'.
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
'<th>Sun</th>'.
|
|
|
|
'<th>Mon</th>'.
|
|
|
|
'<th>Tue</th>'.
|
|
|
|
'<th>Wed</th>'.
|
|
|
|
'<th>Thu</th>'.
|
|
|
|
'<th>Fri</th>'.
|
|
|
|
'<th>Sat</th>'.
|
|
|
|
'</tr>'.
|
2013-02-13 23:50:15 +01:00
|
|
|
'%s'.
|
|
|
|
'</table>',
|
|
|
|
$this->renderCalendarHeader($first),
|
|
|
|
phutil_implode_html("\n", $table));
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
2012-10-24 22:22:24 +02:00
|
|
|
private function renderCalendarHeader(DateTime $date) {
|
|
|
|
$colspan = 7;
|
|
|
|
$left_th = '';
|
|
|
|
$right_th = '';
|
|
|
|
|
|
|
|
// check for a browseURI, which means we need "fancy" prev / next UI
|
|
|
|
$uri = $this->getBrowseURI();
|
|
|
|
if ($uri) {
|
|
|
|
$colspan = 5;
|
|
|
|
$uri = new PhutilURI($uri);
|
|
|
|
list($prev_year, $prev_month) = $this->getPrevYearAndMonth();
|
|
|
|
$query = array('year' => $prev_year, 'month' => $prev_month);
|
2013-01-18 03:57:09 +01:00
|
|
|
$prev_link = phutil_tag(
|
2012-10-24 22:22:24 +02:00
|
|
|
'a',
|
|
|
|
array('href' => (string) $uri->setQueryParams($query)),
|
2013-02-19 22:33:10 +01:00
|
|
|
"\xE2\x86\x90");
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
list($next_year, $next_month) = $this->getNextYearAndMonth();
|
|
|
|
$query = array('year' => $next_year, 'month' => $next_month);
|
2013-01-18 03:57:09 +01:00
|
|
|
$next_link = phutil_tag(
|
2012-10-24 22:22:24 +02:00
|
|
|
'a',
|
|
|
|
array('href' => (string) $uri->setQueryParams($query)),
|
2013-02-19 22:33:10 +01:00
|
|
|
"\xE2\x86\x92");
|
2012-10-24 22:22:24 +02:00
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$left_th = phutil_tag('th', array(), $prev_link);
|
|
|
|
$right_th = phutil_tag('th', array(), $next_link);
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
return hsprintf(
|
|
|
|
'<tr class="aphront-calendar-month-year-header">%s%s%s</tr>',
|
|
|
|
$left_th,
|
|
|
|
phutil_tag('th', array('colspan' => $colspan), $date->format('F Y')),
|
|
|
|
$right_th);
|
2012-10-24 22:22:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getNextYearAndMonth() {
|
|
|
|
$month = $this->month;
|
|
|
|
$year = $this->year;
|
|
|
|
|
|
|
|
$next_year = $year;
|
|
|
|
$next_month = $month + 1;
|
|
|
|
if ($next_month == 13) {
|
|
|
|
$next_year = $year + 1;
|
|
|
|
$next_month = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array($next_year, $next_month);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPrevYearAndMonth() {
|
|
|
|
$month = $this->month;
|
|
|
|
$year = $this->year;
|
|
|
|
|
|
|
|
$prev_year = $year;
|
|
|
|
$prev_month = $month - 1;
|
|
|
|
if ($prev_month == 0) {
|
|
|
|
$prev_year = $year - 1;
|
|
|
|
$prev_month = 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array($prev_year, $prev_month);
|
|
|
|
}
|
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
/**
|
|
|
|
* Return a DateTime object representing the first moment in each day in the
|
|
|
|
* month, according to the user's locale.
|
|
|
|
*
|
|
|
|
* @return list List of DateTimes, one for each day.
|
|
|
|
*/
|
|
|
|
private function getDatesInMonth() {
|
|
|
|
$user = $this->user;
|
|
|
|
|
|
|
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
|
|
|
|
|
|
|
$month = $this->month;
|
|
|
|
$year = $this->year;
|
|
|
|
|
2012-10-24 22:22:24 +02:00
|
|
|
// Get the year and month numbers of the following month, so we can
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
// determine when this month ends.
|
2012-10-24 22:22:24 +02:00
|
|
|
list($next_year, $next_month) = $this->getNextYearAndMonth();
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
|
|
|
|
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
|
|
|
|
$end_epoch = $end_date->format('U');
|
|
|
|
|
|
|
|
$days = array();
|
|
|
|
for ($day = 1; $day <= 31; $day++) {
|
|
|
|
$day_date = new DateTime("{$year}-{$month}-{$day}", $timezone);
|
|
|
|
$day_epoch = $day_date->format('U');
|
|
|
|
if ($day_epoch >= $end_epoch) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
$days[] = $day_date;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $days;
|
|
|
|
}
|
2012-05-21 19:24:23 +02:00
|
|
|
|
|
|
|
private function renderEvent(
|
|
|
|
AphrontCalendarEventView $event,
|
|
|
|
$epoch_start,
|
|
|
|
$epoch_end) {
|
|
|
|
|
|
|
|
$user = $this->user;
|
|
|
|
|
|
|
|
$event_start = $event->getEpochStart();
|
|
|
|
$event_end = $event->getEpochEnd();
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$when = array();
|
|
|
|
|
|
|
|
$classes[] = 'aphront-calendar-event';
|
|
|
|
if ($event_start < $epoch_start) {
|
|
|
|
$classes[] = 'aphront-calendar-event-continues-before';
|
|
|
|
$when[] = 'Started '.phabricator_datetime($event_start, $user);
|
|
|
|
} else {
|
|
|
|
$when[] = 'Starts at '.phabricator_time($event_start, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($event_end > $epoch_end) {
|
|
|
|
$classes[] = 'aphront-calendar-event-continues-after';
|
2012-05-21 20:59:12 +02:00
|
|
|
$when[] = 'Ends '.phabricator_datetime($event_end, $user);
|
2012-05-21 19:24:23 +02:00
|
|
|
} else {
|
|
|
|
$when[] = 'Ends at '.phabricator_time($event_end, $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
Javelin::initBehavior('phabricator-tooltips');
|
|
|
|
|
|
|
|
$info = $event->getName();
|
|
|
|
if ($event->getDescription()) {
|
|
|
|
$info .= "\n\n".$event->getDescription();
|
|
|
|
}
|
|
|
|
|
2012-11-12 22:28:45 +01:00
|
|
|
if ($user->getPHID() == $event->getUserPHID()) {
|
|
|
|
$tag = 'a';
|
|
|
|
$href = '/calendar/status/edit/'.$event->getEventID().'/';
|
|
|
|
} else {
|
|
|
|
$tag = 'div';
|
|
|
|
$href = null;
|
|
|
|
}
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$text_div = javelin_tag(
|
2012-11-12 22:28:45 +01:00
|
|
|
$tag,
|
2012-05-21 19:24:23 +02:00
|
|
|
array(
|
|
|
|
'sigil' => 'has-tooltip',
|
|
|
|
'meta' => array(
|
2012-11-12 22:28:45 +01:00
|
|
|
'tip' => $info."\n\n".implode("\n", $when),
|
|
|
|
'size' => 240,
|
2012-05-21 19:24:23 +02:00
|
|
|
),
|
|
|
|
'class' => 'aphront-calendar-event-text',
|
2012-11-12 22:28:45 +01:00
|
|
|
'href' => $href,
|
2012-05-21 19:24:23 +02:00
|
|
|
),
|
2013-01-25 21:57:17 +01:00
|
|
|
phutil_utf8_shorten($event->getName(), 32));
|
2012-05-21 19:24:23 +02:00
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
return javelin_tag(
|
2012-05-21 19:24:23 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
|
|
|
),
|
|
|
|
$text_div);
|
|
|
|
}
|
|
|
|
|
Build a basic calendar view
Summary:
This is a very small step toward building a Status and possibly an Oncall tool.
Build a calendar view which renders months.
Much of my hesitance to bang these tools out is that dealing with
dates/calendaring is basically horrible, so I'm trying to ease into it.
This calendar is locale-aware and all that jazz.
Test Plan:
- See:
https://secure.phabricator.com/file/view/PHID-FILE-c07a9c663a7d040d2529/
- Verified that months have the right number of days, today is the right day
of the week, months begin on the day after previous months end on, etc.
Reviewed By: aran
Reviewers: jungejason, tuomaspelkonen, aran
Commenters: cwbeck, jungejason
CC: blair, aran, epriestley, cwbeck, jungejason
Differential Revision: 791
2011-08-08 03:26:31 +02:00
|
|
|
}
|