Merge branch 'devel' of dev.sourcefabric.org:airtime
This commit is contained in:
commit
b87e661f96
34 changed files with 1076 additions and 270 deletions
115
airtime_mvc/application/models/Dashboard.php
Normal file
115
airtime_mvc/application/models/Dashboard.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
class Application_Model_Dashboard
|
||||
{
|
||||
|
||||
public static function GetPreviousItem($p_timeNow){
|
||||
//get previous show and previous item in the schedule table.
|
||||
//Compare the two and if the last show was recorded and started
|
||||
//after the last item in the schedule table, then return the show's
|
||||
//name. Else return the last item from the schedule.
|
||||
|
||||
$showInstance = ShowInstance::GetLastShowInstance($p_timeNow);
|
||||
$row = Schedule::GetLastScheduleItem($p_timeNow);
|
||||
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
return null;
|
||||
} else {
|
||||
//should never reach here. Doesnt make sense to have
|
||||
//a schedule item not within a show_instance.
|
||||
}
|
||||
} else {
|
||||
if (count($row) == 0){
|
||||
//last item is a show instance
|
||||
return array("name"=>$showInstance->getName(),
|
||||
"starts"=>$showInstance->getShowStart(),
|
||||
"ends"=>$showInstance->getShowEnd());
|
||||
} else {
|
||||
//return the one that started later.
|
||||
if ($row[0]["starts"] >= $showInstance->getShowStart()){
|
||||
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
|
||||
"starts"=>$row[0]["starts"],
|
||||
"ends"=>$row[0]["ends"]);
|
||||
} else {
|
||||
return array("name"=>$showInstance->getName(),
|
||||
"starts"=>$showInstance->getShowStart(),
|
||||
"ends"=>$showInstance->getShowEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetCurrentItem($p_timeNow){
|
||||
//get previous show and previous item in the schedule table.
|
||||
//Compare the two and if the last show was recorded and started
|
||||
//after the last item in the schedule table, then return the show's
|
||||
//name. Else return the last item from the schedule.
|
||||
|
||||
$showInstance = ShowInstance::GetCurrentShowInstance($p_timeNow);
|
||||
$row = Schedule::GetCurrentScheduleItem($p_timeNow);
|
||||
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
return null;
|
||||
} else {
|
||||
//should never reach here. Doesnt make sense to have
|
||||
//a schedule item not within a show_instance.
|
||||
}
|
||||
} else {
|
||||
if (count($row) == 0){
|
||||
//last item is a show instance
|
||||
return array("name"=>$showInstance->getName(),
|
||||
"starts"=>$showInstance->getShowStart(),
|
||||
"ends"=>$showInstance->getShowEnd(),
|
||||
"media_item_played"=>false, //TODO
|
||||
"record"=>$showInstance->isRecorded()); //TODO
|
||||
} else {
|
||||
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
|
||||
"starts"=>$row[0]["starts"],
|
||||
"ends"=>$row[0]["ends"],
|
||||
"media_item_played"=>$row[0]["media_item_played"],
|
||||
"record"=>0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetNextItem($p_timeNow){
|
||||
//get previous show and previous item in the schedule table.
|
||||
//Compare the two and if the last show was recorded and started
|
||||
//after the last item in the schedule table, then return the show's
|
||||
//name. Else return the last item from the schedule.
|
||||
|
||||
$showInstance = ShowInstance::GetNextShowInstance($p_timeNow);
|
||||
$row = Schedule::GetNextScheduleItem($p_timeNow);
|
||||
|
||||
if (is_null($showInstance)){
|
||||
if (count($row) == 0){
|
||||
return null;
|
||||
} else {
|
||||
//should never reach here. Doesnt make sense to have
|
||||
//a schedule item not within a show_instance.
|
||||
}
|
||||
} else {
|
||||
if (count($row) == 0){
|
||||
//last item is a show instance
|
||||
return array("name"=>$showInstance->getName(),
|
||||
"starts"=>$showInstance->getShowStart(),
|
||||
"ends"=>$showInstance->getShowEnd());
|
||||
} else {
|
||||
//return the one that starts sooner.
|
||||
|
||||
if ($row[0]["starts"] <= $showInstance->getShowStart()){
|
||||
return array("name"=>$row[0]["artist_name"]." - ".$row[0]["track_title"],
|
||||
"starts"=>$row[0]["starts"],
|
||||
"ends"=>$row[0]["ends"]);
|
||||
} else {
|
||||
return array("name"=>$showInstance->getName(),
|
||||
"starts"=>$showInstance->getShowStart(),
|
||||
"ends"=>$showInstance->getShowEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -40,5 +40,27 @@ class RabbitMq
|
|||
}
|
||||
}
|
||||
|
||||
public static function SendFileMetaData($md)
|
||||
{
|
||||
global $CC_CONFIG;
|
||||
|
||||
$conn = new AMQPConnection($CC_CONFIG["rabbitmq"]["host"],
|
||||
$CC_CONFIG["rabbitmq"]["port"],
|
||||
$CC_CONFIG["rabbitmq"]["user"],
|
||||
$CC_CONFIG["rabbitmq"]["password"]);
|
||||
$channel = $conn->channel();
|
||||
$channel->access_request($CC_CONFIG["rabbitmq"]["vhost"], false, false, true, true);
|
||||
|
||||
$EXCHANGE = 'airtime-media-monitor';
|
||||
$channel->exchange_declare($EXCHANGE, 'direct', false, true);
|
||||
|
||||
$data = json_encode($md);
|
||||
$msg = new AMQPMessage($data, array('content_type' => 'text/plain'));
|
||||
|
||||
$channel->basic_publish($msg, $EXCHANGE);
|
||||
$channel->close();
|
||||
$conn->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -365,9 +365,12 @@ class Schedule {
|
|||
$timeNow = $date->getTimestamp();
|
||||
return array("env"=>APPLICATION_ENV,
|
||||
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
|
||||
"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
|
||||
"current"=>Schedule::GetScheduledItemData($timeNow, 0),
|
||||
"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
|
||||
//"previous"=>Schedule::GetScheduledItemData($timeNow, -1, $prev, "24 hours"),
|
||||
//"current"=>Schedule::GetScheduledItemData($timeNow, 0),
|
||||
//"next"=>Schedule::GetScheduledItemData($timeNow, 1, $next, "48 hours"),
|
||||
"previous"=>Application_Model_Dashboard::GetPreviousItem($timeNow),
|
||||
"current"=>Application_Model_Dashboard::GetCurrentItem($timeNow),
|
||||
"next"=>Application_Model_Dashboard::GetNextItem($timeNow),
|
||||
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
|
||||
"nextShow"=>Show_DAL::GetNextShows($timeNow, 1),
|
||||
"timezone"=> date("T"),
|
||||
|
@ -375,6 +378,52 @@ class Schedule {
|
|||
"apiKey"=>$CC_CONFIG['apiKey'][0]);
|
||||
}
|
||||
|
||||
public static function GetLastScheduleItem($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *"
|
||||
." FROM $CC_CONFIG[scheduleTable] st"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
||||
." ON st.file_id = ft.id"
|
||||
." WHERE st.ends < TIMESTAMP '$p_timeNow'"
|
||||
." ORDER BY st.ends DESC"
|
||||
." LIMIT 1";
|
||||
|
||||
$row = $CC_DBC->GetAll($sql);
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
public static function GetCurrentScheduleItem($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *"
|
||||
." FROM $CC_CONFIG[scheduleTable] st"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
||||
." ON st.file_id = ft.id"
|
||||
." WHERE st.starts <= TIMESTAMP '$p_timeNow'"
|
||||
." AND st.ends > TIMESTAMP '$p_timeNow'"
|
||||
." LIMIT 1";
|
||||
|
||||
$row = $CC_DBC->GetAll($sql);
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function GetNextScheduleItem($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT *"
|
||||
." FROM $CC_CONFIG[scheduleTable] st"
|
||||
." LEFT JOIN $CC_CONFIG[filesTable] ft"
|
||||
." ON st.file_id = ft.id"
|
||||
." WHERE st.starts > TIMESTAMP '$p_timeNow'"
|
||||
." ORDER BY st.starts"
|
||||
." LIMIT 1";
|
||||
|
||||
$row = $CC_DBC->GetAll($sql);
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an SQL Query for accessing scheduled item information from
|
||||
* the database.
|
||||
|
|
|
@ -1718,6 +1718,57 @@ class ShowInstance {
|
|||
|
||||
return ($diff < 0) ? 0 : $diff;
|
||||
}
|
||||
|
||||
public static function GetLastShowInstance($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT si.id"
|
||||
." FROM $CC_CONFIG[showInstances] si"
|
||||
." WHERE si.ends < TIMESTAMP '$p_timeNow'"
|
||||
." ORDER BY si.ends DESC"
|
||||
." LIMIT 1";
|
||||
|
||||
$id = $CC_DBC->GetOne($sql);
|
||||
if (is_null($id)){
|
||||
return null;
|
||||
} else {
|
||||
return new ShowInstance($id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetCurrentShowInstance($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT si.id"
|
||||
." FROM $CC_CONFIG[showInstances] si"
|
||||
." WHERE si.starts <= TIMESTAMP '$p_timeNow'"
|
||||
." AND si.ends > TIMESTAMP '$p_timeNow'"
|
||||
." LIMIT 1";
|
||||
|
||||
$id = $CC_DBC->GetOne($sql);
|
||||
if (is_null($id)){
|
||||
return null;
|
||||
} else {
|
||||
return new ShowInstance($id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetNextShowInstance($p_timeNow){
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$sql = "SELECT si.id"
|
||||
." FROM $CC_CONFIG[showInstances] si"
|
||||
." WHERE si.starts > TIMESTAMP '$p_timeNow'"
|
||||
." ORDER BY si.starts"
|
||||
." LIMIT 1";
|
||||
|
||||
$id = $CC_DBC->GetOne($sql);
|
||||
if (is_null($id)){
|
||||
return null;
|
||||
} else {
|
||||
return new ShowInstance($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Show Data Access Layer */
|
||||
|
|
|
@ -543,16 +543,25 @@ class StoredFile {
|
|||
public function replaceDbMetadata($p_values)
|
||||
{
|
||||
global $CC_CONFIG, $CC_DBC;
|
||||
|
||||
$data = array();
|
||||
foreach ($p_values as $category => $value) {
|
||||
$escapedValue = pg_escape_string($value);
|
||||
$columnName = $category;
|
||||
if (!is_null($columnName)) {
|
||||
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
||||
." SET $columnName='$escapedValue'"
|
||||
." WHERE gunid = '".$this->gunid."'";
|
||||
$CC_DBC->query($sql);
|
||||
$data[] = "$columnName='$escapedValue'";
|
||||
}
|
||||
}
|
||||
|
||||
$data = join(",", $data);
|
||||
$sql = "UPDATE ".$CC_CONFIG["filesTable"]
|
||||
." SET $data"
|
||||
." WHERE gunid = '".$this->gunid."'";
|
||||
$res = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($res)) {
|
||||
$CC_DBC->query("ROLLBACK");
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
public function clearMetadata()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue