1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 01:08:50 +02:00

Display holidays

Summary:
We will need it for two purposes:

- Status tool.
- Nagging tool - @aran suggested using "3 business days" and I don't want it to fall on New Year's Eve or such.

I don't plan working on any interface for editing this as this kind of data should be always imported.

Test Plan:
`bin/storage upgrade`
`scripts/calendar/import_us_holidays.php`
/calendar/

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2375
This commit is contained in:
vrana 2012-05-03 00:21:47 -07:00
parent 826e5405b6
commit 73c82e5a94
14 changed files with 211 additions and 4 deletions

View file

@ -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;

View file

@ -0,0 +1,78 @@
#!/usr/bin/env php
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
$root = dirname(dirname(dirname(__FILE__)));
require_once $root.'/scripts/__init_script__.php';
// http://www.opm.gov/operating_status_schedules/fedhol/
$holidays = array(
'2012-01-02' => "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);
}

View file

@ -375,7 +375,7 @@ celerity_register_resource_map(array(
), ),
'aphront-calendar-view-css' => 'aphront-calendar-view-css' =>
array( array(
'uri' => '/res/c86d9a4b/rsrc/css/aphront/calendar-view.css', 'uri' => '/res/57b017ec/rsrc/css/aphront/calendar-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(

View file

@ -529,6 +529,8 @@ phutil_register_library_map(array(
'PhabricatorBuiltinPatchList' => 'infrastructure/setup/sql/phabricator', 'PhabricatorBuiltinPatchList' => 'infrastructure/setup/sql/phabricator',
'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/browse', 'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/browse',
'PhabricatorCalendarController' => 'applications/calendar/controller/base', 'PhabricatorCalendarController' => 'applications/calendar/controller/base',
'PhabricatorCalendarDAO' => 'applications/calendar/storage/base',
'PhabricatorCalendarHoliday' => 'applications/calendar/storage/holiday',
'PhabricatorChangesetResponse' => 'infrastructure/diff/response', 'PhabricatorChangesetResponse' => 'infrastructure/diff/response',
'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/channellist', 'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/channellist',
'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/channellog', 'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/channellog',
@ -1461,6 +1463,8 @@ phutil_register_library_map(array(
'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList',
'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController',
'PhabricatorCalendarController' => 'PhabricatorController', 'PhabricatorCalendarController' => 'PhabricatorController',
'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO',
'PhabricatorCalendarHoliday' => 'PhabricatorCalendarDAO',
'PhabricatorChangesetResponse' => 'AphrontProxyResponse', 'PhabricatorChangesetResponse' => 'AphrontProxyResponse',
'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController',
'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController',

View file

@ -22,11 +22,18 @@ final class PhabricatorCalendarBrowseController
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
$year = idate('Y');
$holidays = id(new PhabricatorCalendarHoliday())->loadAllWhere(
'day BETWEEN %s AND %s',
"{$year}-01-01",
"{$year}-12-31");
$months = array(); $months = array();
for ($ii = 1; $ii <= 12; $ii++) { for ($ii = 1; $ii <= 12; $ii++) {
$month_view = new AphrontCalendarMonthView($ii, 2011); $month_view = new AphrontCalendarMonthView($ii, $year);
$month_view->setUser($user); $month_view->setUser($user);
$month_view->setHolidays($holidays);
$months[] = '<div style="padding: 2em;">'; $months[] = '<div style="padding: 2em;">';
$months[] = $month_view; $months[] = $month_view;
$months[] = '</div>'; $months[] = '</div>';

View file

@ -7,7 +7,10 @@
phutil_require_module('phabricator', 'applications/calendar/controller/base'); 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('phabricator', 'applications/calendar/view/month');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorCalendarBrowseController.php'); phutil_require_source('PhabricatorCalendarBrowseController.php');

View file

@ -0,0 +1,25 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class PhabricatorCalendarDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'calendar';
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/base/storage/lisk');
phutil_require_source('PhabricatorCalendarDAO.php');

View file

@ -0,0 +1,30 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PhabricatorCalendarHoliday extends PhabricatorCalendarDAO {
protected $day;
protected $name;
public function getConfiguration() {
return array(
self::CONFIG_TIMESTAMPS => false,
) + parent::getConfiguration();
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/calendar/storage/base');
phutil_require_source('PhabricatorCalendarHoliday.php');

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,12 +21,19 @@ final class AphrontCalendarMonthView extends AphrontView {
private $user; private $user;
private $month; private $month;
private $year; private $year;
private $holidays = array();
public function setUser(PhabricatorUser $user) { public function setUser(PhabricatorUser $user) {
$this->user = $user; $this->user = $user;
return $this; 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) { public function __construct($month, $year) {
$this->month = $month; $this->month = $month;
$this->year = $year; $this->year = $year;
@ -51,9 +58,16 @@ final class AphrontCalendarMonthView extends AphrontView {
} }
foreach ($days as $day) { 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[] = $markup[] =
'<div class="aphront-calendar-day-of-month">'. '<div class="'.$class.'">'.
$day->format('j'). $day->format('j').
($holiday ? '<br />'.phutil_escape_html($holiday->getName()) : '').
'</div>'; '</div>';
} }

View file

@ -9,5 +9,8 @@
phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'view/base'); phutil_require_module('phabricator', 'view/base');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('AphrontCalendarMonthView.php'); phutil_require_source('AphrontCalendarMonthView.php');

View file

@ -39,6 +39,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'name' => 'audit', 'name' => 'audit',
'after' => array( /* First Patch */ ), 'after' => array( /* First Patch */ ),
), ),
'db.calendar' => array(
'type' => 'db',
'name' => 'calendar',
),
'db.chatlog' => array( 'db.chatlog' => array(
'type' => 'db', 'type' => 'db',
'name' => 'chatlog', 'name' => 'chatlog',
@ -847,6 +851,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'name' => $this->getPatchPath('137.auditmetadata.sql'), 'name' => $this->getPatchPath('137.auditmetadata.sql'),
'legacy' => 137, 'legacy' => 137,
), ),
'holidays.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('holidays.sql'),
),
); );
} }

View file

@ -39,3 +39,7 @@ table.aphront-calendar-view td div {
text-align: right; text-align: right;
color: #666666; color: #666666;
} }
.aphront-calendar-not-work-day {
background-color: #fdfae7;
}