CC-1942: Add ability to set timezone in preferences

-Can change the timezone for PHP. Need to change for python as well.
This commit is contained in:
martin 2011-08-12 14:14:07 -04:00
parent 13285fdd63
commit 84ec62eeca
9 changed files with 144 additions and 21 deletions

View file

@ -6,10 +6,6 @@ require_once __DIR__."/configs/ACL.php";
require_once 'propel/runtime/lib/Propel.php';
Propel::init(__DIR__."/configs/airtime-conf.php");
//DateTime in PHP 5.3.0+ need a default timezone set.
$tz = ini_get('date.timezone') ? ini_get('date.timezone') : 'UTC';
date_default_timezone_set($tz);
require_once __DIR__."/logging/Logging.php";
require_once __DIR__."/configs/constants.php";
require_once __DIR__."/configs/conf.php";
@ -26,22 +22,6 @@ require_once 'RabbitMq.php';
require_once 'DateHelper.php';
require_once __DIR__.'/controllers/plugins/RabbitMqPlugin.php';
global $CC_CONFIG, $CC_DBC;
$dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, FALSE);
if (PEAR::isError($CC_DBC)) {
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
exit(1);
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
Logging::setLogPath('/var/log/airtime/zendphp.log');
Zend_Validate::setDefaultNamespaces("Zend");
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new RabbitMqPlugin());
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
@ -89,6 +69,29 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view = $this->getResource('view');
$view->headTitle(Application_Model_Preference::GetHeadTitle());
}
protected function _initDbConnection(){
global $CC_CONFIG, $CC_DBC;
$dsn = $CC_CONFIG['dsn'];
$CC_DBC = DB::connect($dsn, FALSE);
if (PEAR::isError($CC_DBC)) {
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
exit(1);
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
//DateTime in PHP 5.3.0+ need a default timezone set.
date_default_timezone_set(Application_Model_Preference::GetTimezone());
}
protected function _initMisc(){
Logging::setLogPath('/var/log/airtime/zendphp.log');
Zend_Validate::setDefaultNamespaces("Zend");
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new RabbitMqPlugin());
}
}

View file

@ -35,6 +35,7 @@ class PreferenceController extends Zend_Controller_Action
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::SetDoSoundCloudUpload($values["preferences_soundcloud"]["UseSoundCloud"]);
Application_Model_Preference::SetSoundCloudUser($values["preferences_soundcloud"]["SoundCloudUser"]);

View file

@ -58,7 +58,38 @@ 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");
$timezone->setMultiOptions($this->getTimezones());
$timezone->setValue(Application_Model_Preference::GetTimezone());
$timezone->setDecorators(array('ViewHelper'));
$this->addElement($timezone);
}
private function getTimezones(){
$regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Aisa' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC
);
$tzlist = array();
foreach ($regions as $name => $mask){
$ids = DateTimeZone::listIdentifiers($mask);
foreach ($ids as $id){
$tzlist[$id] = str_replace("_", " ", $id);
}
}
return $tzlist;
}

View file

@ -260,6 +260,14 @@ class Application_Model_Preference
public static function GetStationDescription(){
return Application_Model_Preference::GetValue("description");
}
public static function SetTimezone($timezone){
Application_Model_Preference::SetValue("timezone", $timezone);
}
public static function GetTimezone(){
return Application_Model_Preference::GetValue("timezone");
}
public static function SetStationLogo($imagePath){
if(!empty($imagePath)){

View file

@ -75,5 +75,20 @@
</ul>
<?php endif; ?>
</dd>
<dt id="timezone-label" class="block-display">
<label class="required" for="timezone"><?php echo $this->element->getElement('timezone')->getLabel() ?>
<span class="info-text-small">(Required)</span> :
</label>
</dt>
<dd id="timezone-element" class="block-display">
<?php echo $this->element->getElement('timezone') ?>
<?php if($this->element->getElement('timezone')->hasErrors()) : ?>
<ul class='errors'>
<?php foreach($this->element->getElement('timezone')->getMessages() as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</dd>
</dl>
</fieldset>