CC-2607: Ability to adjust stream bitrate, type, etc from UI
- removed debug code from NowPlayingController - New Form for streamsetting - Action created in PreferenceController
This commit is contained in:
parent
4f2b2dba6d
commit
cf55e92aa3
17 changed files with 701 additions and 103 deletions
|
@ -52,7 +52,6 @@ class NowplayingController extends Zend_Controller_Action
|
|||
// unset session
|
||||
Zend_Session::namespaceUnset('referrer');
|
||||
}else{
|
||||
var_dump($form->getMessages());
|
||||
$logo = Application_Model_Preference::GetStationLogo();
|
||||
if($logo){
|
||||
$this->view->logoImg = $logo;
|
||||
|
|
|
@ -7,9 +7,7 @@ class PreferenceController extends Zend_Controller_Action
|
|||
{
|
||||
/* Initialize action controller here */
|
||||
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
||||
$ajaxContext/*->addActionContext('register', 'json')
|
||||
->addActionContext('remindme', 'json')*/
|
||||
->addActionContext('server-browse', 'json')
|
||||
$ajaxContext->addActionContext('server-browse', 'json')
|
||||
->addActionContext('change-stor-directory', 'json')
|
||||
->addActionContext('reload-watch-directory', 'json')
|
||||
->addActionContext('remove-watch-directory', 'json')
|
||||
|
@ -91,7 +89,66 @@ class PreferenceController extends Zend_Controller_Action
|
|||
|
||||
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/preferences/streamsetting.js','text/javascript');
|
||||
|
||||
$this->view->form = new Application_Form_StreamSetting();
|
||||
// get current settings
|
||||
$temp = Application_Model_StreamSetting::getStreamSetting();
|
||||
$setting = array();
|
||||
foreach ($temp as $t){
|
||||
$setting[$t['keyname']] = $t['value'];
|
||||
}
|
||||
|
||||
// get predefined type and bitrate from pref table
|
||||
$temp_types = Application_Model_Preference::GetStreamType();
|
||||
$stream_types = array();
|
||||
foreach ($temp_types as $type){
|
||||
$stream_types[trim($type)] = strtoupper(trim($type));
|
||||
}
|
||||
|
||||
$temp_bitrate = Application_Model_Preference::GetStreamBitrate();
|
||||
$stream_bitrates = array();
|
||||
foreach ($temp_bitrate as $type){
|
||||
$stream_bitrates[trim($type)] = strtoupper(trim($type))." Kbit/s";
|
||||
}
|
||||
|
||||
$num_of_stream = 3;
|
||||
$form = new Application_Form_StreamSetting();
|
||||
$form->setSetting($setting);
|
||||
$form->startFrom();
|
||||
for($i=1; $i<=$num_of_stream; $i++){
|
||||
$subform = new Application_Form_StreamSettingSubForm();
|
||||
$subform->setPrefix($i);
|
||||
$subform->setSetting($setting);
|
||||
$subform->setStreamTypes($stream_types);
|
||||
$subform->setStreamBitrates($stream_bitrates);
|
||||
$subform->startForm();
|
||||
$form->addSubForm($subform, "s".$i."_subform");
|
||||
}
|
||||
if ($request->isPost()) {
|
||||
$post_data = $request->getPost();
|
||||
$error = false;
|
||||
$values = array();
|
||||
for($i=1; $i<=$num_of_stream; $i++){
|
||||
if(!$form->getSubForm("s".$i."_subform")->isValid($post_data["s".$i."_data"])){
|
||||
$error = true;
|
||||
}else{
|
||||
// getValues returne array of size 1, so reorganized it
|
||||
foreach($form->getSubForm("s".$i."_subform")->getValues() as $key => $d){
|
||||
$values[$key] = $d;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($form->isValid($post_data['output_sound_device'])){
|
||||
$values['output_sound_device'] = $form->getValue('output_sound_device');
|
||||
}
|
||||
if(!$error){
|
||||
Application_Model_StreamSetting::setStreamSetting($values);
|
||||
$data = array();
|
||||
$data['setting'] = Application_Model_StreamSetting::getStreamSetting();
|
||||
RabbitMq::SendMessageToPypo("update_stream_setting", $data);
|
||||
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
|
||||
}
|
||||
}
|
||||
$this->view->num_stream = $num_of_stream;
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function serverBrowseAction()
|
||||
|
@ -145,16 +202,6 @@ class PreferenceController extends Zend_Controller_Action
|
|||
|
||||
$this->view->subform = $watched_dirs_form->render();
|
||||
}
|
||||
|
||||
public function changeStreamSettingAction()
|
||||
{
|
||||
$data = array();
|
||||
$data['setting'] = Application_Model_StreamSetting::getStreamSetting();
|
||||
RabbitMq::SendMessageToPypo("update_stream_setting", $data);
|
||||
|
||||
$form = new Application_Form_StreamSetting();
|
||||
$this->view->subform = $form->render();
|
||||
}
|
||||
|
||||
public function reloadWatchDirectoryAction()
|
||||
{
|
||||
|
|
|
@ -1,13 +1,30 @@
|
|||
<?php
|
||||
|
||||
class Application_Form_StreamSetting extends Zend_Form_SubForm
|
||||
class Application_Form_StreamSetting extends Zend_Form
|
||||
{
|
||||
|
||||
private $setting;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/stream_setting.phtml'))
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function setSetting($setting){
|
||||
$this->setting = $setting;
|
||||
}
|
||||
|
||||
public function startFrom(){
|
||||
$setting = $this->setting;
|
||||
$output_sound_device = new Zend_Form_Element_Checkbox('output_sound_device');
|
||||
$output_sound_device->setLabel('Enabled')
|
||||
->setRequired(false)
|
||||
->setValue($setting['output_sound_device'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output_sound_device);
|
||||
}
|
||||
|
||||
public function isValid($data){
|
||||
$this->populate(array("output_sound_device"=>$data));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
145
airtime_mvc/application/forms/StreamSettingSubForm.php
Normal file
145
airtime_mvc/application/forms/StreamSettingSubForm.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm{
|
||||
private $prefix;
|
||||
private $setting;
|
||||
private $stream_types;
|
||||
private $stream_bitrates;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setPrefix($prefix){
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function setSetting($setting){
|
||||
$this->setting = $setting;
|
||||
}
|
||||
|
||||
public function setStreamTypes($stream_types){
|
||||
$this->stream_types = $stream_types;
|
||||
}
|
||||
|
||||
public function setStreamBitrates($stream_bitrates){
|
||||
$this->stream_bitrates = $stream_bitrates;
|
||||
}
|
||||
|
||||
public function startForm(){
|
||||
$prefix = "s".$this->prefix;
|
||||
$stream_number = $this->prefix;
|
||||
$setting = $this->setting;
|
||||
$stream_types = $this->stream_types;
|
||||
$stream_bitrates = $this->stream_bitrates;
|
||||
|
||||
$this->setIsArray(true);
|
||||
$this->setElementsBelongTo($prefix."_data");
|
||||
|
||||
$enable = new Zend_Form_Element_Checkbox('enable');
|
||||
$enable->setLabel('Enabled:')
|
||||
->setValue($setting['output_'.$prefix] != 'disabled'?1:0)
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($enable);
|
||||
|
||||
$type = new Zend_Form_Element_Select('type');
|
||||
$type->setLabel("Type:")
|
||||
->setMultiOptions($stream_types)
|
||||
->setValue($setting[$prefix.'_type'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($type);
|
||||
|
||||
$bitrate = new Zend_Form_Element_Select('bitrate');
|
||||
$bitrate->setLabel("Bitrate:")
|
||||
->setMultiOptions($stream_bitrates)
|
||||
->setValue($setting[$prefix.'_bitrate'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($bitrate);
|
||||
|
||||
$output = new Zend_Form_Element_Select('output');
|
||||
$output->setLabel("Output to:")
|
||||
->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"Shoutcast"))
|
||||
->setValue($setting['output_'.$prefix])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($output);
|
||||
|
||||
$host = new Zend_Form_Element_Text('host');
|
||||
$host->setLabel("Server")
|
||||
->setValue($setting[$prefix.'_host'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($host);
|
||||
|
||||
$port = new Zend_Form_Element_Text('port');
|
||||
$port->setLabel("Port")
|
||||
->setValue($setting[$prefix.'_port'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($port);
|
||||
|
||||
$pass = new Zend_Form_Element_Text('pass');
|
||||
$pass->setLabel("Password")
|
||||
->setValue($setting[$prefix.'_pass'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($pass);
|
||||
|
||||
$genre = new Zend_Form_Element_Text('genre');
|
||||
$genre->setLabel("Genre:")
|
||||
->setValue($setting[$prefix.'_genre'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($genre);
|
||||
|
||||
$url = new Zend_Form_Element_Text('url');
|
||||
$url->setLabel("URL")
|
||||
->setValue($setting[$prefix.'_url'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($url);
|
||||
|
||||
$description = new Zend_Form_Element_Text('description');
|
||||
$description->setLabel("Description")
|
||||
->setValue($setting[$prefix.'_description'])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($description);
|
||||
|
||||
$mount_info = explode('.',$setting[$prefix.'_mount']);
|
||||
$mount = new Zend_Form_Element_Text('mount');
|
||||
$mount->class = "with-info";
|
||||
$mount->setLabel("Mount Point")
|
||||
->setValue($mount_info[0])
|
||||
->setDecorators(array('ViewHelper'));
|
||||
$this->addElement($mount);
|
||||
|
||||
$stream_url_value = "http://".$setting[$prefix.'_host'].":".$setting[$prefix.'_port']."/".$mount_info[0].".".$setting[$prefix.'_type'];
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "stream_url"=>$stream_url_value))
|
||||
));
|
||||
}
|
||||
|
||||
public function isValid ($data){
|
||||
$isValid = parent::isValid($data);
|
||||
if($data['enable'] == 1){
|
||||
if($data['host'] == ''){
|
||||
$element = $this->getElement("host");
|
||||
$element->addError("Server cannot be empty.");
|
||||
$isValid = false;
|
||||
}
|
||||
if($data['port'] == ''){
|
||||
$element = $this->getElement("port");
|
||||
$element->addError("Port cannot be empty.");
|
||||
$isValid = false;
|
||||
}
|
||||
if($data['pass'] == ''){
|
||||
$element = $this->getElement("pass");
|
||||
$element->addError("Password cannot be empty.");
|
||||
$isValid = false;
|
||||
}
|
||||
if($data['output'] == 'icecast'){
|
||||
if($data['mount'] == ''){
|
||||
$element = $this->getElement("mount");
|
||||
$element->addError("Mount cannot be empty with Icecast server.");
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
}
|
|
@ -377,5 +377,15 @@ class Application_Model_Preference
|
|||
public static function GetImportTimestamp(){
|
||||
return Application_Model_Preference::GetValue("import_timestamp");
|
||||
}
|
||||
|
||||
public static function GetStreamType(){
|
||||
$st = Application_Model_Preference::GetValue("stream_type");
|
||||
return explode(',', $st);
|
||||
}
|
||||
|
||||
public static function GetStreamBitrate(){
|
||||
$sb = Application_Model_Preference::GetValue("stream_bitrate");
|
||||
return explode(',', $sb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
class Application_Model_StreamSetting {
|
||||
public function __construct(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getStreamSetting(){
|
||||
global $CC_DBC;
|
||||
$sql = "SELECT *"
|
||||
|
@ -11,4 +12,32 @@ class Application_Model_StreamSetting {
|
|||
$rows = $CC_DBC->getAll($sql);
|
||||
return $rows;
|
||||
}
|
||||
public static function setStreamSetting($data){
|
||||
global $CC_DBC;
|
||||
foreach($data as $key=>$d){
|
||||
if($key == "output_sound_device"){
|
||||
$v = $d == 1?"true":"false";
|
||||
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
|
||||
$CC_DBC->query($sql);
|
||||
}
|
||||
else{
|
||||
$temp = explode('_', $key);
|
||||
$prefix = $temp[0];
|
||||
foreach($d as $k=>$v){
|
||||
$keyname = $prefix."_".$k;
|
||||
if( $k == 'output'){
|
||||
$keyname = $k."_".$prefix;
|
||||
if( $d["enable"] == 0){
|
||||
$v = 'disabled';
|
||||
}
|
||||
}
|
||||
if( $k == 'mount'){
|
||||
$v = $d['mount'].".".$d['type'];
|
||||
}
|
||||
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
|
||||
$CC_DBC->query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
$s_name = "s".$this->stream_number;
|
||||
?>
|
||||
<h3 class="collapsible-header"><span class="arrow-icon"></span>Stream <?php echo $this->stream_number?></h3>
|
||||
<div class="collapsible-content" id="<?=$s_name?>-config" style="display: block;">
|
||||
<fieldset class="padded">
|
||||
<dl class="zend_form clearfix">
|
||||
<dt id="<?=$s_name?>Enabled-label">
|
||||
<label for="<?=$s_name?>Enabled"><?php echo $this->element->getElement('enable')->getLabel() ?></label>
|
||||
</dt>
|
||||
<dd id="<?=$s_name?>Enabled-element">
|
||||
<?php echo $this->element->getElement('enable')?>
|
||||
</dd>
|
||||
|
||||
<dt id="<?=$s_name?>Type-label">
|
||||
<label for="<?=$s_name?>Type"><?php echo $this->element->getElement('type')->getLabel()?></label>
|
||||
</dt>
|
||||
<dd id="<?=$s_name?>Type-element">
|
||||
<?php echo $this->element->getElement('type')?>
|
||||
</dd>
|
||||
|
||||
<dt id="<?=$s_name?>Bitrate-label">
|
||||
<label for="<?=$s_name?>Bitrate"><?php echo $this->element->getElement('bitrate')->getLabel()?></label>
|
||||
</dt>
|
||||
<dd id="<?=$s_name?>Bitrate-element">
|
||||
<?php echo $this->element->getElement('bitrate')?>
|
||||
</dd>
|
||||
|
||||
<dt id="<?=$s_name?>Output-label">
|
||||
<label for="<?=$s_name?>Output"><?php echo $this->element->getElement('output')->getLabel()?></label>
|
||||
</dt>
|
||||
<dd id="<?=$s_name?>Output-element">
|
||||
<?php echo $this->element->getElement('output')?>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
<fieldset class="padded top-margin left-margin" id="output_setting">
|
||||
<dl class="zend_form">
|
||||
<dt id="outputServer-label" class="block-display">
|
||||
<label for="outputServer"><?php echo $this->element->getElement('host')->getLabel()?><span class="info-text-small">(Required)</span> :</label>
|
||||
</dt>
|
||||
<dd id="outputServer-element" class="block-display">
|
||||
<?php echo $this->element->getElement('host')?>
|
||||
<?php if($this->element->getElement('host')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('host')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt id="outputPort-label" class="block-display">
|
||||
<label for="outputPort"><?php echo $this->element->getElement('port')->getLabel()?><span class="info-text-small">(Required)</span> :</label>
|
||||
</dt>
|
||||
<dd id="outputPort-element" class="block-display">
|
||||
<?php echo $this->element->getElement('port')?>
|
||||
<?php if($this->element->getElement('port')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('port')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt id="outputPassword-label" class="block-display">
|
||||
<label class="optional" for="outputPassword"><?php echo $this->element->getElement('pass')->getLabel()?><span class="info-text-small">(Required)</span> :</label>
|
||||
</dt>
|
||||
<dd id="outputPassword-element" class="block-display clearfix">
|
||||
<?php echo $this->element->getElement('pass')?>
|
||||
<?php if($this->element->getElement('pass')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('pass')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt class="block-display info-block">
|
||||
The following info will be displayed to listeners in their media player:
|
||||
</dt>
|
||||
|
||||
<dt id="outputGenre-label" class="block-display">
|
||||
<label for="outputGenre"><?php echo $this->element->getElement('genre')->getLabel()?></label>
|
||||
</dt>
|
||||
<dd id="outputGenre-element" class="block-display">
|
||||
<?php echo $this->element->getElement('genre')?>
|
||||
<?php if($this->element->getElement('genre')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('genre')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt id="stationURL-label" class="block-display">
|
||||
<label for="stationURL"><?php echo $this->element->getElement('url')->getLabel()?><span class="info-text-small">(Your radio station website)</span> :</label>
|
||||
</dt>
|
||||
<dd id="stationURL-element" class="block-display clearfix">
|
||||
<?php echo $this->element->getElement('url')?>
|
||||
<?php if($this->element->getElement('url')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('url')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt id="stationDescription-label" class="block-display">
|
||||
<label for="stationDescription"><?php echo $this->element->getElement('description')->getLabel()?></label>
|
||||
</dt>
|
||||
<dd id="stationDescription-element" class="block-display clearfix">
|
||||
<?php echo $this->element->getElement('description')?>
|
||||
<?php if($this->element->getElement('description')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('description')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt id="outputMountpoint-label" class="block-display">
|
||||
<label for="outputMountpoint"><?php echo $this->element->getElement('mount')->getLabel()?><span class="info-text-small">(Your radio station website)</span> :</label>
|
||||
</dt>
|
||||
<dd id="outputMountpoint-element" class="block-display">
|
||||
<?php echo $this->element->getElement('mount')?><span id="mount_ext" class="input-info">.<?php echo $this->element->getElement('type')->getValue()?></span>
|
||||
<?php if($this->element->getElement('mount')->hasErrors()) : ?>
|
||||
<ul class='errors'>
|
||||
<?php foreach($this->element->getElement('mount')->getMessages() as $error): ?>
|
||||
<li><?php echo $error; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
<dt id="outputStreamURL-label" class="block-display">
|
||||
<label for="outputStreamURL">Stream URL: </label>
|
||||
</dt>
|
||||
<dd id="outputStreamURL-element" class="block-display">
|
||||
<p id="stream_url"><?php echo $this->stream_url?></p>
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
</div>
|
|
@ -1,4 +1,25 @@
|
|||
<div id="stream-setting-section" class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong manage-folders">
|
||||
<h2>Stream Setting</h2>
|
||||
<?php echo $this->form; ?>
|
||||
</div>
|
||||
<div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong stream-config">
|
||||
<h2>Stream configuration</h2>
|
||||
<?php echo $this->statusMsg;?>
|
||||
<form method="post" action="/Preference/stream-setting" enctype="application/x-www-form-urlencoded">
|
||||
<fieldset class="padded">
|
||||
<legend>Hardware Audio Out</legend>
|
||||
<dl class="zend_form">
|
||||
<dt id="hardwareOut-label" class="block-display" style="display:none;"></dt>
|
||||
<dd id="hardwareOut-element" class="block-display">
|
||||
<label class="required" for="EnableHardwareOut">
|
||||
<?php echo $this->form->getElement('output_sound_device')->getLabel() ?></label>
|
||||
<?php echo $this->form->getElement('output_sound_device') ?>
|
||||
</dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
<?php
|
||||
for($i=1;$i<=$this->num_stream;$i++){
|
||||
echo $this->form->getSubform("s".$i."_subform");
|
||||
}
|
||||
?>
|
||||
<div class="button-bar bottom" id="submit-element">
|
||||
<input type="submit" class="ui-button ui-state-default right-floated" value="Save" id="Save" name="Save" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue