Merge branch 'devel' of dev.sourcefabric.org:airtime into devel
Conflicts: airtime_mvc/application/models/Playlist.php
This commit is contained in:
commit
32f431c584
13 changed files with 353 additions and 233 deletions
|
@ -68,6 +68,7 @@ class Application_Model_Playlist
|
|||
"conductor" => "DbConductor",
|
||||
"utime" => "DbUtime",
|
||||
"mtime" => "DbMtime",
|
||||
"lptime" => "DbLPtime",
|
||||
"disc_number" => "DbDiscNumber",
|
||||
"genre" => "DbGenre",
|
||||
"isrc_number" => "DbIsrcNumber",
|
||||
|
@ -81,7 +82,6 @@ class Application_Model_Playlist
|
|||
"radio_station_name" => "DbRadioStation",
|
||||
"rating" => "DbRating",
|
||||
"sample_rate" => "DbSampleRate",
|
||||
"soundcloud_id" => "DbSoundcloudId",
|
||||
"track_title" => "DbTrackTitle",
|
||||
"track_num" => "DbTrackNum",
|
||||
"year" => "DbYear"
|
||||
|
@ -1109,43 +1109,42 @@ class Application_Model_Playlist
|
|||
}
|
||||
|
||||
$qry = CcFilesQuery::create();
|
||||
foreach ($storedCrit["crit"] as $criteria) {
|
||||
$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']];
|
||||
$spCriteria = $criteria['criteria'];
|
||||
|
||||
$spCriteriaModifier = $criteria['modifier'];
|
||||
$spCriteriaValue = $criteria['value'];
|
||||
|
||||
// change date/time to UTC is the column time is timestamp
|
||||
if (CcFilesPeer::getTableMap()->getColumnByPhpName($spCriteriaPhpName)->getType() == PropelColumnTypes::TIMESTAMP) {
|
||||
$spCriteriaValue = Application_Common_DateHelper::ConvertToUtcDateTimeString($spCriteriaValue);
|
||||
}
|
||||
|
||||
if ($spCriteriaModifier == "starts with") {
|
||||
$spCriteriaValue = "$spCriteriaValue%";
|
||||
} else if ($spCriteriaModifier == "ends with") {
|
||||
$spCriteriaValue = "%$spCriteriaValue";
|
||||
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
|
||||
$spCriteriaValue = "%$spCriteriaValue%";
|
||||
} else if ($spCriteriaModifier == "is in the range") {
|
||||
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'";
|
||||
}
|
||||
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
||||
try{
|
||||
$qry->filterBy($spCriteriaPhpName, $spCriteriaValue, $spCriteriaModifier);
|
||||
$qry->addAscendingOrderByColumn('random()');
|
||||
}catch (Exception $e){
|
||||
Logging::log($e);
|
||||
|
||||
if (isset($storedCrit["crit"])) {
|
||||
foreach ($storedCrit["crit"] as $criteria) {
|
||||
$spCriteriaPhpName = self::$criteria2PeerMap[$criteria['criteria']];
|
||||
$spCriteria = $criteria['criteria'];
|
||||
|
||||
$spCriteriaModifier = $criteria['modifier'];
|
||||
$spCriteriaValue = $criteria['value'];
|
||||
if ($spCriteriaModifier == "starts with") {
|
||||
$spCriteriaValue = "$spCriteriaValue%";
|
||||
} else if ($spCriteriaModifier == "ends with") {
|
||||
$spCriteriaValue = "%$spCriteriaValue";
|
||||
} else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") {
|
||||
$spCriteriaValue = "%$spCriteriaValue%";
|
||||
} else if ($spCriteriaModifier == "is in the range") {
|
||||
$spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'";
|
||||
}
|
||||
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
|
||||
try{
|
||||
$qry->filterBy($spCriteriaPhpName, $spCriteriaValue, $spCriteriaModifier);
|
||||
$qry->addAscendingOrderByColumn('random()');
|
||||
}catch (Exception $e){
|
||||
Logging::log($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// construct limit restriction
|
||||
$limits = array();
|
||||
if ($storedCrit['limit']['modifier'] == "items") {
|
||||
$limits['time'] = 1440 * 60;
|
||||
$limits['items'] = $storedCrit['limit']['value'];
|
||||
} else {
|
||||
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval($storedCrit['limit']['value']) * 60 * 60 : intval($storedCrit['limit']['value'] * 60);
|
||||
$limits['items'] = null;
|
||||
if (isset($storedCrit['limit'])) {
|
||||
if ($storedCrit['limit']['modifier'] == "items") {
|
||||
$limits['time'] = 1440 * 60;
|
||||
$limits['items'] = $storedCrit['limit']['value'];
|
||||
} else {
|
||||
$limits['time'] = $storedCrit['limit']['modifier'] == "hours" ? intval($storedCrit['limit']['value']) * 60 * 60 : intval($storedCrit['limit']['value'] * 60);
|
||||
$limits['items'] = null;
|
||||
}
|
||||
}
|
||||
try{
|
||||
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
|
||||
|
|
|
@ -966,4 +966,10 @@ class Application_Model_Schedule
|
|||
|
||||
return $overlapping;
|
||||
}
|
||||
|
||||
public static function GetFileId($p_scheduleId)
|
||||
{
|
||||
$scheduledItem = CcScheduleQuery::create()->findPK($p_scheduleId);
|
||||
return $scheduledItem->getDbFileId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1519,10 +1519,11 @@ class Application_Model_Show
|
|||
$sql = "SELECT si1.starts AS starts, si1.ends AS ends, si1.record AS record, si1.rebroadcast AS rebroadcast, si2.starts AS parent_starts,
|
||||
si1.instance_id AS record_id, si1.show_id AS show_id, show.name AS name,
|
||||
show.color AS color, show.background_color AS background_color, si1.file_id AS file_id, si1.id AS instance_id,
|
||||
si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled
|
||||
si1.created AS created, si1.last_scheduled AS last_scheduled, si1.time_filled AS time_filled, f.soundcloud_id
|
||||
FROM cc_show_instances AS si1
|
||||
LEFT JOIN cc_show_instances AS si2 ON si1.instance_id = si2.id
|
||||
LEFT JOIN cc_show AS show ON show.id = si1.show_id
|
||||
LEFT JOIN cc_files AS f ON f.id = si1.file_id
|
||||
WHERE si1.modified_instance = FALSE";
|
||||
//only want shows that are starting at the time or later.
|
||||
$start_string = $start_timestamp->format("Y-m-d H:i:s");
|
||||
|
@ -1538,7 +1539,6 @@ class Application_Model_Show
|
|||
OR (si1.starts <= '{$start_string}' AND si1.ends >= '{$end_string}'))";
|
||||
}
|
||||
|
||||
|
||||
if (isset($excludeInstance)) {
|
||||
foreach ($excludeInstance as $instance) {
|
||||
$sql_exclude[] = "si1.id != {$instance}";
|
||||
|
@ -1549,8 +1549,7 @@ class Application_Model_Show
|
|||
$sql = $sql." AND ({$exclude})";
|
||||
}
|
||||
|
||||
$result = $con->query($sql)->fetchAll();
|
||||
|
||||
$result = $con->query($sql);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -1606,7 +1605,7 @@ class Application_Model_Show
|
|||
* -in UTC time
|
||||
* @param boolean $editable
|
||||
*/
|
||||
public static function getFullCalendarEvents($p_start, $p_end, $p_editable=false)
|
||||
public static function &getFullCalendarEvents($p_start, $p_end, $p_editable=false)
|
||||
{
|
||||
$events = array();
|
||||
$interval = $p_start->diff($p_end);
|
||||
|
@ -1614,11 +1613,12 @@ class Application_Model_Show
|
|||
$shows = Application_Model_Show::getShows($p_start, $p_end);
|
||||
$nowEpoch = time();
|
||||
|
||||
$timezone = date_default_timezone_get();
|
||||
|
||||
foreach ($shows as $show) {
|
||||
$options = array();
|
||||
|
||||
//only bother calculating percent for week or day view.
|
||||
|
||||
if (intval($days) <= 7) {
|
||||
$options["percent"] = Application_Model_Show::getPercentScheduled($show["starts"], $show["ends"], $show["time_filled"]);
|
||||
}
|
||||
|
@ -1627,11 +1627,17 @@ class Application_Model_Show
|
|||
$parentStartsDT = new DateTime($show["parent_starts"], new DateTimeZone("UTC"));
|
||||
$parentStartsEpoch = intval($parentStartsDT->format("U"));
|
||||
}
|
||||
$startsDT = new DateTime($show["starts"], new DateTimeZone("UTC"));
|
||||
$endsDT = new DateTime($show["ends"], new DateTimeZone("UTC"));
|
||||
|
||||
$startsEpoch = intval($startsDT->format("U"));
|
||||
$endsEpoch = intval($endsDT->format("U"));
|
||||
$startsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["starts"], new DateTimeZone("UTC"));
|
||||
$endsDT = DateTime::createFromFormat("Y-m-d G:i:s", $show["ends"], new DateTimeZone("UTC"));
|
||||
|
||||
$startsEpochStr = $startsDT->format("U");
|
||||
$endsEpochStr = $endsDT->format("U");
|
||||
|
||||
$startsEpoch = intval($startsEpochStr);
|
||||
$endsEpoch = intval($endsEpochStr);
|
||||
|
||||
$startsDT->setTimezone(new DateTimeZone($timezone));
|
||||
$endsDT->setTimezone(new DateTimeZone($timezone));
|
||||
|
||||
if ($p_editable && $show["record"] && $nowEpoch > $startsEpoch) {
|
||||
$options["editable"] = false;
|
||||
|
@ -1640,7 +1646,7 @@ class Application_Model_Show
|
|||
} elseif ($p_editable && $nowEpoch < $endsEpoch) {
|
||||
$options["editable"] = true;
|
||||
}
|
||||
$events[] = Application_Model_Show::makeFullCalendarEvent($show, $options);
|
||||
$events[] = &self::makeFullCalendarEvent($show, $options, $startsDT, $endsDT, $startsEpochStr, $endsEpochStr);
|
||||
}
|
||||
|
||||
return $events;
|
||||
|
@ -1659,47 +1665,35 @@ class Application_Model_Show
|
|||
return $percent;
|
||||
}
|
||||
|
||||
private static function makeFullCalendarEvent($show, $options=array())
|
||||
private static function &makeFullCalendarEvent(&$show, $options=array(), $startDateTime, $endDateTime, $startsEpoch, $endsEpoch)
|
||||
{
|
||||
$event = array();
|
||||
|
||||
$startDateTime = new DateTime($show["starts"], new DateTimeZone("UTC"));
|
||||
$startDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$endDateTime = new DateTime($show["ends"], new DateTimeZone("UTC"));
|
||||
$endDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
||||
|
||||
$event["id"] = intval($show["instance_id"]);
|
||||
$event["title"] = $show["name"];
|
||||
$event["start"] = $startDateTime->format("Y-m-d H:i:s");
|
||||
$event["startUnix"] = $startDateTime->format("U");
|
||||
$event["startUnix"] = $startsEpoch;
|
||||
$event["end"] = $endDateTime->format("Y-m-d H:i:s");
|
||||
$event["endUnix"] = $endDateTime->format("U");
|
||||
$event["endUnix"] = $endsEpoch;
|
||||
$event["allDay"] = false;
|
||||
$event["showId"] = intval($show["show_id"]);
|
||||
$event["record"] = intval($show["record"]);
|
||||
$event["rebroadcast"] = intval($show["rebroadcast"]);
|
||||
|
||||
// get soundcloud_id
|
||||
if (!is_null($show["file_id"])) {
|
||||
$file = Application_Model_StoredFile::Recall($show["file_id"]);
|
||||
$soundcloud_id = $file->getSoundCloudId();
|
||||
}
|
||||
|
||||
$event["soundcloud_id"] = isset($soundcloud_id) ? $soundcloud_id : -1;
|
||||
$event["soundcloud_id"] = is_null($show["soundcloud_id"]) ? -1 : $show["soundcloud_id"];
|
||||
|
||||
//event colouring
|
||||
if ($show["color"] != "") {
|
||||
$event["textColor"] = "#".$show["color"];
|
||||
}
|
||||
|
||||
if ($show["background_color"] != "") {
|
||||
$event["color"] = "#".$show["background_color"];
|
||||
}
|
||||
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
$event[$key] = $value;
|
||||
}
|
||||
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,19 @@ class Application_Model_StoredFile
|
|||
{
|
||||
$this->_file->setDbFtype($p_format);
|
||||
}
|
||||
|
||||
/* This function is only called after liquidsoap
|
||||
* has notified that a track has started playing.
|
||||
*/
|
||||
public function setLastPlayedTime($p_now)
|
||||
{
|
||||
$this->_file->setDbLPtime($p_now);
|
||||
/* Normally we would only call save after all columns have been set
|
||||
* like in setDbColMetadata(). But since we are only setting one
|
||||
* column in this case it is OK.
|
||||
*/
|
||||
$this->_file->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multiple metadata values using defined metadata constants.
|
||||
|
@ -120,9 +133,6 @@ class Application_Model_StoredFile
|
|||
}
|
||||
$this->setDbColMetadata($dbMd);
|
||||
}
|
||||
|
||||
$this->_file->setDbMtime(new DateTime("now"), new DateTimeZone("UTC"));
|
||||
$this->_file->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,7 +163,7 @@ class Application_Model_StoredFile
|
|||
}
|
||||
}
|
||||
|
||||
$this->_file->setDbMtime(new DateTime("now"), new DateTimeZone("UTC"));
|
||||
$this->_file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
||||
$this->_file->save();
|
||||
}
|
||||
|
||||
|
@ -476,8 +486,8 @@ Logging::log("getting media! - 2");
|
|||
{
|
||||
$file = new CcFiles();
|
||||
$file->setDbGunid(md5(uniqid("", true)));
|
||||
$file->setDbUtime(new DateTime("now"), new DateTimeZone("UTC"));
|
||||
$file->setDbMtime(new DateTime("now"), new DateTimeZone("UTC"));
|
||||
$file->setDbUtime(new DateTime("now", new DateTimeZone("UTC")));
|
||||
$file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
||||
|
||||
$storedFile = new Application_Model_StoredFile();
|
||||
$storedFile->_file = $file;
|
||||
|
@ -713,6 +723,15 @@ Logging::log("getting media! - 2");
|
|||
$formatter = new BitrateFormatter($row['bit_rate']);
|
||||
$row['bit_rate'] = $formatter->format();
|
||||
}
|
||||
|
||||
//convert mtime and utime to localtime
|
||||
$row['mtime'] = new DateTime($row['mtime'], new DateTimeZone('UTC'));
|
||||
$row['mtime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));
|
||||
$row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
|
||||
|
||||
$row['utime'] = new DateTime($row['utime'], new DateTimeZone('UTC'));
|
||||
$row['utime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));
|
||||
$row['utime'] = $row['utime']->format('Y-m-d H:i:s');
|
||||
|
||||
// add checkbox row
|
||||
$row['checkbox'] = "<input type='checkbox' name='cb_".$row['id']."'>";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue