diff --git a/application/Bootstrap.php b/application/Bootstrap.php index 52c0a8d11..709a7ff29 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -73,7 +73,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap protected function _initTitle(){ $view = $this->getResource('view'); - $view->headTitle(Application_Model_Preference::GetStationName()); + $view->headTitle(Application_Model_Preference::GetHeadTitle()); } } diff --git a/application/configs/ACL.php b/application/configs/ACL.php index 6800e806b..aeebc0147 100644 --- a/application/configs/ACL.php +++ b/application/configs/ACL.php @@ -32,7 +32,7 @@ $ccAcl->allow('guest', 'index') ->allow('guest', 'api') ->allow('host', 'plupload') ->allow('host', 'playlist') - ->allow('host', 'sideplaylist') + ->allow('host', 'sideplaylist') ->allow('host', 'schedule') ->allow('admin', 'user') ->allow('admin', 'preference'); diff --git a/application/configs/navigation.php b/application/configs/navigation.php index 9b7676553..56cd97696 100644 --- a/application/configs/navigation.php +++ b/application/configs/navigation.php @@ -49,50 +49,27 @@ $pages = array( 'action' => 'plupload', 'resource' => 'plupload' ), - array( - 'label' => 'Configure', - 'uri' => 'javascript:void(null)', - 'pages' => array( - array( - 'label' => 'Preferences', - 'module' => 'default', - 'controller' => 'Preference' - ), - array( - 'label' => 'Manage Users', - 'module' => 'default', - 'controller' => 'user', - 'action' => 'add-user', - 'resource' => 'user' - ) - ) - ) - /* - array( - 'label' => 'Media Library', - 'module' => 'default', - 'controller' => 'Library', - 'action' => 'index', - 'resource' => 'library', - 'pages' => array( - array( - 'label' => 'Add Audio', - 'module' => 'default', - 'controller' => 'Plupload', - 'action' => 'plupload', - 'resource' => 'plupload' - ), - array( - 'label' => 'Search (not working right now)', - 'module' => 'default', - 'controller' => 'Search', - 'action' => 'index', - 'resource' => 'search' - ) - ) - ) - */ + array( + 'label' => 'Configure', + 'uri' => 'javascript:void(null)', + 'resource' => 'preference', + 'pages' => array( + array( + 'label' => 'Preferences', + 'module' => 'default', + 'controller' => 'Preference' + ), + array( + 'label' => 'Manage Users', + 'module' => 'default', + 'controller' => 'user', + 'action' => 'add-user', + 'resource' => 'user' + ) + ) + ) ); + // Create container from array $container = new Zend_Navigation($pages); diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php index 07fd3ad48..ccd52d962 100644 --- a/application/controllers/PreferenceController.php +++ b/application/controllers/PreferenceController.php @@ -27,12 +27,10 @@ class PreferenceController extends Zend_Controller_Action $this->view->form = $form; return $this->render('index'); //render the phtml file } - - $auth = Zend_Auth::getInstance(); - $id = $auth->getIdentity()->id; - + $values = $form->getValues(); - Application_Model_Preference::UpdateStationName($values["stationName"], $id); + Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); + $this->view->form = $form; } diff --git a/application/forms/Preferences.php b/application/forms/Preferences.php index 32d59bded..152468842 100644 --- a/application/forms/Preferences.php +++ b/application/forms/Preferences.php @@ -12,7 +12,8 @@ class Application_Form_Preferences extends Zend_Form 'label' => 'Station Name:', 'required' => true, 'filters' => array('StringTrim'), - 'validators' => array('NotEmpty') + 'validators' => array('NotEmpty'), + 'value' => Application_Model_Preference::GetValue("station_name") )); /* diff --git a/application/models/Preference.php b/application/models/Preference.php index e56d006aa..a330db6e2 100644 --- a/application/models/Preference.php +++ b/application/models/Preference.php @@ -3,42 +3,69 @@ class Application_Model_Preference { - public static function UpdateStationName($name, $id){ + public static function SetValue($key, $value, $id){ global $CC_CONFIG, $CC_DBC; //Check if key already exists $sql = "SELECT COUNT(*) FROM cc_pref" - ." WHERE keystr = 'station_name'"; + ." WHERE keystr = '$key'"; $result = $CC_DBC->GetOne($sql); if ($result == 1){ $sql = "UPDATE cc_pref" - ." SET subjid = $id, valstr = '$name'" - ." WHERE keystr = 'station_name'"; + ." SET subjid = $id, valstr = '$value'" + ." WHERE keystr = '$key'"; } else { $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" - ." VALUES ($id, 'station_name', '$name')"; + ." VALUES ($id, '$key', '$value')"; } return $CC_DBC->query($sql); } - public static function GetStationName(){ + public static function GetValue($key){ global $CC_CONFIG, $CC_DBC; //Check if key already exists $sql = "SELECT COUNT(*) FROM cc_pref" - ." WHERE keystr = 'station_name'"; + ." WHERE keystr = '$key'"; $result = $CC_DBC->GetOne($sql); if ($result == 0) return "Airtime"; else { $sql = "SELECT valstr FROM cc_pref" - ." WHERE keystr = 'station_name'"; + ." WHERE keystr = '$key'"; $result = $CC_DBC->GetOne($sql); - return $result." - Airtime"; + return $result; } } + + public static function GetHeadTitle(){ + /* Caches the title name as a session variable so we dont access + * the database on every page load. */ + $defaultNamespace = new Zend_Session_Namespace('title_name'); + if (isset($defaultNamespace->title)) { + $title = $defaultNamespace->title; + } else { + $title = Application_Model_Preference::GetValue("station_name"); + $defaultNamespace->title = $title; + } + return $title." - Airtime"; + } + + public static function SetHeadTitle($title, $view){ + $auth = Zend_Auth::getInstance(); + $id = $auth->getIdentity()->id; + + Application_Model_Preference::SetValue("station_name", $title, $id); + $defaultNamespace = new Zend_Session_Namespace('title_name'); + $defaultNamespace->title = $title; + + //set session variable to new station name so that html title is updated. + //should probably do this in a view helper to keep this controller as minimal as possible. + $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject + $view->headTitle(Application_Model_Preference::GetHeadTitle()); + } }