2012-05-09 01:31:56 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Model_LiveLog
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function GetLiveShowDuration($p_keepData = false)
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2012-05-09 01:31:56 +02:00
|
|
|
try {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT * FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE state = :state'
|
|
|
|
. " and (start_time >= (now() - INTERVAL '1 day'))"
|
|
|
|
. ' ORDER BY id';
|
2021-10-11 16:10:47 +02:00
|
|
|
$rows = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':state' => 'L'],
|
|
|
|
Application_Common_Database::ALL
|
|
|
|
);
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-05-10 19:18:38 +02:00
|
|
|
/* Check if last log has end time.
|
|
|
|
* If not, set end time to current time
|
|
|
|
*/
|
|
|
|
if ($rows != null) {
|
2012-05-11 20:50:38 +02:00
|
|
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
2012-05-10 19:18:38 +02:00
|
|
|
array_push($rows, $last_row);
|
2012-06-19 22:59:59 +02:00
|
|
|
$skip = false;
|
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT * FROM CC_LIVE_LOG'
|
|
|
|
. ' WHERE state = :state'
|
|
|
|
. ' ORDER BY id';
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':state' => 'L'],
|
|
|
|
Application_Common_Database::ALL
|
|
|
|
);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if ($rows != null) {
|
|
|
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
|
|
|
array_push($rows, $last_row);
|
|
|
|
foreach ($rows as $row) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_delete = 'DELETE FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE id = :id';
|
2021-10-11 16:10:47 +02:00
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_delete,
|
|
|
|
[':id' => $row['id']],
|
|
|
|
Application_Common_Database::EXECUTE
|
|
|
|
);
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
$skip = true;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
|
|
|
$hours = 0;
|
|
|
|
$minutes = 0;
|
|
|
|
$seconds = 0;
|
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!$skip) {
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$end = new DateTime($row['end_time']);
|
|
|
|
$start = new DateTime($row['start_time']);
|
|
|
|
$duration = $start->diff($end);
|
2021-10-11 16:10:47 +02:00
|
|
|
$duration = $duration->format('%H:%i:%s');
|
|
|
|
$intervals = explode(':', $duration);
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
for ($i = 0; $i < count($intervals); ++$i) {
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!isset($intervals[$i])) {
|
|
|
|
$intervals[$i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
// Trim milliseconds (DateInterval does not support)
|
2021-10-11 16:10:47 +02:00
|
|
|
$sec = explode('.', $intervals[2]);
|
2012-06-19 22:59:59 +02:00
|
|
|
if (isset($sec[0])) {
|
|
|
|
$intervals[2] = $sec[0];
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$seconds += $intervals[2];
|
|
|
|
if ($seconds / 60 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
++$minutes;
|
2012-06-19 22:59:59 +02:00
|
|
|
$seconds -= 60;
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$minutes += $intervals[1];
|
|
|
|
if ($minutes / 60 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
++$hours;
|
2012-06-19 22:59:59 +02:00
|
|
|
$minutes -= 60;
|
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$hours += $intervals[0];
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!$p_keepData) {
|
|
|
|
// Delete data we just used to start a new log history
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_delete = 'DELETE FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE id = :id';
|
2021-10-11 16:10:47 +02:00
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_delete,
|
|
|
|
[':id' => $row['id']],
|
|
|
|
Application_Common_Database::EXECUTE
|
|
|
|
);
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
|
|
|
}
|
2022-03-14 11:15:04 +01:00
|
|
|
// Trim milliseconds
|
2021-10-11 16:10:47 +02:00
|
|
|
$seconds = explode('.', $seconds);
|
2012-06-19 22:59:59 +02:00
|
|
|
if (isset($seconds[0])) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$minutes = (float) (($hours * 60) + $minutes . '.' . $seconds[0]);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$minutes = (float) (($hours * 60) + $minutes);
|
2012-05-11 23:27:14 +02:00
|
|
|
}
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-05-11 23:27:14 +02:00
|
|
|
return $minutes;
|
2012-05-09 01:31:56 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
header('HTTP/1.0 503 Service Unavailable');
|
2021-10-11 16:10:47 +02:00
|
|
|
Logging::info('GetLiveShowDuration - Could not connect to database.');
|
|
|
|
|
2012-05-11 20:50:38 +02:00
|
|
|
exit;
|
|
|
|
}
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function GetScheduledDuration($p_keepData = false)
|
2012-05-11 23:27:14 +02:00
|
|
|
{
|
2012-05-09 01:31:56 +02:00
|
|
|
try {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_get_logs = 'SELECT * FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE state = :state'
|
|
|
|
. " and (start_time >= (now() - INTERVAL '1 day'))"
|
|
|
|
. ' ORDER BY id';
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_get_logs,
|
|
|
|
[':state' => 'S'],
|
|
|
|
Application_Common_Database::ALL
|
|
|
|
);
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-05-10 19:18:38 +02:00
|
|
|
/* Check if last log has end time.
|
|
|
|
* If not, set end time to current time
|
|
|
|
*/
|
|
|
|
if ($rows != null) {
|
2012-05-11 20:50:38 +02:00
|
|
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
2012-05-10 19:18:38 +02:00
|
|
|
array_push($rows, $last_row);
|
2012-06-19 22:59:59 +02:00
|
|
|
$skip = false;
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = 'SELECT * FROM CC_LIVE_LOG'
|
|
|
|
. ' WHERE state = :state'
|
|
|
|
. ' ORDER BY id';
|
|
|
|
$rows = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[':state' => 'S'],
|
|
|
|
Application_Common_Database::ALL
|
|
|
|
);
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if ($rows != null) {
|
|
|
|
$last_row = self::UpdateLastLogEndTime(array_pop($rows));
|
|
|
|
array_push($rows, $last_row);
|
|
|
|
foreach ($rows as $row) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_delete = 'DELETE FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE id = :id';
|
2021-10-11 16:10:47 +02:00
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_delete,
|
|
|
|
[':id' => $row['id']],
|
|
|
|
Application_Common_Database::EXECUTE
|
|
|
|
);
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
$skip = true;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
|
|
|
$hours = 0;
|
|
|
|
$minutes = 0;
|
|
|
|
$seconds = 0;
|
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!$skip) {
|
|
|
|
/* Get all shows and tracks from cc_schedule that played
|
|
|
|
* during a scheduled state
|
|
|
|
*/
|
|
|
|
foreach ($rows as $row) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_get_tracks = 'SELECT * FROM cc_schedule'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE starts >= :starts1'
|
|
|
|
. ' AND starts < :starts2'
|
|
|
|
. ' AND file_id IS NOT NULL'
|
|
|
|
. ' AND media_item_played IS TRUE';
|
2021-10-11 16:10:47 +02:00
|
|
|
$params = [
|
|
|
|
':starts1' => $row['start_time'],
|
|
|
|
':starts2' => $row['end_time'],
|
|
|
|
];
|
|
|
|
$tracks = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_get_tracks,
|
|
|
|
$params,
|
|
|
|
Application_Common_Database::ALL
|
2013-05-09 21:53:12 +02:00
|
|
|
);
|
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
foreach ($tracks as $track) {
|
|
|
|
if ($track['ends'] > $row['end_time']) {
|
|
|
|
$scheduled_ends = new DateTime($row['end_time']);
|
|
|
|
$track_ends = new DateTime($track['ends']);
|
|
|
|
$extra_time = $scheduled_ends->diff($track_ends);
|
|
|
|
|
|
|
|
/* Get difference between clip_length
|
|
|
|
* and the extra time. We need to subtract
|
|
|
|
* this difference from the track's
|
|
|
|
* clip length.
|
|
|
|
*/
|
|
|
|
$clip_length = $track['clip_length'];
|
2022-03-14 11:15:04 +01:00
|
|
|
// Convert clip_length into seconds
|
2021-10-11 16:10:47 +02:00
|
|
|
$clip_length_intervals = explode(':', $clip_length);
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
for ($i = 0; $i < count($clip_length_intervals); ++$i) {
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!isset($clip_length_intervals[$i])) {
|
|
|
|
$clip_length_intervals[$i] = 0;
|
|
|
|
}
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
$clip_length_seconds = $clip_length_intervals[0] * 3600 + $clip_length_intervals[1] * 60 + $clip_length_intervals[2];
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$extra_time = $extra_time->format('%H:%i:%s');
|
2022-03-14 11:15:04 +01:00
|
|
|
// Convert extra_time into seconds;
|
2021-10-11 16:10:47 +02:00
|
|
|
$extra_time_intervals = explode(':', $extra_time);
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
for ($i = 0; $i < count($extra_time_intervals); ++$i) {
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!isset($extra_time_intervals[$i])) {
|
|
|
|
$extra_time_intervals[$i] = 0;
|
|
|
|
}
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
$extra_time_seconds = $extra_time_intervals[0] * 3600 + $extra_time_intervals[1] * 60 + $extra_time_intervals[2];
|
2012-06-19 22:59:59 +02:00
|
|
|
|
|
|
|
$clip_length_seconds -= $extra_time_seconds;
|
2012-07-11 00:51:32 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// Convert new clip_length into "H-i-s" format
|
2021-10-11 16:10:47 +02:00
|
|
|
$clip_length_arr = [];
|
2012-06-19 22:59:59 +02:00
|
|
|
if ($clip_length_seconds / 3600 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
array_push($clip_length_arr, str_pad(floor($clip_length_seconds / 3600), 2, '0', STR_PAD_LEFT));
|
2012-06-19 22:59:59 +02:00
|
|
|
$clip_length_seconds -= floor($clip_length_seconds / 3600);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
array_push($clip_length_arr, '00');
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
|
|
|
if ($clip_length_seconds / 60 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
array_push($clip_length_arr, str_pad(floor($clip_length_seconds / 60), 2, '0', STR_PAD_LEFT));
|
2012-06-19 22:59:59 +02:00
|
|
|
$clip_length_seconds -= floor($clip_length_seconds / 60);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
array_push($clip_length_arr, '00');
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
array_push($clip_length_arr, str_pad($clip_length_seconds, 2, '0', STR_PAD_LEFT));
|
|
|
|
$clip_length = implode(':', $clip_length_arr);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2012-06-19 22:59:59 +02:00
|
|
|
$clip_length = $track['clip_length'];
|
2012-05-11 20:50:38 +02:00
|
|
|
}
|
2012-06-19 22:59:59 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$intervals = explode(':', $clip_length);
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
for ($i = 0; $i < count($intervals); ++$i) {
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!isset($intervals[$i])) {
|
|
|
|
$intervals[$i] = 0;
|
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
}
|
2012-06-19 22:59:59 +02:00
|
|
|
// Trim milliseconds (DateInteral does not support)
|
2021-10-11 16:10:47 +02:00
|
|
|
$sec = explode('.', $intervals[2]);
|
2012-06-19 22:59:59 +02:00
|
|
|
if (isset($sec[0])) {
|
|
|
|
$intervals[2] = $sec[0];
|
2012-05-11 20:50:38 +02:00
|
|
|
}
|
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$seconds += $intervals[2];
|
|
|
|
if ($seconds / 60 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
++$minutes;
|
2012-06-19 22:59:59 +02:00
|
|
|
$seconds -= 60;
|
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$minutes += $intervals[1];
|
|
|
|
if ($minutes / 60 >= 1) {
|
2021-10-11 16:10:47 +02:00
|
|
|
++$hours;
|
2012-06-19 22:59:59 +02:00
|
|
|
$minutes -= 60;
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
$hours += $intervals[0];
|
2012-05-11 20:50:38 +02:00
|
|
|
}
|
|
|
|
|
2012-06-19 22:59:59 +02:00
|
|
|
if (!$p_keepData) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// Delete row because we do not need data anymore
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_delete = 'DELETE FROM CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE id = :id';
|
2021-10-11 16:10:47 +02:00
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_delete,
|
|
|
|
[':id' => $row['id']],
|
|
|
|
Application_Common_Database::EXECUTE
|
|
|
|
);
|
2012-05-11 20:50:38 +02:00
|
|
|
}
|
2012-05-10 19:18:38 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$seconds = explode('.', $seconds);
|
2012-06-19 22:59:59 +02:00
|
|
|
if (isset($seconds[0])) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$minutes = (float) (($hours * 60) + $minutes . '.' . $seconds[0]);
|
2012-07-16 03:17:13 +02:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$minutes = (float) (($hours * 60) + $minutes);
|
2012-06-19 22:59:59 +02:00
|
|
|
}
|
2012-05-14 21:24:53 +02:00
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-05-11 23:27:14 +02:00
|
|
|
return $minutes;
|
2012-05-09 01:31:56 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
header('HTTP/1.0 503 Service Unavailable');
|
2021-10-11 16:10:47 +02:00
|
|
|
Logging::info('GetScheduledDuration - Could not connect to database.');
|
|
|
|
|
2012-05-11 20:50:38 +02:00
|
|
|
exit;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public static function UpdateLastLogEndTime($log)
|
|
|
|
{
|
2012-05-11 20:50:38 +02:00
|
|
|
if ($log['end_time'] == null) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$current_time = new DateTime('now', new DateTimeZone('UTC'));
|
2012-05-11 20:50:38 +02:00
|
|
|
$log['end_time'] = $current_time;
|
2015-06-26 20:42:52 +02:00
|
|
|
$log['end_time'] = $log['end_time']->format(DEFAULT_TIMESTAMP_FORMAT);
|
2012-05-11 20:50:38 +02:00
|
|
|
self::SetEndTime($log['state'], $current_time, true);
|
|
|
|
self::SetNewLogTime($log['state'], $current_time);
|
|
|
|
}
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-05-10 19:18:38 +02:00
|
|
|
return $log;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
public static function SetNewLogTime($state, $dateTime)
|
|
|
|
{
|
2012-05-09 01:31:56 +02:00
|
|
|
try {
|
2012-05-22 22:53:04 +02:00
|
|
|
$scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play');
|
|
|
|
if ($state == 'L' && $scheduled == 'on') {
|
2012-05-11 20:50:38 +02:00
|
|
|
self::SetEndTime('S', $dateTime);
|
2012-05-09 20:56:21 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-05-09 22:31:36 +02:00
|
|
|
/* Only insert new state if last log
|
|
|
|
* has ended
|
2012-05-09 20:56:21 +02:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_select = 'SELECT max(id) from CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' WHERE (state= :state1 and end_time is NULL) or (state= :state2 and end_time is NULL)';
|
2021-10-11 16:10:47 +02:00
|
|
|
$params = [
|
|
|
|
':state1' => 'L',
|
|
|
|
':state2' => 'S',
|
|
|
|
];
|
|
|
|
$id = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_select,
|
|
|
|
$params,
|
|
|
|
Application_Common_Database::COLUMN
|
2013-05-09 21:53:12 +02:00
|
|
|
);
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-05-09 20:56:21 +02:00
|
|
|
if ($id == null) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_insert = 'INSERT INTO CC_LIVE_LOG (state, start_time)'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' VALUES (:state, :start)';
|
2021-10-11 16:10:47 +02:00
|
|
|
$params = [
|
|
|
|
':state' => $state,
|
|
|
|
':start' => $dateTime->format(DEFAULT_TIMESTAMP_FORMAT),
|
|
|
|
];
|
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_insert,
|
|
|
|
$params,
|
|
|
|
Application_Common_Database::EXECUTE
|
2013-05-09 21:53:12 +02:00
|
|
|
);
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($state == 'S') {
|
2012-05-22 23:39:27 +02:00
|
|
|
// if scheduled play source is getting broadcasted
|
|
|
|
Application_Model_Schedule::UpdateBrodcastedStatus($dateTime, 1);
|
|
|
|
}
|
2012-05-09 20:56:21 +02:00
|
|
|
}
|
2012-05-09 01:31:56 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
header('HTTP/1.0 503 Service Unavailable');
|
2021-10-11 16:10:47 +02:00
|
|
|
Logging::info('SetNewLogTime - Could not connect to database.');
|
|
|
|
|
2012-05-11 20:50:38 +02:00
|
|
|
exit;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function SetEndTime($state, $dateTime, $override = false)
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
2012-05-09 01:31:56 +02:00
|
|
|
try {
|
2012-05-11 20:50:38 +02:00
|
|
|
$dj_live = Application_Model_Preference::GetSourceSwitchStatus('live_dj');
|
|
|
|
$master_live = Application_Model_Preference::GetSourceSwitchStatus('master_dj');
|
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
if (($dj_live == 'off' && $master_live == 'off') || $state == 'S' || $override) {
|
|
|
|
$sql = 'SELECT id, state from cc_live_log'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' where id in (select max(id) from cc_live_log)';
|
2021-10-11 16:10:47 +02:00
|
|
|
$row = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql,
|
|
|
|
[],
|
|
|
|
Application_Common_Database::SINGLE
|
|
|
|
);
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2012-05-09 22:31:36 +02:00
|
|
|
/* Only set end time if state recevied ($state)
|
|
|
|
* is the last row in cc_live_log
|
|
|
|
*/
|
|
|
|
if ($row['state'] == $state) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$update_sql = 'UPDATE CC_LIVE_LOG'
|
2022-07-07 20:01:15 +02:00
|
|
|
. ' SET end_time = :end'
|
|
|
|
. ' WHERE id = :id';
|
2021-10-11 16:10:47 +02:00
|
|
|
$params = [
|
|
|
|
':end' => $dateTime->format(DEFAULT_TIMESTAMP_FORMAT),
|
|
|
|
':id' => $row['id'],
|
|
|
|
];
|
|
|
|
Application_Common_Database::prepareAndExecute(
|
|
|
|
$update_sql,
|
|
|
|
$params,
|
|
|
|
Application_Common_Database::EXECUTE
|
2013-05-09 21:53:12 +02:00
|
|
|
);
|
2012-05-09 20:56:21 +02:00
|
|
|
}
|
2012-05-11 20:50:38 +02:00
|
|
|
|
2022-03-14 11:15:04 +01:00
|
|
|
// If live broadcasting is off, turn scheduled play on
|
2012-05-09 20:56:21 +02:00
|
|
|
$scheduled = Application_Model_Preference::GetSourceSwitchStatus('scheduled_play');
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($state == 'L' && $scheduled == 'on' && !$override) {
|
2012-05-09 20:56:21 +02:00
|
|
|
self::SetNewLogTime('S', $dateTime);
|
|
|
|
}
|
|
|
|
}
|
2012-05-09 01:31:56 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
header('HTTP/1.0 503 Service Unavailable');
|
2021-10-11 16:10:47 +02:00
|
|
|
Logging::info('SetEndTime - Could not connect to database.');
|
|
|
|
|
2012-05-11 20:50:38 +02:00
|
|
|
exit;
|
2012-05-09 01:31:56 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 22:53:04 +02:00
|
|
|
}
|