Skip to content

Commit

Permalink
Modern TWFY styling for calendar pages.
Browse files Browse the repository at this point in the history
www/docs/calendar/index.php now renders the calendar/index.php template
rather than including calendar_date.php the old fashioned way.

The .business-section__what-is-this class has become
.business-section__secondary__item, in a first step towards
standardising how vertical space is added to items in the sidebar.

Also take the opportunity to refactor different calendar display
functions together (one was not used anywhere).
  • Loading branch information
zarino authored and dracos committed Mar 11, 2021
1 parent de29d63 commit dfbeaa3
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 598 deletions.
166 changes: 97 additions & 69 deletions www/docs/calendar/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

include_once '../../includes/easyparliament/init.php';
include_once INCLUDESPATH . "easyparliament/recess.php";

$date = get_http_var('d');
if (!$date || !preg_match('#^\d\d\d\d-\d\d-\d\d$#', $date)) {
Expand Down Expand Up @@ -43,95 +44,122 @@ function calendar_summary() {
}

function calendar_date($date) {
global $DATA, $this_page;
global $DATA, $this_page, $hansardmajors;

$DATA->set_page_metadata($this_page, 'title', format_date($date, LONGERDATEFORMAT));

$db = new ParlDB();

$data = array();
$data = array(
'date' => $date,
);
$data['dates'] = MySociety\TheyWorkForYou\Utility\Calendar::fetchDate($date);

$data['majors'] = array();
$majors = array();
if ($this_page == 'calendar_past') {
$q = $db->query('SELECT DISTINCT major FROM hansard WHERE hdate = :date', array(
':date' => $date
));
foreach ($q as $row) {
$data['majors'][] = $row['major'];
$majors[] = $row['major'];
}
}

include_once INCLUDESPATH . 'easyparliament/templates/html/calendar_date.php';
}
$data['order'] = array(
['name'=>'Commons: Main Chamber', 'major'=>1, 'list'=>1],
['name'=>'Lords: Main Chamber', 'major'=>101, 'list'=>1],
['name'=>'Commons: Westminster Hall', 'major'=>2, 'list'=>1],
['name'=>'Commons: General Committees', 'major'=>6, 'list'=>1],
['name'=>'Commons: Select Committees', 'list'=>0],
['name'=>'Lords: Select Committees', 'list'=>0],
['name'=>'Lords: Grand Committees', 'list'=>1],
['name'=>'Joint Committees', 'list'=>1],
);
foreach ($data['order'] as &$chamber) {
if (in_array($chamber['major'] ?? 0, $majors)) {
$URL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$chamber['major']]['page_all']);
$URL->insert( array( 'd' => $date ) );
$chamber['url'] = $URL->generate();
}
}

# ---
$parent_page = $DATA->page_metadata($this_page, 'parent');

$data['title'] = $DATA->page_metadata($this_page, 'title');
$data['parent_title'] = $DATA->page_metadata($parent_page, 'title');

/*
function calendar_past_date($date) {
global $PAGE, $DATA, $this_page, $hansardmajors;
$data = sidebar_calendars($data);

$PAGE->set_hansard_headings(array('date'=>$date));
$URL = new \MySociety\TheyWorkForYou\Url($this_page);
$nextprevdata = array();
$template = 'calendar/index';
MySociety\TheyWorkForYou\Renderer::output($template, $data);
}

function sidebar_calendars($data) {
$db = new ParlDB;
$hdate = $db->query("SELECT MIN(hdate) AS hdate FROM hansard WHERE hdate > '$date'")->first()['hdate'];
if ($hdate != NULL) {
$URL->insert( array( 'd'=>$hdate ) );
$title = format_date($hdate, SHORTDATEFORMAT);
$nextprevdata['next'] = array (
'hdate' => $hdate,
'url' => $URL->generate(),
'body' => 'Next day',
'title' => $title
);
}
$hdate = $db->query("SELECT MAX(hdate) AS hdate FROM hansard WHERE hdate < '$date'")->first()['hdate'];
if ($hdate != NULL) {
$URL->insert( array( 'd'=>$hdate ) );
$title = format_date($hdate, SHORTDATEFORMAT);
$nextprevdata['prev'] = array (
'hdate' => $hdate,
'url' => $URL->generate(),
'body' => 'Previous day',
'title' => $title
);

$years = array();
$data['years'] = &$years;

$q = $db->query('SELECT MIN(event_date) AS min, MAX(event_date) AS max FROM future WHERE event_date >= NOW() AND deleted = 0')->first();
$min_future_date = $q['min'];
$max_future_date = $q['max'];
if (!$min_future_date || !$max_future_date) {
return $data;
}
# $year = substr($date, 0, 4);
# $URL = new \MySociety\TheyWorkForYou\Url($hansardmajors[1]['page_year']);
# $URL->insert(array('y'=>$year));
# $nextprevdata['up'] = array (
# 'body' => "All of $year",
# 'title' => '',
# 'url' => $URL->generate()
# );
$DATA->set_page_metadata($this_page, 'nextprev', $nextprevdata);
$PAGE->page_start();
$PAGE->stripe_start();
include_once INCLUDESPATH . 'easyparliament/recess.php';
$time = strtotime($date);
$dayofweek = date('w', $time);
$recess = recess_prettify(date('j', $time), date('n', $time), date('Y', $time), 1);
if ($recess[0]) {
print '<p>The Houses of Parliament are in their ' . $recess[0] . ' at this time.</p>';
} elseif ($dayofweek == 0 || $dayofweek == 6) {
print '<p>The Houses of Parliament do not meet at weekends.</p>';
} else {
$data = array(
'date' => $date
);
foreach (array_keys($hansardmajors) as $major) {
$URL = new \MySociety\TheyWorkForYou\Url($hansardmajors[$major]['page_all']);
$URL->insert(array('d'=>$date));
$data[$major] = array('listurl'=>$URL->generate());

list($firstyear, $firstmonth, $day) = explode('-', $min_future_date);
list($finalyear, $finalmonth, $day) = explode('-', $max_future_date);

$q = $db->query("SELECT DISTINCT(event_date) AS event_date FROM future
WHERE event_date >= :firstdate
AND event_date <= :finaldate
AND deleted = 0
ORDER BY event_date ASC
", array(
':firstdate' => $firstyear . '-' . $firstmonth . '-01',
':finaldate' => $finalyear . '-' . $finalmonth . '-31'
));

if ($q->rows() > 0) {
foreach ($q as $row) {
list($year, $month, $day) = explode('-', $row['event_date']);
$month = intval($month);
$years[$year][$month][] = intval($day);
}

// If nothing happened on one month we'll have fetched nothing for it.
// So now we need to fill in any gaps with blank months.

// We cycle through every year and month we're supposed to have fetched.
// If it doesn't have an array in $years, we create an empty one for that
// month.
for ($y = intval($firstyear); $y <= $finalyear; $y++) {

if (!isset($years[$y])) {
$years[$y] = array(1=>array(), 2=>array(), 3=>array(), 4=>array(), 5=>array(), 6=>array(), 7=>array(), 8=>array(), 9=>array(), 10=>array(), 11=>array(), 12=>array());
} else {
// This year is set. Check it has all the months...
$minmonth = $y == $firstyear ? $firstmonth : 1;
$maxmonth = $y == $finalyear ? $finalmonth : 12;
for ($m = intval($minmonth); $m <= $maxmonth; $m++) {
if (!isset($years[$y][$m])) {
$years[$y][$m] = array();
}
}
ksort($years[$y]);
}
}
major_summary($data);
}
$PAGE->stripe_end(array(
array (
'type' => 'nextprev'
),
));
$PAGE->page_end();

# Extra things calendar include needs
$data['info'] = [
'onday' => $data['date'],
];
$data['recess_major'] = 1; # good enough
$data['section'] = 'calendar';
$data['urls'] = [
'calendarday' => new \MySociety\TheyWorkForYou\Url('calendar_future'),
];

return $data;
}
*/
21 changes: 11 additions & 10 deletions www/docs/style/sass/pages/_business.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
}
}

.business-section__what-is-this {
.business-section__secondary__item {
h3 {
color: $colour_grey;
margin: 0;
Expand All @@ -114,6 +114,16 @@
}
}

.business-section__secondary__item + .business-section__secondary__item,
.business-section__secondary .calendar,
.business-section__secondary .minisurvey {
margin-top: 2em;

@media (min-height: 700px) {
margin-top: 3em;
}
}

.business-list {
@include unstyled-list();
margin: 0;
Expand Down Expand Up @@ -397,12 +407,3 @@ input.search-section__submit {
}
}
}

.calendar,
.minisurvey {
margin-top: 2em;

@media (min-height: 700px) {
margin-top: 3em;
}
}
137 changes: 0 additions & 137 deletions www/includes/easyparliament/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,143 +1113,6 @@ public function display_commentreportlist($data) {

}



public function display_calendar_month($month, $year, $dateArray, $page) {
// From http://www.zend.com/zend/trick/tricks-Oct-2002.php
// Adjusted for style, putting Monday first, and the URL of the page linked to.

// Used in templates/html/hansard_calendar.php

// $month and $year are integers.
// $dateArray is an array of dates that should be links in this month.
// $page is the name of the page the dates should link to.

// Create array containing abbreviations of days of week.
$daysOfWeek = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');

// What is the first day of the month in question?
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);

// How many days does this month contain?
$numberDays = date('t',$firstDayOfMonth);

// Retrieve some information about the first day of the
// month in question.
$dateComponents = getdate($firstDayOfMonth);

// What is the name of the month in question?
$monthName = $dateComponents['month'];

// If this calendar is for this current, real world, month
// we get the value of today, so we can highlight it.
$nowDateComponents = getdate();
if ($nowDateComponents['mon'] == $month && $nowDateComponents['year'] == $year) {
$toDay = $nowDateComponents['mday'];
} else {
$toDay = '';
}

// What is the index value (0-6) of the first day of the
// month in question.

// Adjusted to cope with the week starting on Monday.
$dayOfWeek = $dateComponents['wday'] - 1;

// Adjusted to cope with the week starting on Monday.
if ($dayOfWeek < 0) {
$dayOfWeek = 6;
}

// Create the table tag opener and day headers

$calendar = "\t\t\t\t<div class=\"calendar\">\n";
$calendar .= "\t\t\t\t<table border=\"0\">\n";
$calendar .= "\t\t\t\t<caption>$monthName $year</caption>\n";
$calendar .= "\t\t\t\t<thead>\n\t\t\t\t<tr>";

// Create the calendar headers

foreach ($daysOfWeek as $day) {
$calendar .= "<th>$day</th>";
}

// Create the rest of the calendar

// Initiate the day counter, starting with the 1st.

$currentDay = 1;

$calendar .= "</tr>\n\t\t\t\t</thead>\n\t\t\t\t<tbody>\n\t\t\t\t<tr>";

// The variable $dayOfWeek is used to
// ensure that the calendar
// display consists of exactly 7 columns.

if ($dayOfWeek > 0) {
$calendar .= "<td colspan=\"$dayOfWeek\">&nbsp;</td>";
}

$DAYURL = new \MySociety\TheyWorkForYou\Url($page);

while ($currentDay <= $numberDays) {

// Seventh column (Sunday) reached. Start a new row.

if ($dayOfWeek == 7) {

$dayOfWeek = 0;
$calendar .= "</tr>\n\t\t\t\t<tr>";
}


// Is this day actually Today in the real world?
// If so, higlight it.
if ($currentDay == $toDay) {
$calendar .= '<td class="on">';
} else {
$calendar .= '<td>';
}

// Is the $currentDay a member of $dateArray? If so,
// the day should be linked.
if (in_array($currentDay,$dateArray)) {

$date = sprintf("%04d-%02d-%02d", $year, $month, $currentDay);

$DAYURL->insert(array('d'=>$date));

$calendar .= "<a href=\"" . $DAYURL->generate() . "\">$currentDay</a></td>";

// $currentDay is not a member of $dateArray.

} else {

$calendar .= "$currentDay</td>";
}

// Increment counters

$currentDay++;
$dayOfWeek++;
}

// Complete the row of the last week in month, if necessary

if ($dayOfWeek != 7) {

$remainingDays = 7 - $dayOfWeek;
$calendar .= "<td colspan=\"$remainingDays\">&nbsp;</td>";
}


$calendar .= "</tr>\n\t\t\t\t</tbody>\n\t\t\t\t</table>\n\t\t\t\t</div> <!-- end calendar -->\n\n";

return $calendar;

}


public function display_table($data) {
/* Pass it data to be displayed in a <table> and it renders it
with stripes.
Expand Down
13 changes: 0 additions & 13 deletions www/includes/easyparliament/sidebars/calendar_box.php

This file was deleted.

Loading

0 comments on commit dfbeaa3

Please sign in to comment.