Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

Conflicts:
	airtime_mvc/application/models/Playlist.php
This commit is contained in:
James 2012-07-23 11:03:29 -04:00
commit 32f431c584
13 changed files with 353 additions and 233 deletions

View file

@ -349,6 +349,18 @@ class ApiController extends Zend_Controller_Action
$schedule_group_id = $this->_getParam("schedule_id");
$media_id = $this->_getParam("media_id");
$result = Application_Model_Schedule::UpdateMediaPlayedStatus($media_id);
//set a 'last played' timestamp for media item
//needed for smart playlists
try{
$file_id = Application_Model_Schedule::GetFileId($media_id);
$file = Application_Model_StoredFile::Recall($file_id);
$now = new DateTime("now", new DateTimeZone("UTC"));
$file->setLastPlayedTime($now);
}catch(Exception $e){
Logging::log($e);
}
echo json_encode(array("status"=>1, "message"=>""));
}

View file

@ -76,9 +76,13 @@ class PlaylistController extends Zend_Controller_Action
$formatter = new LengthFormatter($pl->getLength());
$this->view->length = $formatter->format();
$form = new Application_Form_SmartPlaylistCriteria();
$form = new Application_Form_SmartPlaylist();
$form->removeDecorator('DtDdWrapper');
$form->startForm($pl->getId());
$subform = new Application_Form_SmartPlaylistCriteriaSubForm();
$form->removeDecorator('DtDdWrapper');
$form->addSubForm($subform, 'sp_set_1');
$this->view->form = $form;
$this->view->pl = $pl;
@ -171,7 +175,7 @@ class PlaylistController extends Zend_Controller_Action
if($isAdminOrPM || $pl->getCreatorId() == $userInfo->id){
$this->view->pl = $pl;
$form = new Application_Form_SmartPlaylistCriteria();
$form = new Application_Form_SmartPlaylist();
$form->startForm($this->pl_sess->id);
$this->view->form = $form;
}
@ -203,7 +207,7 @@ class PlaylistController extends Zend_Controller_Action
{
$id = $this->_getParam('id', null);
Logging::log("editing playlist {$id}");
//$form = new Application_Form_SmartPlaylistCriteria();
//$form = new Application_Form_SmartPlaylist();
if (!is_null($id)) {

View file

@ -114,18 +114,8 @@ class ScheduleController extends Zend_Controller_Action
$editable = false;
}
$this->view->events = Application_Model_Show::getFullCalendarEvents($start, $end, $editable);
}
public function getCurrentShowAction()
{
$currentShow = Application_Model_Show::GetCurrentShow();
if (!empty($currentShow)) {
$this->view->si_id = $currentShow[0]["instance_id"];
$this->view->current_show = true;
} else {
$this->view->current_show = false;
}
$events = &Application_Model_Show::getFullCalendarEvents($start, $end, $editable);
$this->view->events = $events;
}
public function moveShowAction()

View file

@ -0,0 +1,89 @@
<?php
class Application_Form_SmartPlaylist extends Zend_Form
{
public function init(){
}
public function startForm($p_playlistId)
{
// load type
$out = CcPlaylistQuery::create()->findPk($p_playlistId);
if ($out->getDbType() == "static") {
$playlistType = 0;
} else {
$playlistType = 1;
}
$spType = new Zend_Form_Element_Radio('sp_type');
$spType->setLabel('Set smart playlist type:')
->setDecorators(array('viewHelper'))
->setMultiOptions(array(
'static' => 'Static',
'dynamic' => 'Dynamic'
))
->setValue($playlistType);
$this->addElement($spType);
/*
// load criteria from db
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($p_playlistId);
*/
$storedCrit = array();
foreach ($out as $crit) {
$criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
if($criteria == "limit"){
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
}else{
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
}
}
$openSmartPlaylistOption = false;
if (!empty($storedCrit)) {
$openSmartPlaylistOption = true;
}
$save = new Zend_Form_Element_Button('save_button');
$save->setAttrib('class', 'ui-button ui-state-default sp-button');
$save->setAttrib('title', 'Save criteria only');
$save->setIgnore(true);
$save->setLabel('Save');
$save->setDecorators(array('viewHelper'));
$this->addElement($save);
$generate = new Zend_Form_Element_Button('generate_button');
$generate->setAttrib('class', 'ui-button ui-state-default sp-button');
$generate->setAttrib('title', 'Save criteria and generate playlist content');
$generate->setIgnore(true);
$generate->setLabel('Generate');
$generate->setDecorators(array('viewHelper'));
$this->addElement($generate);
$shuffle = new Zend_Form_Element_Button('shuffle_button');
$shuffle->setAttrib('class', 'ui-button ui-state-default sp-button');
$shuffle->setAttrib('title', 'Shuffle playlist content');
$shuffle->setIgnore(true);
$shuffle->setLabel('Shuffle');
$shuffle->setDecorators(array('viewHelper'));
$this->addElement($shuffle);
$numOfSubForm = 3;
for ($i=0;$i<$numOfSubForm;$i++) {
$subform = new Application_Form_SmartPlaylistCriteriaSubForm();
$subform->setCriteriaSetNumber($i);
$subform->startForm($p_playlistId);
$this->addSubForm($subform, 'sp_set_'.$i);
}
//getting playlist content candidate count that meets criteria
$pl = new Application_Model_Playlist($p_playlistId);
$files = $pl->getListofFilesMeetCriteria();
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist.phtml', "openOption"=> $openSmartPlaylistOption, "parent_form"=>$this, "numOfSubForm"=>$numOfSubForm))
));
}
}

View file

@ -1,9 +1,17 @@
<?php
class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
class Application_Form_SmartPlaylistCriteriaSubForm extends Zend_Form_SubForm
{
private $setNumber;
public function init(){
}
public function setCriteriaSetNumber($p_num)
{
$this->setNumber = $p_num;
}
public function startForm($p_playlistId)
{
$criteriaOptions = array(
@ -21,6 +29,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
"label" => "Label",
"language" => "Language",
"mtime" => "Last Modified",
"lptime" => "Last Played",
"length" => "Length",
"lyricist" => "Lyricist",
"mood" => "Mood",
@ -29,60 +38,59 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
"radio_station_name" => "Radio Station Name",
"rating" => "Rating",
"sample_rate" => "Sample Rate",
"soundcloud_id" => "Soundcloud Upload",
"track_title" => "Title",
"track_num" => "Track Number",
"utime" => "Uploaded",
"year" => "Year"
);
$criteriaTypes = array(
0 => "",
"album_title" => "s",
"artist_name" => "s",
"bit_rate" => "n",
"bpm" => "n",
"comments" => "s",
"composer" => "s",
"conductor" => "s",
"utime" => "n",
"mtime" => "n",
"disc_number" => "n",
"genre" => "s",
"isrc_number" => "s",
"label" => "s",
"language" => "s",
"length" => "n",
"lyricist" => "s",
"mood" => "s",
"name" => "s",
"orchestra" => "s",
"radio_station_name" => "s",
"rating" => "n",
"sample_rate" => "n",
"soundcloud_id" => "n",
"track_title" => "s",
"track_num" => "n",
"year" => "n"
);
$stringCriteriaOptions = array(
"0" => "Select modifier",
"contains" => "contains",
"does not contain" => "does not contain",
"is" => "is",
"is not" => "is not",
"starts with" => "starts with",
"ends with" => "ends with"
);
$numericCriteriaOptions = array(
"0" => "Select modifier",
"is" => "is",
"is not" => "is not",
"is greater than" => "is greater than",
"is less than" => "is less than",
"is in the range" => "is in the range"
$criteriaTypes = array(
0 => "",
"album_title" => "s",
"artist_name" => "s",
"bit_rate" => "n",
"bpm" => "n",
"comments" => "s",
"composer" => "s",
"conductor" => "s",
"utime" => "n",
"mtime" => "n",
"lptime" => "n",
"disc_number" => "n",
"genre" => "s",
"isrc_number" => "s",
"label" => "s",
"language" => "s",
"length" => "n",
"lyricist" => "s",
"mood" => "s",
"name" => "s",
"orchestra" => "s",
"radio_station_name" => "s",
"rating" => "n",
"sample_rate" => "n",
"track_title" => "s",
"track_num" => "n",
"year" => "n"
);
$stringCriteriaOptions = array(
"0" => "Select modifier",
"contains" => "contains",
"does not contain" => "does not contain",
"is" => "is",
"is not" => "is not",
"starts with" => "starts with",
"ends with" => "ends with"
);
$numericCriteriaOptions = array(
"0" => "Select modifier",
"is" => "is",
"is not" => "is not",
"is greater than" => "is greater than",
"is less than" => "is less than",
"is in the range" => "is in the range"
);
$limitOptions = array(
@ -91,6 +99,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
"items" => "items"
);
/*
// load type
$out = CcPlaylistQuery::create()->findPk($p_playlistId);
if ($out->getDbType() == "static") {
@ -99,6 +108,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$playlistType = 1;
}
$spType = new Zend_Form_Element_Radio('sp_type');
$spType->setLabel('Set smart playlist type:')
->setDecorators(array('viewHelper'))
@ -108,22 +118,23 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
))
->setValue($playlistType);
$this->addElement($spType);
*/
// load criteria from db
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($p_playlistId);
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($p_playlistId);
$storedCrit = array();
foreach ($out as $crit) {
$criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
$storedCrit = array();
foreach ($out as $crit) {
$criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
if($criteria == "limit"){
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
}else{
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
}
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
}
}
$openSmartPlaylistOption = false;
@ -134,7 +145,8 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$numElements = count($criteriaOptions);
for ($i = 0; $i < $numElements; $i++) {
$criteriaType = "";
$criteria = new Zend_Form_Element_Select('sp_criteria_field_'.$i);
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$this->setNumber."_".$i);
$criteria->setAttrib('class', 'input_select sp_input_select')
->setValue('Select criteria')
->setDecorators(array('viewHelper'))
@ -148,7 +160,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
}
$this->addElement($criteria);
$criteriaModifers = new Zend_Form_Element_Select('sp_criteria_modifier_'.$i);
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$this->setNumber."_".$i);
$criteriaModifers->setValue('Select modifier')
->setAttrib('class', 'input_select sp_input_select')
->setDecorators(array('viewHelper'));
@ -160,85 +172,64 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
}else{
$criteriaModifers->setMultiOptions($numericCriteriaOptions);
}
$criteriaModifers->setValue($storedCrit["crit"][$i]["modifier"]);
}
$criteriaModifers->setValue($storedCrit["crit"][$i]["modifier"]);
}else{
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
}
$this->addElement($criteriaModifers);
$criteriaValue = new Zend_Form_Element_Text('sp_criteria_value_'.$i);
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$this->setNumber."_".$i);
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
->setDecorators(array('viewHelper'));
if ($i != 0 && !isset($storedCrit["crit"][$i])){
$criteriaValue->setAttrib('disabled', 'disabled');
}
if (isset($storedCrit["crit"][$i])) {
$criteriaValue->setValue($storedCrit["crit"][$i]["value"]);
if (isset($storedCrit["crit"][$i])) {
$criteriaValue->setValue($storedCrit["crit"][$i]["value"]);
}
$this->addElement($criteriaValue);
$criteriaExtra = new Zend_Form_Element_Text('sp_criteria_extra_'.$i);
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$this->setNumber."_".$i);
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
->setDecorators(array('viewHelper'));
if (isset($storedCrit["crit"][$i]["extra"])) {
if (isset($storedCrit["crit"][$i]["extra"])) {
$criteriaExtra->setValue($storedCrit["crit"][$i]["extra"]);
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
}else{
$criteriaExtra->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtra);
}
$limit = new Zend_Form_Element_Select('sp_limit_options');
$limit->setAttrib('class', 'sp_input_select');
$limit->setDecorators(array('viewHelper'));
$limit->setMultiOptions($limitOptions);
if (isset($storedCrit["limit"])) {
$limit->setValue($storedCrit["limit"]["modifier"]);
$limit = new Zend_Form_Element_Select('sp_limit_options_'.$this->setNumber);
$limit->setAttrib('class', 'sp_input_select')
->setDecorators(array('viewHelper'))
->setMultiOptions($limitOptions);
if (isset($storedCrit["limit"])) {
$limit->setValue($storedCrit["limit"]["modifier"]);
}
$this->addElement($limit);
$limitValue = new Zend_Form_Element_Text('sp_limit_value');
$limitValue->setAttrib('class', 'sp_input_text_limit');
$limitValue->setLabel('Limit to');
$limitValue->setDecorators(array('viewHelper'));
$limitValue = new Zend_Form_Element_Text('sp_limit_value_'.$this->setNumber);
$limitValue->setAttrib('class', 'sp_input_text_limit')
->setLabel('Limit to')
->setDecorators(array('viewHelper'));
$this->addElement($limitValue);
if (isset($storedCrit["limit"])) {
$limitValue->setValue($storedCrit["limit"]["value"]);
if (isset($storedCrit["limit"])) {
$limitValue->setValue($storedCrit["limit"]["value"]);
}
$save = new Zend_Form_Element_Button('save_button');
$save->setAttrib('class', 'ui-button ui-state-default sp-button');
$save->setAttrib('title', 'Save criteria only');
$save->setIgnore(true);
$save->setLabel('Save');
$save->setDecorators(array('viewHelper'));
$this->addElement($save);
$generate = new Zend_Form_Element_Button('generate_button');
$generate->setAttrib('class', 'ui-button ui-state-default sp-button');
$generate->setAttrib('title', 'Save criteria and generate playlist content');
$generate->setIgnore(true);
$generate->setLabel('Generate');
$generate->setDecorators(array('viewHelper'));
$this->addElement($generate);
$shuffle = new Zend_Form_Element_Button('shuffle_button');
$shuffle->setAttrib('class', 'ui-button ui-state-default sp-button');
$shuffle->setAttrib('title', 'Shuffle playlist content');
$shuffle->setIgnore(true);
$shuffle->setLabel('Shuffle');
$shuffle->setDecorators(array('viewHelper'));
$this->addElement($shuffle);
//getting playlist content candidate count that meets criteria
$pl = new Application_Model_Playlist($p_playlistId);
$files = $pl->getListofFilesMeetCriteria();
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', "openOption"=> $openSmartPlaylistOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count']))
Logging::log($this->getElements());
Logging::log(count($this->getElements()));
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', "openOption"=> $openSmartPlaylistOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'], 'setNumber' => $this->setNumber))
));
}
}

View file

@ -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();

View file

@ -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();
}
}

View file

@ -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;
}

View file

@ -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']."'>";

View file

@ -1,38 +1,18 @@
<form id="smart-playlist-form" method="post" action="">
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='smart_playlist_options'>
<legend style='cursor: pointer;'><span class='ui-icon ui-icon-triangle-2-n-s'></span>Smart Playlist Options</legend>
<h2 class="collapsible-header close"><span class="arrow-icon"></span>Set <?php echo $this->setNumber?></h2>
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='sp_set_<?php echo $this->setNumber?>'>
<dl class='zend_form'>
<div id='sp-success' class='success' style='display:none'></div>
<dd id='sp_type-element' class='radio-inline-list'>
<label>
<?php echo $this->element->getElement('sp_type')->getLabel() ?>
<span class='playlist_type_help_icon'></span>
</label>
<?php $i=0;
$value = $this->element->getElement('sp_type')->getValue();
foreach ($this->element->getElement('sp_type')->getMultiOptions() as $radio) : ?>
<label for='sp_type-<?php echo $i?>'>
<input type="radio" value="<?php echo $i ?>" id="sp_type-<?php echo $i ?>" name="sp_type" <?php if($i == $value){echo 'checked="checked"';}?> ><?php echo $radio ?>
</label>
<?php $i = $i + 1; ?>
<?php endforeach; ?>
<?php echo $this->element->getElement('save_button') ?>
<?php echo $this->element->getElement('generate_button') ?>
<?php echo $this->element->getElement('shuffle_button') ?>
</dd>
<dd id='sp_criteria-element'>
<?php for ($i = 0; $i < $this->criteriasLength; $i++) {?>
<div <?php if (($i > 0) && ($this->element->getElement('sp_criteria_field_'.$i)->getAttrib('disabled') == 'disabled')) {
<div <?php if (($i > 0) && ($this->element->getElement("sp_criteria_field_".$this->setNumber."_".$i)->getAttrib('disabled') == 'disabled')) {
echo 'style=display:none';
} ?>>
<?php echo $this->element->getElement('sp_criteria_field_'.$i) ?>
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?>
<span class='sp_text_font' id="extra_criteria" <?php echo $this->element->getElement('sp_criteria_extra_'.$i)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to <?php echo $this->element->getElement('sp_criteria_extra_'.$i) ?></span>
<a class='ui-button sp-ui-button-icon-only' id='criteria_remove_<?php echo $i ?>'>
<?php echo $this->element->getElement("sp_criteria_field_".$this->setNumber."_".$i) ?>
<?php echo $this->element->getElement("sp_criteria_modifier_".$this->setNumber."_".$i) ?>
<?php echo $this->element->getElement("sp_criteria_value_".$this->setNumber."_".$i) ?>
<span class='sp_text_font' id="extra_criteria" <?php echo $this->element->getElement("sp_criteria_extra_".$this->setNumber."_".$i)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to <?php echo $this->element->getElement('sp_criteria_extra_'.$this->setNumber.'_'.$i) ?></span>
<a class='ui-button sp-ui-button-icon-only' id='criteria_remove_<?php echo $this->setNumber ?>_<?php echo $i ?>'>
<span class='ui-icon ui-icon-closethick'></span>
</a>
<br />
@ -43,9 +23,9 @@
</dd>
<dd id='sp_limit-element'>
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value')->getLabel() ?></span>
<?php echo $this->element->getElement('sp_limit_value')?>
<?php echo $this->element->getElement('sp_limit_options') ?>
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value_'.$this->setNumber)->getLabel() ?></span>
<?php echo $this->element->getElement('sp_limit_value_'.$this->setNumber)?>
<?php echo $this->element->getElement('sp_limit_options_'.$this->setNumber) ?>
<br /><br />
</dd>
<div class='sp_text_font sp_text_font_bold'>
@ -76,5 +56,4 @@
</div>
</dl>
</fieldset>
</form>
</fieldset>

View file

@ -0,0 +1,32 @@
<form id="smart-playlist-form" method="post" action="">
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='smart_playlist_options'>
<legend style='cursor: pointer;'><span class='ui-icon ui-icon-triangle-2-n-s'></span>Smart Playlist Options</legend>
<dl class='zend_form'>
<div id='sp-success' class='success' style='display:none'></div>
<dd id='sp_type-element'>
<label class='sp-label'>
<?php echo $this->element->getElement('sp_type')->getLabel() ?>
<span class='playlist_type_help_icon'></span>
</label>
<?php $i=0;
$value = $this->element->getElement('sp_type')->getValue();
foreach ($this->element->getElement('sp_type')->getMultiOptions() as $radio) : ?>
<label class='sp-label' for='sp_type-<?php echo $i?>'>
<input type="radio" value="<?php echo $i ?>" id="sp_type-<?php echo $i ?>" name="sp_type" <?php if($i == $value){echo 'checked="checked"';}?> ><?php echo $radio ?>
</label>
<?php $i = $i + 1; ?>
<?php endforeach; ?>
<?php echo $this->element->getElement('save_button') ?>
<?php echo $this->element->getElement('generate_button') ?>
<?php echo $this->element->getElement('shuffle_button') ?>
</dd>
</dl>
<?php
for($i=0;$i<$this->numOfSubForm;$i++){
echo $this->parent_form->getSubform('sp_set_'.$i);
}
?>
</fieldset>
</form>

View file

@ -477,6 +477,10 @@ input.input_text.sp_extra_input_text{
width: 16px;
display: inline-block;
}
.sp-label{
padding: 0px !important;
}
/***** SMART PLAYLIST SPECIFIC STYLES END *****/
label {

View file

@ -279,7 +279,7 @@ function callback(data, type) {
if (type == 'shuffle') {
form.find('.success').text('Playlist shuffled');
} else {
form.find('.success').text('Smart playlist generated');
form.find('.success').text('Smart playlist generated and saved');
}
form.find('.success').show();
form.find('#smart_playlist_options').removeClass("closed");
@ -287,8 +287,9 @@ function callback(data, type) {
form.find('.success').text('Criteria saved');
form.find('.success').show();
/* Update number of files that meet criteria and
* change icon to success/warning as appropriate
/* Update number of files that meet criteria and change icon to success/warning
* as appropriate. This is also done in the form but we do not pass the form
* back on a 'Save' callback.
*/
if (json.poolCount > 1) {
$('#sp_pool_count').text(json.poolCount+' files meet the criteria');
@ -358,6 +359,7 @@ var criteriaTypes = {
"conductor" : "s",
"utime" : "n",
"mtime" : "n",
"lptime" : "n",
"disc_number" : "n",
"genre" : "s",
"isrc_number" : "s",
@ -371,7 +373,6 @@ var criteriaTypes = {
"radio_station_name" : "s",
"rating" : "n",
"sample_rate" : "n",
"soundcloud_id" : "n",
"track_title" : "s",
"track_num" : "n",
"year" : "n"