From 3cd11c696f54e0d7f9c9401fad65f0f424c06ef8 Mon Sep 17 00:00:00 2001
From: Naomi Aro <naomiaro@gmail.com>
Date: Tue, 13 Dec 2011 12:10:25 +0100
Subject: [PATCH] CC-3184 : Preferences: "Stream Label" needs to be moved to
 "Stream Settings"->"Global"

---
 .../controllers/PreferenceController.php      | 14 +++++-----
 .../application/forms/GeneralPreferences.php  | 27 +++++++------------
 .../application/forms/StreamSetting.php       | 27 ++++++++++++-------
 .../scripts/form/preferences_general.phtml    | 27 ++-----------------
 .../scripts/preference/stream-setting.phtml   | 25 ++++++++++++++++-
 5 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php
index 54a5ef8f4..88ceca045 100644
--- a/airtime_mvc/application/controllers/PreferenceController.php
+++ b/airtime_mvc/application/controllers/PreferenceController.php
@@ -33,7 +33,6 @@ class PreferenceController extends Zend_Controller_Action
 
                 Application_Model_Preference::SetHeadTitle($values["preferences_general"]["stationName"], $this->view);
                 Application_Model_Preference::SetDefaultFade($values["preferences_general"]["stationDefaultFade"]);
-                Application_Model_Preference::SetStreamLabelFormat($values["preferences_general"]["streamFormat"]);
                 Application_Model_Preference::SetAllow3rdPartyApi($values["preferences_general"]["thirdPartyApi"]);
                 Application_Model_Preference::SetTimezone($values["preferences_general"]["timezone"]);
                 Application_Model_Preference::SetWeekStartDay($values["preferences_general"]["weekStartDay"]);
@@ -64,9 +63,9 @@ class PreferenceController extends Zend_Controller_Action
         $this->view->statusMsg = "";
 
         $isSass = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
-        
+
         $form = new Application_Form_SupportSettings();
-        
+
         if ($request->isPost()) {
             $values = $request->getPost();
             if ($form->isValid($values)) {
@@ -165,10 +164,10 @@ class PreferenceController extends Zend_Controller_Action
 
         $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
         $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);
@@ -180,6 +179,7 @@ class PreferenceController extends Zend_Controller_Action
         }
         if ($request->isPost()) {
             $post_data = $request->getPost();
+
             $error = false;
             $values = array();
             for($i=1; $i<=$num_of_stream; $i++){
@@ -196,9 +196,11 @@ class PreferenceController extends Zend_Controller_Action
                 if(Application_Model_Preference::GetPlanLevel() == 'disabled'){// && $form->isValid($post_data['output_sound_device'])){
                     $values['output_sound_device'] = $form->getValue('output_sound_device');
                 }
+
                 
                 $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata');
                 $values['output_sound_device_type'] = $form->getValue('output_sound_device_type');
+
             }
             if(!$error){
                 Application_Model_StreamSetting::setStreamSetting($values);
@@ -303,7 +305,7 @@ class PreferenceController extends Zend_Controller_Action
         }
         die(json_encode($res));
     }
-    
+
     public function getLiquidsoapStatusAction(){
         $out = array();
         $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php
index 61b79dbc8..1514e1460 100644
--- a/airtime_mvc/application/forms/GeneralPreferences.php
+++ b/airtime_mvc/application/forms/GeneralPreferences.php
@@ -13,7 +13,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
         if($defaultFade == ""){
             $defaultFade = '00:00:00.000000';
         }
-        
+
         //Station name
         $this->addElement('text', 'stationName', array(
             'class'      => 'input_text',
@@ -25,7 +25,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
                 'ViewHelper'
             )
         ));
-        
+
         //Default station fade
         $this->addElement('text', 'stationDefaultFade', array(
             'class'      => 'input_text',
@@ -41,15 +41,6 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
             )
         ));
 
-        $stream_format = new Zend_Form_Element_Radio('streamFormat');
-        $stream_format->setLabel('Stream Label:');
-        $stream_format->setMultiOptions(array("Artist - Title",
-                                            "Show - Artist - Title",
-                                            "Station name - Show name"));
-        $stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat());
-        $stream_format->setDecorators(array('ViewHelper'));
-        $this->addElement($stream_format);
-
         $third_party_api = new Zend_Form_Element_Radio('thirdPartyApi');
         $third_party_api->setLabel('Allow Remote Websites To Access "Schedule" Info?<br> (Enable this to make front-end widgets work.)');
         $third_party_api->setMultiOptions(array("Disabled",
@@ -57,7 +48,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
         $third_party_api->setValue(Application_Model_Preference::GetAllow3rdPartyApi());
         $third_party_api->setDecorators(array('ViewHelper'));
         $this->addElement($third_party_api);
-        
+
         /* Form Element for setting the Timezone */
         $timezone = new Zend_Form_Element_Select("timezone");
         $timezone->setLabel("Timezone");
@@ -65,7 +56,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
         $timezone->setValue(Application_Model_Preference::GetTimezone());
         $timezone->setDecorators(array('ViewHelper'));
         $this->addElement($timezone);
-        
+
         /* Form Element for setting which day is the start of the week */
         $week_start_day = new Zend_Form_Element_Select("weekStartDay");
         $week_start_day->setLabel("Week Starts On");
@@ -74,7 +65,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
         $week_start_day->setDecorators(array('ViewHelper'));
         $this->addElement($week_start_day);
     }
-    
+
     private function getTimezones(){
         $regions = array(
             'Africa' => DateTimeZone::AFRICA,
@@ -86,9 +77,9 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
             'Indian' => DateTimeZone::INDIAN,
             'Pacific' => DateTimeZone::PACIFIC
         );
-        
+
         $tzlist = array();
-        
+
         foreach ($regions as $name => $mask){
             $ids = DateTimeZone::listIdentifiers($mask);
             foreach ($ids as $id){
@@ -98,7 +89,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
 
         return $tzlist;
     }
-    
+
 
     private function getWeekStartDays() {
     	$days = array(
@@ -110,7 +101,7 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
 		    'Friday',
 		    'Saturday'
     	);
-    	return $days;   	
+    	return $days;
     }
 }
 
diff --git a/airtime_mvc/application/forms/StreamSetting.php b/airtime_mvc/application/forms/StreamSetting.php
index b54a36393..9d5289ebf 100644
--- a/airtime_mvc/application/forms/StreamSetting.php
+++ b/airtime_mvc/application/forms/StreamSetting.php
@@ -25,7 +25,7 @@ class Application_Form_StreamSetting extends Zend_Form
                 $output_sound_device->setAttrib("readonly", true);
             }
             $this->addElement($output_sound_device);
-            
+
             $output_types = array("ALSA"=>"ALSA", "AO"=>"AO", "OSS"=>"OSS", "Portaudio"=>"Portaudio", "Pulseaudio"=>"Pulseaudio");
             $output_type = new Zend_Form_Element_Select('output_sound_device_type');
             $output_type->setLabel("Output Type")
@@ -37,15 +37,15 @@ class Application_Form_StreamSetting extends Zend_Form
             }
             $this->addElement($output_type);
         }
-        
+
         # tooltip
-        $description = 'VLC and mplayer have a serious bug when playing an OGG/VORBIS 
-                    stream that has metadata information enabled (stream metadata is the 
-                    track title, show name, etc displayed in the audio player): they will 
-                    disconnect from the stream after every song if this option is enabled. 
-                    If your listeners do not require support for these audio players, 
+        $description = 'VLC and mplayer have a serious bug when playing an OGG/VORBIS
+                    stream that has metadata information enabled (stream metadata is the
+                    track title, show name, etc displayed in the audio player): they will
+                    disconnect from the stream after every song if this option is enabled.
+                    If your listeners do not require support for these audio players,
                     then you should enable this option.';
-        
+
         $icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata');
         $icecast_vorbis_metadata->setLabel('Icecast Vorbis Metadata')
                                 ->setDescription($description)
@@ -56,11 +56,20 @@ class Application_Form_StreamSetting extends Zend_Form
             $icecast_vorbis_metadata->setAttrib("readonly", true);
         }
         $this->addElement($icecast_vorbis_metadata);
+
+        $stream_format = new Zend_Form_Element_Radio('streamFormat');
+        $stream_format->setLabel('Stream Label:');
+        $stream_format->setMultiOptions(array("Artist - Title",
+                                            "Show - Artist - Title",
+                                            "Station name - Show name"));
+        $stream_format->setValue(Application_Model_Preference::GetStreamLabelFormat());
+        $stream_format->setDecorators(array('ViewHelper'));
+        $this->addElement($stream_format);
     }
 
     public function isValid($data){
         $this->populate(array("output_sound_device"=>$data['output_sound_device'], "icecast_vorbis_metadata"=>$data['icecast_vorbis_metadata'],
-                                "output_sound_device_type"=>$data['output_sound_device_type']));
+                                "output_sound_device_type"=>$data['output_sound_device_type'], "streamFormat"=>$data['streamFormat']));
         return true;
     }
 }
diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml
index f8d7b23f7..12ec92df2 100644
--- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml
+++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml
@@ -27,29 +27,6 @@
                 </ul>
             <?php endif; ?>
         </dd>
-        <dt id="streamFormat-label" class="block-display">
-            <label class="optional"><?php echo $this->element->getElement('streamFormat')->getLabel() ?></label>
-        </dt>
-        <dd id="streamFormat-element" class="block-display radio-inline-list">
-            <?php $i=0;
-                  $value = $this->element->getElement('streamFormat')->getValue();
-            ?>
-            <?php foreach ($this->element->getElement('streamFormat')->getMultiOptions() as $radio) : ?>
-                <label for="streamFormat-<?php echo $i ?>">
-                    <input type="radio" value="<?php echo $i ?>" id="streamFormat-<?php echo $i ?>" name="streamFormat" <?php if($i == $value){echo 'checked="checked"';}?> >
-                        <?php echo $radio ?>
-                    </input>
-                </label>
-                <?php $i = $i + 1; ?>
-            <?php endforeach; ?>
-            <?php if($this->element->getElement('streamFormat')->hasErrors()) : ?>
-                <ul class='errors'>
-                    <?php foreach($this->element->getElement('streamFormat')->getMessages() as $error): ?>
-                        <li><?php echo $error; ?></li>
-                    <?php endforeach; ?>
-                </ul>
-            <?php endif; ?>
-        </dd>
         <dt id="thirdPartyApi-label" class="block-display">
             <label class="optional"><?php echo $this->element->getElement('thirdPartyApi')->getLabel() ?></label>
         </dt>
@@ -88,7 +65,7 @@
                 </ul>
             <?php endif; ?>
         </dd>
-        
+
         <!-- Week Start Day option -->
         <dt id="weekStartDay-label" class="block-display">
             <label class="required" for="timezone"><?php echo $this->element->getElement('weekStartDay')->getLabel() ?>:
@@ -106,7 +83,7 @@
                 <?php $i = $i + 1; ?>
             <?php endforeach; ?>
             </select>
-            
+
             <?php if($this->element->getElement('weekStartDay')->hasErrors()) : ?>
                 <ul class='errors'>
                     <?php foreach($this->element->getElement('weekStartDay')->getMessages() as $error): ?>
diff --git a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml
index 9b52e7194..d74b57079 100644
--- a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml
+++ b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml
@@ -31,7 +31,7 @@
         <?php } ?>
             <dt id="vorbisMetadata-label">
                 <label class="required">
-                    <?php echo $this->form->getElement('icecast_vorbis_metadata')->getLabel() ?> : 
+                    <?php echo $this->form->getElement('icecast_vorbis_metadata')->getLabel() ?> :
                     <span class='info-tooltip'>
                         <span>
                             <?php echo $this->form->getElement('icecast_vorbis_metadata')->getDescription() ?>
@@ -42,6 +42,29 @@
             <dd id="vorbisMetadata-element">
                 <?php echo $this->form->getElement('icecast_vorbis_metadata') ?>
             </dd>
+            <dt id="streamFormat-label" class="block-display">
+                <label class="optional"><?php echo $this->form->getElement('streamFormat')->getLabel() ?></label>
+            </dt>
+            <dd id="streamFormat-element" class="block-display radio-inline-list">
+                <?php $i=0;
+                      $value = $this->form->getElement('streamFormat')->getValue();
+                ?>
+                <?php foreach ($this->form->getElement('streamFormat')->getMultiOptions() as $radio) : ?>
+                    <label for="streamFormat-<?php echo $i ?>">
+                        <input type="radio" value="<?php echo $i ?>" id="streamFormat-<?php echo $i ?>" name="streamFormat" <?php if($i == $value){echo 'checked="checked"';}?> >
+                            <?php echo $radio ?>
+                        </input>
+                    </label>
+                    <?php $i = $i + 1; ?>
+                <?php endforeach; ?>
+                <?php if($this->form->getElement('streamFormat')->hasErrors()) : ?>
+                    <ul class='errors'>
+                        <?php foreach($this->form->getElement('streamFormat')->getMessages() as $error): ?>
+                            <li><?php echo $error; ?></li>
+                        <?php endforeach; ?>
+                    </ul>
+                <?php endif; ?>
+            </dd>
         </dl>
     </fieldset>
     <?php