Formatting; Changed tabs to spaces

This commit is contained in:
Duncan Sommerville 2014-11-05 17:04:18 -05:00
parent 273afaa126
commit 90626a2fcb
2 changed files with 81 additions and 98 deletions

View File

@ -5,7 +5,7 @@ class LocaleController extends Zend_Controller_Action
public function init() public function init()
{ {
} }
public function datatablesTranslationTableAction() public function datatablesTranslationTableAction()
{ {
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();

View File

@ -4,45 +4,44 @@ require_once 'Cache.php';
class Application_Model_Preference class Application_Model_Preference
{ {
private static function getUserId() private static function getUserId()
{ {
//pass in true so the check is made with the autoloader //pass in true so the check is made with the autoloader
//we need this check because saas calls this function from outside Zend //we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) { if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null; $userId = null;
} } else {
else { $auth = Zend_Auth::getInstance();
$auth = Zend_Auth::getInstance(); $userId = $auth->getIdentity()->id;
$userId = $auth->getIdentity()->id; }
}
return $userId;
return $userId; }
}
/** /**
* *
* @param boolean $isUserValue is true when we are setting a value for the current user * @param boolean $isUserValue is true when we are setting a value for the current user
*/ */
private static function setValue($key, $value, $isUserValue = false) private static function setValue($key, $value, $isUserValue = false)
{ {
$cache = new Cache(); $cache = new Cache();
try { try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME); $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction(); $con->beginTransaction();
$userId = self::getUserId(); $userId = self::getUserId();
if ($isUserValue && is_null($userId)) { if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference {$key}."); throw new Exception("User id can't be null for a user preference {$key}.");
}
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref"); Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = :key"; ." WHERE keystr = :key";
$paramMap = array(); $paramMap = array();
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
@ -64,37 +63,33 @@ class Application_Model_Preference
//this case should not happen. //this case should not happen.
throw new Exception("Invalid number of results returned. Should be ". throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead"); "0 or 1, but is '$result' instead");
} } else if ($result == 1) {
elseif ($result == 1) {
// result found // result found
if (!$isUserValue) { if (!$isUserValue) {
// system pref // system pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = :value" ." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key"; ." WHERE keystr = :key";
} } else {
else {
// user pref // user pref
$sql = "UPDATE cc_pref" $sql = "UPDATE cc_pref"
. " SET valstr = :value" . " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id"; . " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
} } else {
else {
// result not found // result not found
if (!$isUserValue) { if (!$isUserValue) {
// system pref // system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)" $sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES (:key, :value)"; ." VALUES (:key, :value)";
} } else {
else {
// user pref // user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)"; ." VALUES (:id, :key, :value)";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
@ -109,8 +104,7 @@ class Application_Model_Preference
$con); $con);
$con->commit(); $con->commit();
} } catch (Exception $e) {
catch (Exception $e) {
$con->rollback(); $con->rollback();
header('HTTP/1.0 503 Service Unavailable'); header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage()); Logging::info("Database error: ".$e->getMessage());
@ -118,26 +112,22 @@ class Application_Model_Preference
} }
$cache->store($key, $value, $isUserValue, $userId); $cache->store($key, $value, $isUserValue, $userId);
//Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
} }
private static function getValue($key, $isUserValue = false) private static function getValue($key, $isUserValue = false)
{ {
$cache = new Cache(); $cache = new Cache();
try { try {
$userId = self::getUserId(); $userId = self::getUserId();
if ($isUserValue && is_null($userId)) { if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference."); throw new Exception("User id can't be null for a user preference.");
}
$res = $cache->fetch($key, $isUserValue, $userId); // If the value is already cached, return it
if ($res !== false) { $res = $cache->fetch($key, $isUserValue, $userId);
//Logging::info("returning {$key} {$userId} from cache. = {$res}"); if ($res !== false) return $res;
return $res;
}
//Check if key already exists //Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref" $sql = "SELECT COUNT(*) FROM cc_pref"
@ -147,7 +137,7 @@ class Application_Model_Preference
$paramMap[':key'] = $key; $paramMap[':key'] = $key;
//For user specific preference, check if id matches as well //For user specific preference, check if id matches as well
if ($isUserValue) { if ($isUserValue) {
$sql .= " AND subjid = :id"; $sql .= " AND subjid = :id";
$paramMap[':id'] = $userId; $paramMap[':id'] = $userId;
} }
@ -157,8 +147,7 @@ class Application_Model_Preference
//return an empty string if the result doesn't exist. //return an empty string if the result doesn't exist.
if ($result == 0) { if ($result == 0) {
$res = ""; $res = "";
} } else {
else {
$sql = "SELECT valstr FROM cc_pref" $sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key"; ." WHERE keystr = :key";
@ -248,53 +237,53 @@ class Application_Model_Preference
public static function SetDefaultCrossfadeDuration($duration) public static function SetDefaultCrossfadeDuration($duration)
{ {
self::setValue("default_crossfade_duration", $duration); self::setValue("default_crossfade_duration", $duration);
} }
public static function GetDefaultCrossfadeDuration() public static function GetDefaultCrossfadeDuration()
{ {
$duration = self::getValue("default_crossfade_duration"); $duration = self::getValue("default_crossfade_duration");
if ($duration === "") { if ($duration === "") {
// the default value of the fade is 00.5 // the default value of the fade is 00.5
return "0"; return "0";
} }
return $duration; return $duration;
} }
public static function SetDefaultFadeIn($fade) public static function SetDefaultFadeIn($fade)
{ {
self::setValue("default_fade_in", $fade); self::setValue("default_fade_in", $fade);
} }
public static function GetDefaultFadeIn() public static function GetDefaultFadeIn()
{ {
$fade = self::getValue("default_fade_in"); $fade = self::getValue("default_fade_in");
if ($fade === "") { if ($fade === "") {
// the default value of the fade is 00.5 // the default value of the fade is 00.5
return "00.5"; return "00.5";
} }
return $fade; return $fade;
} }
public static function SetDefaultFadeOut($fade) public static function SetDefaultFadeOut($fade)
{ {
self::setValue("default_fade_out", $fade); self::setValue("default_fade_out", $fade);
} }
public static function GetDefaultFadeOut() public static function GetDefaultFadeOut()
{ {
$fade = self::getValue("default_fade_out"); $fade = self::getValue("default_fade_out");
if ($fade === "") { if ($fade === "") {
// the default value of the fade is 00.5 // the default value of the fade is 00.5
return "00.5"; return "00.5";
} }
return $fade; return $fade;
} }
public static function SetDefaultFade($fade) public static function SetDefaultFade($fade)
@ -556,9 +545,8 @@ class Application_Model_Preference
{ {
// When a new user is created they will get the default timezone // When a new user is created they will get the default timezone
// setting which the admin sets on preferences page // setting which the admin sets on preferences page
if (is_null($timezone)) { if (is_null($timezone))
$timezone = self::GetDefaultTimezone(); $timezone = self::GetDefaultTimezone();
}
self::setValue("user_timezone", $timezone, true); self::setValue("user_timezone", $timezone, true);
} }
@ -567,8 +555,7 @@ class Application_Model_Preference
$timezone = self::getValue("user_timezone", true); $timezone = self::getValue("user_timezone", true);
if (!$timezone) { if (!$timezone) {
return self::GetDefaultTimezone(); return self::GetDefaultTimezone();
} } else {
else {
return $timezone; return $timezone;
} }
} }
@ -580,8 +567,7 @@ class Application_Model_Preference
if (!is_null($userId)) { if (!is_null($userId)) {
return self::GetUserTimezone(); return self::GetUserTimezone();
} } else {
else {
return self::GetDefaultTimezone(); return self::GetDefaultTimezone();
} }
} }
@ -612,9 +598,8 @@ class Application_Model_Preference
{ {
// When a new user is created they will get the default locale // When a new user is created they will get the default locale
// setting which the admin sets on preferences page // setting which the admin sets on preferences page
if (is_null($locale)) { if (is_null($locale))
$locale = self::GetDefaultLocale(); $locale = self::GetDefaultLocale();
}
self::setValue("user_locale", $locale, true); self::setValue("user_locale", $locale, true);
} }
@ -624,8 +609,7 @@ class Application_Model_Preference
if (!is_null($userId)) { if (!is_null($userId)) {
return self::GetUserLocale(); return self::GetUserLocale();
} } else {
else {
return self::GetDefaultLocale(); return self::GetDefaultLocale();
} }
} }
@ -648,7 +632,7 @@ class Application_Model_Preference
public static function SetUniqueId($id) public static function SetUniqueId($id)
{ {
self::setValue("uniqueId", $id); self::setValue("uniqueId", $id);
} }
public static function GetUniqueId() public static function GetUniqueId()
@ -908,7 +892,7 @@ class Application_Model_Preference
public static function SetAirtimeVersion($version) public static function SetAirtimeVersion($version)
{ {
self::setValue("system_version", $version); self::setValue("system_version", $version);
} }
public static function GetAirtimeVersion() public static function GetAirtimeVersion()
@ -1404,12 +1388,11 @@ class Application_Model_Preference
return self::getValue("enable_replay_gain", false); return self::getValue("enable_replay_gain", false);
} }
public static function getReplayGainModifier(){ public static function getReplayGainModifier() {
$rg_modifier = self::getValue("replay_gain_modifier"); $rg_modifier = self::getValue("replay_gain_modifier");
if ($rg_modifier === "") { if ($rg_modifier === "")
return "0"; return "0";
}
return $rg_modifier; return $rg_modifier;
} }
@ -1420,18 +1403,18 @@ class Application_Model_Preference
} }
public static function SetHistoryItemTemplate($value) { public static function SetHistoryItemTemplate($value) {
self::setValue("history_item_template", $value); self::setValue("history_item_template", $value);
} }
public static function GetHistoryItemTemplate() { public static function GetHistoryItemTemplate() {
return self::getValue("history_item_template"); return self::getValue("history_item_template");
} }
public static function SetHistoryFileTemplate($value) { public static function SetHistoryFileTemplate($value) {
self::setValue("history_file_template", $value); self::setValue("history_file_template", $value);
} }
public static function GetHistoryFileTemplate() { public static function GetHistoryFileTemplate() {
return self::getValue("history_file_template"); return self::getValue("history_file_template");
} }
} }