2011-02-03 23:51:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Application_Model_Preference
|
|
|
|
{
|
|
|
|
|
2011-02-05 22:00:05 +01:00
|
|
|
public static function SetValue($key, $value){
|
2011-02-03 23:51:35 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
2011-02-05 22:00:05 +01:00
|
|
|
|
2011-04-04 06:02:35 +02:00
|
|
|
//called from a daemon process
|
|
|
|
if(!Zend_Auth::getInstance()->hasIdentity()) {
|
|
|
|
$id = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
$id = $auth->getIdentity()->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = pg_escape_string($key);
|
|
|
|
$value = pg_escape_string($value);
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-03 23:51:35 +01:00
|
|
|
//Check if key already exists
|
|
|
|
$sql = "SELECT COUNT(*) FROM cc_pref"
|
2011-02-04 01:17:52 +01:00
|
|
|
." WHERE keystr = '$key'";
|
2011-02-03 23:51:35 +01:00
|
|
|
$result = $CC_DBC->GetOne($sql);
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-04-04 06:02:35 +02:00
|
|
|
if ($result == 1 && is_null($id)){
|
|
|
|
$sql = "UPDATE cc_pref"
|
|
|
|
." SET subjid = NULL, valstr = '$value'"
|
|
|
|
." WHERE keystr = '$key'";
|
|
|
|
}
|
|
|
|
else if ($result == 1 && !is_null($id)){
|
2011-02-03 23:51:35 +01:00
|
|
|
$sql = "UPDATE cc_pref"
|
2011-02-04 01:17:52 +01:00
|
|
|
." SET subjid = $id, valstr = '$value'"
|
2011-03-23 23:16:08 +01:00
|
|
|
." WHERE keystr = '$key'";
|
2011-04-04 06:02:35 +02:00
|
|
|
}
|
|
|
|
else if(is_null($id)) {
|
|
|
|
$sql = "INSERT INTO cc_pref (keystr, valstr)"
|
|
|
|
." VALUES ('$key', '$value')";
|
|
|
|
}
|
|
|
|
else {
|
2011-02-03 23:51:35 +01:00
|
|
|
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
|
2011-02-04 01:17:52 +01:00
|
|
|
." VALUES ($id, '$key', '$value')";
|
2011-02-03 23:51:35 +01:00
|
|
|
}
|
|
|
|
return $CC_DBC->query($sql);
|
|
|
|
}
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-04 01:17:52 +01:00
|
|
|
public static function GetValue($key){
|
2011-02-03 23:51:35 +01:00
|
|
|
global $CC_CONFIG, $CC_DBC;
|
|
|
|
//Check if key already exists
|
|
|
|
$sql = "SELECT COUNT(*) FROM cc_pref"
|
2011-02-04 01:17:52 +01:00
|
|
|
." WHERE keystr = '$key'";
|
2011-02-03 23:51:35 +01:00
|
|
|
$result = $CC_DBC->GetOne($sql);
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-03 23:51:35 +01:00
|
|
|
if ($result == 0)
|
2011-02-04 01:22:17 +01:00
|
|
|
return "";
|
2011-02-03 23:51:35 +01:00
|
|
|
else {
|
|
|
|
$sql = "SELECT valstr FROM cc_pref"
|
2011-02-04 01:17:52 +01:00
|
|
|
." WHERE keystr = '$key'";
|
2011-02-03 23:51:35 +01:00
|
|
|
$result = $CC_DBC->GetOne($sql);
|
2011-02-04 01:17:52 +01:00
|
|
|
return $result;
|
2011-02-03 23:51:35 +01:00
|
|
|
}
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-03 23:51:35 +01:00
|
|
|
}
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-04 01:17:52 +01:00
|
|
|
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;
|
|
|
|
}
|
2011-02-04 01:22:17 +01:00
|
|
|
if (strlen($title) > 0)
|
|
|
|
$title .= " - ";
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-04 01:22:17 +01:00
|
|
|
return $title."Airtime";
|
2011-02-04 01:17:52 +01:00
|
|
|
}
|
2011-03-23 23:16:08 +01:00
|
|
|
|
2011-02-04 01:17:52 +01:00
|
|
|
public static function SetHeadTitle($title, $view){
|
2011-03-23 23:16:08 +01:00
|
|
|
Application_Model_Preference::SetValue("station_name", $title);
|
|
|
|
$defaultNamespace = new Zend_Session_Namespace('title_name');
|
2011-02-04 01:17:52 +01:00
|
|
|
$defaultNamespace->title = $title;
|
2011-03-23 23:16:08 +01:00
|
|
|
RabbitMq::PushSchedule();
|
|
|
|
|
2011-02-04 01:17:52 +01:00
|
|
|
//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());
|
|
|
|
}
|
2011-02-03 23:51:35 +01:00
|
|
|
|
2011-03-23 23:16:08 +01:00
|
|
|
public static function SetShowsPopulatedUntil($timestamp) {
|
|
|
|
Application_Model_Preference::SetValue("shows_populated_until", $timestamp);
|
2011-02-05 22:00:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetShowsPopulatedUntil() {
|
|
|
|
return Application_Model_Preference::GetValue("shows_populated_until");
|
|
|
|
}
|
|
|
|
|
2011-03-23 23:16:08 +01:00
|
|
|
public static function SetDefaultFade($fade) {
|
|
|
|
Application_Model_Preference::SetValue("default_fade", $fade);
|
2011-02-11 23:46:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetDefaultFade() {
|
|
|
|
return Application_Model_Preference::GetValue("default_fade");
|
|
|
|
}
|
|
|
|
|
2011-03-04 18:07:22 +01:00
|
|
|
public static function SetStreamLabelFormat($type){
|
|
|
|
Application_Model_Preference::SetValue("stream_label_format", $type);
|
2011-03-23 23:16:08 +01:00
|
|
|
RabbitMq::PushSchedule();
|
2011-03-04 18:07:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetStreamLabelFormat(){
|
|
|
|
return Application_Model_Preference::getValue("stream_label_format");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetStationName(){
|
|
|
|
return Application_Model_Preference::getValue("station_name");
|
|
|
|
}
|
2011-03-18 22:15:12 +01:00
|
|
|
|
2011-03-23 23:16:08 +01:00
|
|
|
public static function SetDoSoundCloudUpload($upload) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_upload", $upload);
|
2011-03-18 22:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetDoSoundCloudUpload() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_upload");
|
|
|
|
}
|
|
|
|
|
2011-03-23 23:16:08 +01:00
|
|
|
public static function SetSoundCloudUser($user) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_user", $user);
|
2011-03-18 22:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetSoundCloudUser() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_user");
|
|
|
|
}
|
|
|
|
|
2011-03-23 23:16:08 +01:00
|
|
|
public static function SetSoundCloudPassword($password) {
|
2011-03-31 23:30:50 +02:00
|
|
|
if (strlen($password) > 0)
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_password", $password);
|
2011-03-18 22:15:12 +01:00
|
|
|
}
|
|
|
|
|
2011-03-21 20:48:44 +01:00
|
|
|
public static function GetSoundCloudPassword() {
|
2011-03-18 22:15:12 +01:00
|
|
|
return Application_Model_Preference::GetValue("soundcloud_password");
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:39:01 +02:00
|
|
|
public static function SetSoundCloudTags($tags) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_tags", $tags);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetSoundCloudTags() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_tags");
|
|
|
|
}
|
|
|
|
|
2011-04-02 22:33:45 +02:00
|
|
|
public static function SetSoundCloudGenre($genre) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_genre", $genre);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetSoundCloudGenre() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_genre");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function SetSoundCloudTrackType($track_type) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_tracktype", $track_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetSoundCloudTrackType() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_tracktype");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function SetSoundCloudLicense($license) {
|
|
|
|
Application_Model_Preference::SetValue("soundcloud_license", $license);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetSoundCloudLicense() {
|
|
|
|
return Application_Model_Preference::GetValue("soundcloud_license");
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:34:35 +02:00
|
|
|
public static function SetAllow3rdPartyApi($bool) {
|
|
|
|
Application_Model_Preference::SetValue("third_party_api", $bool);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function GetAllow3rdPartyApi() {
|
|
|
|
$val = Application_Model_Preference::GetValue("third_party_api");
|
|
|
|
if (strlen($val) == 0){
|
|
|
|
return "0";
|
|
|
|
} else {
|
|
|
|
return $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 23:51:35 +01:00
|
|
|
}
|
|
|
|
|