forked from HPR/hpr_generator
Fixing days to next free slot
templates/queries-index-mysql.tpl.html, templates/queries-index-sqlite.tpl.html: Enhanced the query that finds the next free slot (query_next_available_episode). Also made it compute the days to the slot from the current day. The query returns data for calling Date::Calc to compute the number of days, but this calculation is no longer necessary. Next release will remove this. templates/content-index.tpl.html: The number of days to the next free slot is reported here. The original Date::Calc computation which did this is no longer needed and has been removed since the query (query_next_available_episode) does it.
This commit is contained in:
@@ -1,58 +1,73 @@
|
||||
<!--% query_next_available_episode = '
|
||||
WITH next_id AS (
|
||||
SELECT id, id + 1 AS \'id_next\', date as \'last_date\'
|
||||
FROM eps
|
||||
WHERE eps.date > NOW()
|
||||
)
|
||||
SELECT
|
||||
MIN(next_id.id_next) AS \'next_id\',
|
||||
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%Y\') AS \'last_year\',
|
||||
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%d\') AS \'last_day\',
|
||||
DATE_FORMAT(DATE_ADD(MIN(last_date), INTERVAL 1 DAY), \'%m\') AS \'last_month\'
|
||||
FROM next_id
|
||||
LEFT JOIN eps ON next_id.id_next = eps.id
|
||||
WHERE eps.id IS NULL
|
||||
WITH next_id AS (
|
||||
SELECT id, id + 1 AS id_next, date as last_date
|
||||
FROM eps
|
||||
WHERE eps.date > NOW()
|
||||
),
|
||||
free_slot AS (
|
||||
SELECT
|
||||
last_date AS prev_date,
|
||||
CASE
|
||||
WHEN DAYOFWEEK(last_date) = 6
|
||||
THEN 3
|
||||
ELSE 1
|
||||
END AS date_offset,
|
||||
next_id.id_next AS empty_slot
|
||||
FROM next_id
|
||||
LEFT JOIN eps ON next_id.id_next = eps.id
|
||||
WHERE eps.id IS NULL
|
||||
ORDER BY next_id.id
|
||||
LIMIT 1
|
||||
)
|
||||
SELECT
|
||||
empty_slot AS next_id,
|
||||
ADDDATE(prev_date,date_offset) AS next_date,
|
||||
YEAR(ADDDATE(prev_date,date_offset)) AS last_year,
|
||||
MONTH(ADDDATE(prev_date,date_offset)) AS last_month,
|
||||
DAY(ADDDATE(prev_date,date_offset)) AS last_day,
|
||||
DATEDIFF(ADDDATE(prev_date,date_offset),NOW()) AS delta_days
|
||||
FROM free_slot
|
||||
'
|
||||
%-->
|
||||
<!--% query_latest_episodes = '
|
||||
WITH comment_tallies AS (
|
||||
SELECT
|
||||
WITH comment_tallies AS (
|
||||
SELECT
|
||||
eps_id,
|
||||
COUNT(eps_id) AS eps_tally
|
||||
FROM comments
|
||||
GROUP BY eps_id
|
||||
GROUP BY eps_id
|
||||
)
|
||||
SELECT
|
||||
eps.id,
|
||||
eps.explicit,
|
||||
eps.date, eps.license, eps.duration,
|
||||
eps.title, eps.summary, eps.tags,
|
||||
SELECT
|
||||
eps.id,
|
||||
eps.explicit,
|
||||
eps.date, eps.license, eps.duration,
|
||||
eps.title, eps.summary, eps.tags,
|
||||
eps.notes,
|
||||
hosts.local_image,
|
||||
hosts.hostid,
|
||||
hosts.hostid,
|
||||
hosts.host, hosts.email,
|
||||
miniseries.name AS series, miniseries.id AS seriesid,
|
||||
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
|
||||
FROM eps
|
||||
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
|
||||
FROM eps
|
||||
INNER JOIN hosts ON eps.hostid = hosts.hostid
|
||||
INNER JOIN miniseries ON eps.series = miniseries.id
|
||||
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
|
||||
WHERE eps.date <= UTC_DATE()
|
||||
ORDER BY eps.id DESC
|
||||
ORDER BY eps.id DESC
|
||||
LIMIT 10
|
||||
'
|
||||
%-->
|
||||
<!--% query_last_5_weeks_episodes = '
|
||||
SELECT
|
||||
eps.id,
|
||||
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
|
||||
eps.date, eps.license, eps.title, eps.summary,
|
||||
SELECT
|
||||
eps.id,
|
||||
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
|
||||
eps.date, eps.license, eps.title, eps.summary,
|
||||
eps.duration, eps.notes, eps.tags,
|
||||
hosts.hostid,
|
||||
hosts.host, hosts.email, hosts.local_image,
|
||||
hosts.hostid,
|
||||
hosts.host, hosts.email, hosts.local_image,
|
||||
miniseries.name AS series, miniseries.id AS seriesid
|
||||
FROM eps
|
||||
INNER JOIN hosts ON eps.hostid = hosts.hostid
|
||||
FROM eps
|
||||
INNER JOIN hosts ON eps.hostid = hosts.hostid
|
||||
INNER JOIN miniseries ON eps.series = miniseries.id
|
||||
WHERE eps.date <= UTC_DATE()
|
||||
ORDER BY eps.id DESC
|
||||
|
Reference in New Issue
Block a user