Skip to content

Commit

Permalink
Expand on IN_SESSION constant
Browse files Browse the repository at this point in the history
We were misusing this to mean "is stuff happening?" So this is now broken out into IN_SESSION and LEGISLATIVE_SEASON, with IN_SESSION meaning "is this within the dates of the actual session," and LEGISLATIVE_SEASON meaning "is it between November and April"?
  • Loading branch information
waldoj committed Jan 8, 2024
1 parent c3cd617 commit 0f83ac2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 7 deletions.
7 changes: 5 additions & 2 deletions deploy/settings-docker.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
# As defined by the year.
define('SESSION_YEAR', 2019);

# Determine whether the GA is currently in session.
define('IN_SESSION', 'Y');
# Is the GA currently in session?
define('IN_SESSION', true);

# Is it a time of year when the legislature is doing anything at all?
define('LEGISLATIVE_SEASON', true);

# Set the FTP auth pair for legislative data.
define('LIS_FTP_USERNAME', '');
Expand Down
2 changes: 1 addition & 1 deletion htdocs/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
}

# Select the most popular bills of the past X days.
if (IN_SESSION == 'Y')
if (LEGISLATIVE_SEASON == true)
{
$days = 3;
}
Expand Down
86 changes: 86 additions & 0 deletions htdocs/includes/class.Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* Session Class
*
* This class is responsible for handling session-related operations, primarily
* focused on determining the status of a session based on database records.
*/
class Session
{
/**
* Retrieves the current session's status.
*
* This method queries the database to retrieve information about the current
* session based on a predefined SESSION_ID. It then evaluates whether the
* current time falls within the session's start and end dates, and whether
* the current month is within the legislative season (November to April).
*
* @return array An associative array containing the session status with keys
* 'in_session' (boolean) indicating if the current time is within
* the session period, and 'in_season' (boolean) indicating if
* it is the legislative season.
*
* @throws Exception If there is a database connection or execution error.
*/
public function status()
{

$sql = 'SELECT *
FROM sessions
WHERE
id= :id';

$stmt = $GLOBALS['dbh']->prepare($sql);
$stmt->bindParam(':id', SESSION_ID);

$stmt->execute();
$session = $stmt->fetch(PDO::FETCH_ASSOC);

if ($session == false)
{
unset($session);
$session=array();
$session['in_session'] = false;
$session['in_season'] = false;
return false;
}

$session = array_map('stripslashes', $session);

/*
* If we're in the midst of session
*/
if (
time() >= strtotime($session['date_started'])
&&
time() <= strtotime($session['date_ended'])
)
{
$session['in_session'] = true;
$session['in_season'] = true;
}

/*
* If it's legislative season, but not session
*/
elseif (date('n') >= 11 || date('n') <= 4)
{
$session['in_session'] = false;
$session['in_season'] = true;
}

/*
* It's the off season
*/
else
{
$session['in_session'] = false;
$session['in_season'] = false;
}

return $session;

}

}
15 changes: 12 additions & 3 deletions htdocs/includes/settings-default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
# As defined by the year.
define('SESSION_YEAR', 2024);

# Determine whether the GA is currently in session.
define('IN_SESSION', 'Y');

# Set the FTP auth pair for legislative data.
define('LIS_FTP_USERNAME', '');
define('LIS_FTP_PASSWORD', '');
Expand Down Expand Up @@ -98,3 +95,15 @@

# Set the timezone.
date_default_timezone_set('America/New_York');

/*
* Generate status constants dynamically.
*/
$session = new Session;
$status = $session->status();

# Is the GA currently in session?
define('IN_SESSION', $status['in_session']);

# Is it a time of year when the legislature is doing anything at all?
define('LEGISLATIVE_SEASON', $status['in_season]);
2 changes: 1 addition & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
}

# Newest Bills
if (IN_SESSION == 'y')
if (LEGISLATIVE_SEASON == true)
{
$sql = 'SELECT bills.number, bills.catch_line, sessions.year,
DATE_FORMAT(bills.date_introduced, "%M %d, %Y") AS date_introduced,
Expand Down

0 comments on commit 0f83ac2

Please sign in to comment.