-title now stored in session variable.

This commit is contained in:
mkonecny 2011-02-03 19:17:52 -05:00
parent df675bd8c6
commit 4698e963c1
6 changed files with 63 additions and 60 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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")
));
/*

View file

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