-added simple configuration page

-implemented CC-1830
-issue CC-1850 closed
This commit is contained in:
mkonecny 2011-02-03 17:51:35 -05:00
parent 1e23907df1
commit df675bd8c6
15 changed files with 179 additions and 9 deletions

View file

@ -84,6 +84,10 @@
<actionMethod actionName="getDataGridData"/>
<actionMethod actionName="livestream"/>
</controllerFile>
<controllerFile controllerName="Preference">
<actionMethod actionName="index"/>
<actionMethod actionName="update"/>
</controllerFile>
</controllersDirectory>
<formsDirectory>
<formFile formName="Login"/>
@ -100,10 +104,12 @@
<formFile formName="AddShowStyle"/>
<formFile formName="AddShowWhat"/>
<formFile formName="AddShowRepeats"/>
<formFile formName="Preferences"/>
</formsDirectory>
<layoutsDirectory enabled="false"/>
<modelsDirectory>
<modelFile modelName="Nowplaying"/>
<modelFile modelName="Preference"/>
</modelsDirectory>
<modulesDirectory enabled="false"/>
<viewsDirectory>
@ -270,6 +276,12 @@
<viewControllerScriptsDirectory forControllerName="Schedule">
<viewScriptFile forActionName="showContentDialog"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Preference">
<viewScriptFile forActionName="index"/>
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Preference">
<viewScriptFile forActionName="update"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/>
@ -313,6 +325,7 @@
<testApplicationControllerFile filesystemName="ApiControllerTest.php"/>
<testApplicationControllerFile filesystemName="UserControllerTest.php"/>
<testApplicationControllerFile filesystemName="NowplayingControllerTest.php"/>
<testApplicationControllerFile filesystemName="PreferenceControllerTest.php"/>
</testApplicationControllerDirectory>
</testApplicationDirectory>
<testLibraryDirectory>

View file

@ -64,9 +64,16 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
$view->headScript()->appendFile('/js/airtime/common/common.js','text/javascript');
}
//TODO: Find better place to put this in.
protected function _initViewHelpers(){
$view = $this->getResource('view');
$view->addHelperPath('../application/views/helpers', 'Airtime_View_Helper');
}
protected function _initTitle(){
$view = $this->getResource('view');
$view->headTitle(Application_Model_Preference::GetStationName());
}
}

View file

@ -19,7 +19,8 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
->add(new Zend_Acl_Resource('schedule'))
->add(new Zend_Acl_Resource('api'))
->add(new Zend_Acl_Resource('nowplaying'))
->add(new Zend_Acl_Resource('search'));
->add(new Zend_Acl_Resource('search'))
->add(new Zend_Acl_Resource('preference'));
/** Creating permissions */
$ccAcl->allow('guest', 'index')
@ -33,7 +34,8 @@ $ccAcl->allow('guest', 'index')
->allow('host', 'playlist')
->allow('host', 'sideplaylist')
->allow('host', 'schedule')
->allow('admin', 'user');
->allow('admin', 'user')
->allow('admin', 'preference');
$aclPlugin = new Zend_Controller_Plugin_Acl($ccAcl);

View file

@ -56,7 +56,7 @@ $pages = array(
array(
'label' => 'Preferences',
'module' => 'default',
'controller' => 'Nowplaying'
'controller' => 'Preference'
),
array(
'label' => 'Manage Users',

View file

@ -0,0 +1,43 @@
<?php
class PreferenceController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$form = new Application_Form_Preferences();
$this->view->form = $form;
}
public function updateAction()
{
$request = $this->getRequest();
if (!$this->getRequest()->isPost()) {
return $this->_forward('Preference/index');
}
$form = new Application_Form_Preferences();
if (!$form->isValid($request->getPost())) {
// Failed validation; redisplay form
$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);
$this->view->form = $form;
}
}

View file

@ -0,0 +1,34 @@
<?php
class Application_Form_Preferences extends Zend_Form
{
public function init()
{
$this->setAction('/Preference/update')->setMethod('post');
// Add login element
$this->addElement('text', 'stationName', array(
'label' => 'Station Name:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('NotEmpty')
));
/*
$this->addElement('select', 'test', array(
'label' => 'Live Stream Button: ',
'multiOptions' => array(
"e" => "enabled",
"d" => "disabled"
))
);
*/
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Submit',
));
}
}

View file

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Airtime</title>
<?php echo $this->headTitle() ?>
<?php echo $this->headScript() ?>
<?php echo $this->headLink() ?>
</head>

View file

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Airtime</title>
<?php echo $this->headTitle() ?>
<?php echo $this->headScript() ?>
<?php echo $this->headLink() ?>
</head>

View file

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Airtime</title>
<?php echo $this->headTitle() ?>
<?php echo $this->headScript() ?>
<?php echo $this->headLink() ?>
</head>

View file

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Airtime</title>
<?php echo $this->headTitle() ?>
<?php echo $this->headScript() ?>
<?php echo $this->headLink() ?>
</head>

View file

@ -0,0 +1,44 @@
<?php
class Application_Model_Preference
{
public static function UpdateStationName($name, $id){
global $CC_CONFIG, $CC_DBC;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = 'station_name'";
$result = $CC_DBC->GetOne($sql);
if ($result == 1){
$sql = "UPDATE cc_pref"
." SET subjid = $id, valstr = '$name'"
." WHERE keystr = 'station_name'";
} else {
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, 'station_name', '$name')";
}
return $CC_DBC->query($sql);
}
public static function GetStationName(){
global $CC_CONFIG, $CC_DBC;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = 'station_name'";
$result = $CC_DBC->GetOne($sql);
if ($result == 0)
return "Airtime";
else {
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = 'station_name'";
$result = $CC_DBC->GetOne($sql);
return $result." - Airtime";
}
}
}

View file

@ -0,0 +1,3 @@
<?php
echo $this->form;
?>

View file

@ -0,0 +1,4 @@
Preferences Updated.
<?php
echo $this->form;
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 949 B

View file

@ -0,0 +1,20 @@
<?php
require_once 'PHPUnit/Framework/TestCase.php';
class PreferenceControllerTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
/* Setup Routine */
}
public function tearDown()
{
/* Tear Down Routine */
}
}