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
|
|
|
|
|
2014-02-16 18:25:29 +01:00
|
|
|
final class PHUICalendarMonthView extends AphrontView {
|
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-04-29 21:15:38 +02:00
|
|
|
private $day;
|
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
|
|
|
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;
|
2014-02-24 19:04:23 +01:00
|
|
|
private $image;
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:04:23 +01:00
|
|
|
public function setImage($uri) {
|
|
|
|
$this->image = $uri;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-29 21:15:38 +02:00
|
|
|
public function __construct($month, $year, $day = null) {
|
|
|
|
$this->day = $day;
|
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
|
|
|
$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();
|
|
|
|
|
2014-02-16 18:25:29 +01:00
|
|
|
require_celerity_resource('phui-calendar-month-css');
|
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
|
|
|
|
|
|
|
$first = reset($days);
|
|
|
|
$empty = $first->format('w');
|
|
|
|
|
|
|
|
$markup = array();
|
|
|
|
|
2013-02-13 23:50:15 +01:00
|
|
|
$empty_box = phutil_tag(
|
|
|
|
'div',
|
2014-02-16 18:25:29 +01:00
|
|
|
array('class' => 'phui-calendar-day phui-calendar-empty'),
|
2013-02-13 23:50:15 +01:00
|
|
|
'');
|
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'));
|
2014-02-16 18:25:29 +01:00
|
|
|
$class = 'phui-calendar-day';
|
2012-05-03 09:21:47 +02:00
|
|
|
$weekday = $day->format('w');
|
2013-04-29 21:15:38 +02:00
|
|
|
|
|
|
|
if ($day_number == $this->day) {
|
2014-02-16 18:25:29 +01:00
|
|
|
$class .= ' phui-calendar-today';
|
2013-04-29 21:15:38 +02:00
|
|
|
}
|
|
|
|
|
2012-05-03 09:21:47 +02:00
|
|
|
if ($holiday || $weekday == 0 || $weekday == 6) {
|
2014-02-16 18:25:29 +01:00
|
|
|
$class .= ' phui-calendar-not-work-day';
|
2012-05-03 09:21:47 +02:00
|
|
|
}
|
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-11-11 18:23:23 +01:00
|
|
|
phutil_tag_div(
|
2014-02-16 18:25:29 +01:00
|
|
|
'phui-calendar-event phui-calendar-event-empty',
|
2013-11-11 18:23:23 +01:00
|
|
|
"\xC2\xA0")); //
|
2012-05-21 20:59:12 +02:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:04:23 +01:00
|
|
|
$list_events = array();
|
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) {
|
2014-02-24 19:04:23 +01:00
|
|
|
$list_events[] = $event;
|
2012-05-21 19:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:04:23 +01:00
|
|
|
$list = new PHUICalendarListView();
|
|
|
|
$list->setUser($this->user);
|
|
|
|
foreach ($list_events as $item) {
|
|
|
|
$list->addEvent($item);
|
|
|
|
}
|
|
|
|
|
2012-05-21 19:24:23 +02:00
|
|
|
$holiday_markup = null;
|
|
|
|
if ($holiday) {
|
2013-02-13 23:50:15 +01:00
|
|
|
$name = $holiday->getName();
|
|
|
|
$holiday_markup = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2014-02-16 18:25:29 +01:00
|
|
|
'class' => 'phui-calendar-holiday',
|
2013-02-13 23:50:15 +01:00
|
|
|
'title' => $name,
|
|
|
|
),
|
|
|
|
$name);
|
2012-05-21 19:24:23 +02:00
|
|
|
}
|
|
|
|
|
2013-11-11 18:23:23 +01:00
|
|
|
$markup[] = phutil_tag_div(
|
2013-02-13 23:50:15 +01:00
|
|
|
$class,
|
2013-11-11 18:23:23 +01:00
|
|
|
array(
|
2014-02-16 18:25:29 +01:00
|
|
|
phutil_tag_div('phui-calendar-date-number', $day_number),
|
2013-11-11 18:23:23 +01:00
|
|
|
$holiday_markup,
|
2014-02-24 19:04:23 +01:00
|
|
|
$list,
|
2013-11-11 18:23:23 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
$table = array();
|
|
|
|
$rows = array_chunk($markup, 7);
|
|
|
|
foreach ($rows as $row) {
|
2013-11-11 18:23:23 +01:00
|
|
|
$cells = 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
|
|
|
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
|
|
|
}
|
2014-02-16 18:25:29 +01:00
|
|
|
$j = 0;
|
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) {
|
2014-02-16 18:25:29 +01:00
|
|
|
if ($j == 0) {
|
|
|
|
$cells[] = phutil_tag(
|
|
|
|
'td',
|
|
|
|
array(
|
|
|
|
'class' => 'phui-calendar-month-weekstart'),
|
|
|
|
$cell);
|
|
|
|
} else {
|
|
|
|
$cells[] = phutil_tag('td', array(), $cell);
|
|
|
|
}
|
|
|
|
$j++;
|
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-11-11 18:23:23 +01:00
|
|
|
$table[] = phutil_tag('tr', array(), $cells);
|
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-11-11 18:23:23 +01:00
|
|
|
|
|
|
|
$header = phutil_tag(
|
|
|
|
'tr',
|
2014-02-16 18:25:29 +01:00
|
|
|
array('class' => 'phui-calendar-day-of-week-header'),
|
2013-11-11 18:23:23 +01:00
|
|
|
array(
|
|
|
|
phutil_tag('th', array(), pht('Sun')),
|
|
|
|
phutil_tag('th', array(), pht('Mon')),
|
|
|
|
phutil_tag('th', array(), pht('Tue')),
|
|
|
|
phutil_tag('th', array(), pht('Wed')),
|
|
|
|
phutil_tag('th', array(), pht('Thu')),
|
|
|
|
phutil_tag('th', array(), pht('Fri')),
|
|
|
|
phutil_tag('th', array(), pht('Sat')),
|
|
|
|
));
|
|
|
|
|
|
|
|
$table = phutil_tag(
|
|
|
|
'table',
|
2014-02-16 18:25:29 +01:00
|
|
|
array('class' => 'phui-calendar-view'),
|
2013-11-11 18:23:23 +01:00
|
|
|
array(
|
|
|
|
$header,
|
|
|
|
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
|
|
|
|
2014-02-16 18:25:29 +01:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($this->renderCalendarHeader($first))
|
|
|
|
->appendChild($table);
|
|
|
|
|
|
|
|
return $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-10-24 22:22:24 +02:00
|
|
|
private function renderCalendarHeader(DateTime $date) {
|
2014-02-16 18:25:29 +01:00
|
|
|
$button_bar = null;
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
// check for a browseURI, which means we need "fancy" prev / next UI
|
|
|
|
$uri = $this->getBrowseURI();
|
|
|
|
if ($uri) {
|
|
|
|
$uri = new PhutilURI($uri);
|
|
|
|
list($prev_year, $prev_month) = $this->getPrevYearAndMonth();
|
|
|
|
$query = array('year' => $prev_year, 'month' => $prev_month);
|
2014-02-16 18:25:29 +01:00
|
|
|
$prev_uri = (string) $uri->setQueryParams($query);
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
list($next_year, $next_month) = $this->getNextYearAndMonth();
|
|
|
|
$query = array('year' => $next_year, 'month' => $next_month);
|
2014-02-16 18:25:29 +01:00
|
|
|
$next_uri = (string) $uri->setQueryParams($query);
|
|
|
|
|
|
|
|
$button_bar = new PHUIButtonBarView();
|
|
|
|
|
|
|
|
$left_icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_BUTTONBAR)
|
|
|
|
->setSpriteIcon('chevron-left');
|
|
|
|
$left = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setColor(PHUIButtonView::GREY)
|
|
|
|
->setHref($prev_uri)
|
|
|
|
->setTitle(pht('Previous Month'))
|
|
|
|
->setIcon($left_icon);
|
|
|
|
|
|
|
|
$right_icon = id(new PHUIIconView())
|
|
|
|
->setSpriteSheet(PHUIIconView::SPRITE_BUTTONBAR)
|
|
|
|
->setSpriteIcon('chevron-right');
|
|
|
|
$right = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setColor(PHUIButtonView::GREY)
|
|
|
|
->setHref($next_uri)
|
|
|
|
->setTitle(pht('Next Month'))
|
|
|
|
->setIcon($right_icon);
|
|
|
|
|
|
|
|
$button_bar->addButton($left);
|
|
|
|
$button_bar->addButton($right);
|
2012-10-24 22:22:24 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-16 18:25:29 +01:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($date->format('F Y'));
|
|
|
|
|
|
|
|
if ($button_bar) {
|
|
|
|
$header->setButtonBar($button_bar);
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:04:23 +01:00
|
|
|
if ($this->image) {
|
|
|
|
$header->setImage($this->image);
|
|
|
|
}
|
|
|
|
|
2014-02-16 18:25:29 +01:00
|
|
|
return $header;
|
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
|
|
|
|
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
|
|
|
}
|