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

@ -11,8 +11,7 @@ class Application_Model_Preference
//we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
}
else {
} else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
@ -29,14 +28,14 @@ class Application_Model_Preference
$cache = new Cache();
try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction();
$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}.");
}
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
@ -64,8 +63,7 @@ class Application_Model_Preference
//this case should not happen.
throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead");
}
elseif ($result == 1) {
} else if ($result == 1) {
// result found
if (!$isUserValue) {
@ -73,8 +71,7 @@ class Application_Model_Preference
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key";
}
else {
} else {
// user pref
$sql = "UPDATE cc_pref"
. " SET valstr = :value"
@ -82,16 +79,14 @@ class Application_Model_Preference
$paramMap[':id'] = $userId;
}
}
else {
} else {
// result not found
if (!$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES (:key, :value)";
}
else {
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)";
@ -109,8 +104,7 @@ class Application_Model_Preference
$con);
$con->commit();
}
catch (Exception $e) {
} catch (Exception $e) {
$con->rollback();
header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage());
@ -118,7 +112,6 @@ class Application_Model_Preference
}
$cache->store($key, $value, $isUserValue, $userId);
//Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
}
private static function getValue($key, $isUserValue = false)
@ -129,15 +122,12 @@ class Application_Model_Preference
$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.");
}
// If the value is already cached, return it
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) {
//Logging::info("returning {$key} {$userId} from cache. = {$res}");
return $res;
}
if ($res !== false) return $res;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
@ -157,8 +147,7 @@ class Application_Model_Preference
//return an empty string if the result doesn't exist.
if ($result == 0) {
$res = "";
}
else {
} else {
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key";
@ -556,9 +545,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default timezone
// setting which the admin sets on preferences page
if (is_null($timezone)) {
if (is_null($timezone))
$timezone = self::GetDefaultTimezone();
}
self::setValue("user_timezone", $timezone, true);
}
@ -567,8 +555,7 @@ class Application_Model_Preference
$timezone = self::getValue("user_timezone", true);
if (!$timezone) {
return self::GetDefaultTimezone();
}
else {
} else {
return $timezone;
}
}
@ -580,8 +567,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserTimezone();
}
else {
} else {
return self::GetDefaultTimezone();
}
}
@ -612,9 +598,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default locale
// setting which the admin sets on preferences page
if (is_null($locale)) {
if (is_null($locale))
$locale = self::GetDefaultLocale();
}
self::setValue("user_locale", $locale, true);
}
@ -624,8 +609,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserLocale();
}
else {
} else {
return self::GetDefaultLocale();
}
}
@ -1407,9 +1391,8 @@ class Application_Model_Preference
public static function getReplayGainModifier() {
$rg_modifier = self::getValue("replay_gain_modifier");
if ($rg_modifier === "") {
if ($rg_modifier === "")
return "0";
}
return $rg_modifier;
}