diff --git a/resources/sql/patches/holidays.sql b/resources/sql/patches/holidays.sql new file mode 100644 index 0000000000..0d250d61ad --- /dev/null +++ b/resources/sql/patches/holidays.sql @@ -0,0 +1,7 @@ +CREATE TABLE {$NAMESPACE}_calendar.calendar_holiday ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `day` date NOT NULL, + `name` varchar(50) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE `day` (`day`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/scripts/calendar/import_us_holidays.php b/scripts/calendar/import_us_holidays.php new file mode 100755 index 0000000000..d69367f6ac --- /dev/null +++ b/scripts/calendar/import_us_holidays.php @@ -0,0 +1,78 @@ +#!/usr/bin/env php + "New Year's Day", + '2012-01-16' => "Birthday of Martin Luther King, Jr.", + '2012-02-20' => "Washington's Birthday", + '2012-05-28' => "Memorial Day", + '2012-07-04' => "Independence Day", + '2012-09-03' => "Labor Day", + '2012-10-08' => "Columbus Day", + '2012-11-12' => "Veterans Day", + '2012-11-22' => "Thanksgiving Day", + '2012-12-25' => "Christmas Day", + '2013-01-01' => "New Year's Day", + '2013-01-21' => "Birthday of Martin Luther King, Jr.", + '2013-02-18' => "Washington's Birthday", + '2013-05-27' => "Memorial Day", + '2013-07-04' => "Independence Day", + '2013-09-02' => "Labor Day", + '2013-10-14' => "Columbus Day", + '2013-11-11' => "Veterans Day", + '2013-11-28' => "Thanksgiving Day", + '2013-12-25' => "Christmas Day", + '2014-01-01' => "New Year's Day", + '2014-01-20' => "Birthday of Martin Luther King, Jr.", + '2014-02-17' => "Washington's Birthday", + '2014-05-26' => "Memorial Day", + '2014-07-04' => "Independence Day", + '2014-09-01' => "Labor Day", + '2014-10-13' => "Columbus Day", + '2014-11-11' => "Veterans Day", + '2014-11-27' => "Thanksgiving Day", + '2014-12-25' => "Christmas Day", + '2015-01-01' => "New Year's Day", + '2015-01-19' => "Birthday of Martin Luther King, Jr.", + '2015-02-16' => "Washington's Birthday", + '2015-05-25' => "Memorial Day", + '2015-07-03' => "Independence Day", + '2015-09-07' => "Labor Day", + '2015-10-12' => "Columbus Day", + '2015-11-11' => "Veterans Day", + '2015-11-26' => "Thanksgiving Day", + '2015-12-25' => "Christmas Day", +); + +$table = new PhabricatorCalendarHoliday(); +$conn_w = $table->establishConnection('w'); +$table_name = $table->getTableName(); + +foreach ($holidays as $day => $name) { + queryfx( + $conn_w, + 'INSERT IGNORE INTO %T (day, name) VALUES (%s, %s)', + $table_name, + $day, + $name); +} diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 935f52926f..d9d792a0f2 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -375,7 +375,7 @@ celerity_register_resource_map(array( ), 'aphront-calendar-view-css' => array( - 'uri' => '/res/c86d9a4b/rsrc/css/aphront/calendar-view.css', + 'uri' => '/res/57b017ec/rsrc/css/aphront/calendar-view.css', 'type' => 'css', 'requires' => array( diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 52f8772e47..828ec80ad2 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -529,6 +529,8 @@ phutil_register_library_map(array( 'PhabricatorBuiltinPatchList' => 'infrastructure/setup/sql/phabricator', 'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/browse', 'PhabricatorCalendarController' => 'applications/calendar/controller/base', + 'PhabricatorCalendarDAO' => 'applications/calendar/storage/base', + 'PhabricatorCalendarHoliday' => 'applications/calendar/storage/holiday', 'PhabricatorChangesetResponse' => 'infrastructure/diff/response', 'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/channellist', 'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/channellog', @@ -1461,6 +1463,8 @@ phutil_register_library_map(array( 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', 'PhabricatorCalendarController' => 'PhabricatorController', + 'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO', + 'PhabricatorCalendarHoliday' => 'PhabricatorCalendarDAO', 'PhabricatorChangesetResponse' => 'AphrontProxyResponse', 'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController', diff --git a/src/applications/calendar/controller/browse/PhabricatorCalendarBrowseController.php b/src/applications/calendar/controller/browse/PhabricatorCalendarBrowseController.php index dd8b97cccf..b6edb1b264 100644 --- a/src/applications/calendar/controller/browse/PhabricatorCalendarBrowseController.php +++ b/src/applications/calendar/controller/browse/PhabricatorCalendarBrowseController.php @@ -22,11 +22,18 @@ final class PhabricatorCalendarBrowseController public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); + $year = idate('Y'); + + $holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere( + 'day BETWEEN %s AND %s', + "{$year}-01-01", + "{$year}-12-31"); $months = array(); for ($ii = 1; $ii <= 12; $ii++) { - $month_view = new AphrontCalendarMonthView($ii, 2011); + $month_view = new AphrontCalendarMonthView($ii, $year); $month_view->setUser($user); + $month_view->setHolidays($holidays); $months[] = '
'; $months[] = $month_view; $months[] = '
'; diff --git a/src/applications/calendar/controller/browse/__init__.php b/src/applications/calendar/controller/browse/__init__.php index f6ed2aa4fa..f8d3f23799 100644 --- a/src/applications/calendar/controller/browse/__init__.php +++ b/src/applications/calendar/controller/browse/__init__.php @@ -7,7 +7,10 @@ phutil_require_module('phabricator', 'applications/calendar/controller/base'); +phutil_require_module('phabricator', 'applications/calendar/storage/holiday'); phutil_require_module('phabricator', 'applications/calendar/view/month'); +phutil_require_module('phutil', 'utils'); + phutil_require_source('PhabricatorCalendarBrowseController.php'); diff --git a/src/applications/calendar/storage/base/PhabricatorCalendarDAO.php b/src/applications/calendar/storage/base/PhabricatorCalendarDAO.php new file mode 100644 index 0000000000..800ff0ccbe --- /dev/null +++ b/src/applications/calendar/storage/base/PhabricatorCalendarDAO.php @@ -0,0 +1,25 @@ + false, + ) + parent::getConfiguration(); + } + +} diff --git a/src/applications/calendar/storage/holiday/__init__.php b/src/applications/calendar/storage/holiday/__init__.php new file mode 100644 index 0000000000..c5c4a005c2 --- /dev/null +++ b/src/applications/calendar/storage/holiday/__init__.php @@ -0,0 +1,12 @@ +user = $user; return $this; } + public function setHolidays(array $holidays) { + assert_instances_of($holidays, 'PhabricatorCalendarHoliday'); + $this->holidays = mpull($holidays, null, 'getDay'); + return $this; + } + public function __construct($month, $year) { $this->month = $month; $this->year = $year; @@ -51,9 +58,16 @@ final class AphrontCalendarMonthView extends AphrontView { } foreach ($days as $day) { + $holiday = idx($this->holidays, $day->format('Y-m-d')); + $class = 'aphront-calendar-day-of-month'; + $weekday = $day->format('w'); + if ($holiday || $weekday == 0 || $weekday == 6) { + $class .= ' aphront-calendar-not-work-day'; + } $markup[] = - '
'. + '
'. $day->format('j'). + ($holiday ? '
'.phutil_escape_html($holiday->getName()) : ''). '
'; } diff --git a/src/applications/calendar/view/month/__init__.php b/src/applications/calendar/view/month/__init__.php index 9cc72509a9..10d4ea1bae 100644 --- a/src/applications/calendar/view/month/__init__.php +++ b/src/applications/calendar/view/month/__init__.php @@ -9,5 +9,8 @@ phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'view/base'); +phutil_require_module('phutil', 'markup'); +phutil_require_module('phutil', 'utils'); + phutil_require_source('AphrontCalendarMonthView.php'); diff --git a/src/infrastructure/setup/sql/phabricator/PhabricatorBuiltinPatchList.php b/src/infrastructure/setup/sql/phabricator/PhabricatorBuiltinPatchList.php index c5517c2a71..485acee7f5 100644 --- a/src/infrastructure/setup/sql/phabricator/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/setup/sql/phabricator/PhabricatorBuiltinPatchList.php @@ -39,6 +39,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'name' => 'audit', 'after' => array( /* First Patch */ ), ), + 'db.calendar' => array( + 'type' => 'db', + 'name' => 'calendar', + ), 'db.chatlog' => array( 'type' => 'db', 'name' => 'chatlog', @@ -847,6 +851,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'name' => $this->getPatchPath('137.auditmetadata.sql'), 'legacy' => 137, ), + 'holidays.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('holidays.sql'), + ), ); } diff --git a/webroot/rsrc/css/aphront/calendar-view.css b/webroot/rsrc/css/aphront/calendar-view.css index fd387fc1a9..8eb7ae781b 100644 --- a/webroot/rsrc/css/aphront/calendar-view.css +++ b/webroot/rsrc/css/aphront/calendar-view.css @@ -39,3 +39,7 @@ table.aphront-calendar-view td div { text-align: right; color: #666666; } + +.aphront-calendar-not-work-day { + background-color: #fdfae7; +}