mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-03 16:09:17 +01: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:
parent
826e5405b6
commit
73c82e5a94
14 changed files with 211 additions and 4 deletions
7
resources/sql/patches/holidays.sql
Normal file
7
resources/sql/patches/holidays.sql
Normal 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;
|
78
scripts/calendar/import_us_holidays.php
Executable file
78
scripts/calendar/import_us_holidays.php
Executable 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);
|
||||
}
|
|
@ -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(
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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[] = '<div style="padding: 2em;">';
|
||||
$months[] = $month_view;
|
||||
$months[] = '</div>';
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
}
|
12
src/applications/calendar/storage/base/__init__.php
Normal file
12
src/applications/calendar/storage/base/__init__.php
Normal 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');
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
12
src/applications/calendar/storage/holiday/__init__.php
Normal file
12
src/applications/calendar/storage/holiday/__init__.php
Normal 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');
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* 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.
|
||||
|
@ -21,12 +21,19 @@ final class AphrontCalendarMonthView extends AphrontView {
|
|||
private $user;
|
||||
private $month;
|
||||
private $year;
|
||||
private $holidays = array();
|
||||
|
||||
public function setUser(PhabricatorUser $user) {
|
||||
$this->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[] =
|
||||
'<div class="aphront-calendar-day-of-month">'.
|
||||
'<div class="'.$class.'">'.
|
||||
$day->format('j').
|
||||
($holiday ? '<br />'.phutil_escape_html($holiday->getName()) : '').
|
||||
'</div>';
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,3 +39,7 @@ table.aphront-calendar-view td div {
|
|||
text-align: right;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.aphront-calendar-not-work-day {
|
||||
background-color: #fdfae7;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue