From df675bd8c6cdd660f5896f102bb99b102f165c03 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Thu, 3 Feb 2011 17:51:35 -0500 Subject: [PATCH] -added simple configuration page -implemented CC-1830 -issue CC-1850 closed --- .zfproject.xml | 13 ++++++ application/Bootstrap.php | 11 ++++- application/configs/ACL.php | 6 ++- application/configs/navigation.php | 2 +- .../controllers/PreferenceController.php | 43 +++++++++++++++++ application/forms/Preferences.php | 34 ++++++++++++++ application/layouts/scripts/layout.phtml | 2 +- application/layouts/scripts/library.phtml | 2 +- application/layouts/scripts/login.phtml | 2 +- application/layouts/scripts/search.phtml | 2 +- application/models/Preference.php | 44 ++++++++++++++++++ .../views/scripts/preference/index.phtml | 3 ++ .../views/scripts/preference/update.phtml | 4 ++ .../images/schedule-show_progressbar_bg.png | Bin 0 -> 949 bytes .../controllers/PreferenceControllerTest.php | 20 ++++++++ 15 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 application/controllers/PreferenceController.php create mode 100644 application/forms/Preferences.php create mode 100644 application/models/Preference.php create mode 100644 application/views/scripts/preference/index.phtml create mode 100644 application/views/scripts/preference/update.phtml create mode 100644 public/css/images/schedule-show_progressbar_bg.png create mode 100644 tests/application/controllers/PreferenceControllerTest.php diff --git a/.zfproject.xml b/.zfproject.xml index 873f96251..c849f233f 100644 --- a/.zfproject.xml +++ b/.zfproject.xml @@ -84,6 +84,10 @@ + + + + @@ -100,10 +104,12 @@ + + @@ -270,6 +276,12 @@ + + + + + + @@ -313,6 +325,7 @@ + diff --git a/application/Bootstrap.php b/application/Bootstrap.php index cce62ae14..52c0a8d11 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -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()); + } } diff --git a/application/configs/ACL.php b/application/configs/ACL.php index 092957d14..6800e806b 100644 --- a/application/configs/ACL.php +++ b/application/configs/ACL.php @@ -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); diff --git a/application/configs/navigation.php b/application/configs/navigation.php index 42f9f447c..9b7676553 100644 --- a/application/configs/navigation.php +++ b/application/configs/navigation.php @@ -56,7 +56,7 @@ $pages = array( array( 'label' => 'Preferences', 'module' => 'default', - 'controller' => 'Nowplaying' + 'controller' => 'Preference' ), array( 'label' => 'Manage Users', diff --git a/application/controllers/PreferenceController.php b/application/controllers/PreferenceController.php new file mode 100644 index 000000000..07fd3ad48 --- /dev/null +++ b/application/controllers/PreferenceController.php @@ -0,0 +1,43 @@ +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; + } + + +} + + + diff --git a/application/forms/Preferences.php b/application/forms/Preferences.php new file mode 100644 index 000000000..32d59bded --- /dev/null +++ b/application/forms/Preferences.php @@ -0,0 +1,34 @@ +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', + )); + } +} + diff --git a/application/layouts/scripts/layout.phtml b/application/layouts/scripts/layout.phtml index 4c694de6e..d08fb0020 100644 --- a/application/layouts/scripts/layout.phtml +++ b/application/layouts/scripts/layout.phtml @@ -3,7 +3,7 @@ - Airtime + headTitle() ?> headScript() ?> headLink() ?> diff --git a/application/layouts/scripts/library.phtml b/application/layouts/scripts/library.phtml index 1ed4618a2..9af9fdc21 100644 --- a/application/layouts/scripts/library.phtml +++ b/application/layouts/scripts/library.phtml @@ -3,7 +3,7 @@ - Airtime + headTitle() ?> headScript() ?> headLink() ?> diff --git a/application/layouts/scripts/login.phtml b/application/layouts/scripts/login.phtml index cf47b1b82..512da3aa9 100644 --- a/application/layouts/scripts/login.phtml +++ b/application/layouts/scripts/login.phtml @@ -3,7 +3,7 @@ - Airtime + headTitle() ?> headScript() ?> headLink() ?> diff --git a/application/layouts/scripts/search.phtml b/application/layouts/scripts/search.phtml index c98c352a6..8704c615a 100644 --- a/application/layouts/scripts/search.phtml +++ b/application/layouts/scripts/search.phtml @@ -3,7 +3,7 @@ - Airtime + headTitle() ?> headScript() ?> headLink() ?> diff --git a/application/models/Preference.php b/application/models/Preference.php new file mode 100644 index 000000000..e56d006aa --- /dev/null +++ b/application/models/Preference.php @@ -0,0 +1,44 @@ +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"; + } + + } + +} + diff --git a/application/views/scripts/preference/index.phtml b/application/views/scripts/preference/index.phtml new file mode 100644 index 000000000..c7fd9eb7e --- /dev/null +++ b/application/views/scripts/preference/index.phtml @@ -0,0 +1,3 @@ +form; +?> diff --git a/application/views/scripts/preference/update.phtml b/application/views/scripts/preference/update.phtml new file mode 100644 index 000000000..63d962812 --- /dev/null +++ b/application/views/scripts/preference/update.phtml @@ -0,0 +1,4 @@ +Preferences Updated. +form; +?> diff --git a/public/css/images/schedule-show_progressbar_bg.png b/public/css/images/schedule-show_progressbar_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..b1d7b3bc7f5e89f4a69cb7b89f68e8b44545b1af GIT binary patch literal 949 zcmaJ=zi-n(6gG4yis-}y)5%?leYW$Xw>8>`+T}5+#nBB~l#UC9x9wjC~8H@SdsWAy0EYy&S{)75G2fJwX@++=!+yU^NKJD9Annwb`%`ie5 zM2yXGwX-yGy&0xpgeQKe^S7VB@W4kpe_ghr9o6yFzg)+-yKXw(dgiH!KRX4rRAT}G zrY=Z>d6;Oa&Tn)zcFxQq4>k}w)A_rg`gR-CNsK{RfJF~hAgD-!q?D@F>T@7N35rk_ zCAlb7HAU7S1lx~i-eNS?I!0sbi`{g7N@=8t;&QnZmWn{)i72V6nrX;#ks*r7Dx_{& z43pzr!N7?Z`w{g?2r@-?L>5%%S)_L<1kp}5Ot#O&9!yN#NR$MarIZ70`~T1&*r5~J z!T0h0Q#f%}5f(c*A&b~!g&QAdt|F}-W0#WHA!MGvVtYy`Nv0$M^==tl`ynFBWP`SC z%?cChh90&Ioo9T(_mQTUifT5@l5CVzNiyLHG%BWI$go~5*H0=JIoBZGBETWdx#*r- z-pkDzA&8h~1IPX=j2bZsz$RhM-ye&-S8vNj`(sh|azz%5n3eUfGUq1NJK1s9wCu8L zdmOS}k6BZH`gIK1Ks;_=IVM7AFc|cDy;iIB?nA+1_9vEc?xa6P!|`x5L^ls_I5ve2 UcX<2r+dLa2%WN7SFNUxG0ADsD9smFU literal 0 HcmV?d00001 diff --git a/tests/application/controllers/PreferenceControllerTest.php b/tests/application/controllers/PreferenceControllerTest.php new file mode 100644 index 000000000..41bb531eb --- /dev/null +++ b/tests/application/controllers/PreferenceControllerTest.php @@ -0,0 +1,20 @@ +