CC-2646: Set a calendar view default (Day/week/month) that's remembered

1. If the preference is not user-specific, or if id is null, set subjid to null

2. Rewrote the code for the setValue logic, added comments. Should be easier
to read and understand
This commit is contained in:
Yuchen Wang 2011-10-24 12:05:55 -04:00
parent 6237a199af
commit 4db6636b06

View file

@ -29,30 +29,32 @@ class Application_Model_Preference
$result = $CC_DBC->GetOne($sql); $result = $CC_DBC->GetOne($sql);
if ($result == 1 && is_null($id)){ if($result == 1) {
$sql = "UPDATE cc_pref" // result found
." SET subjid = NULL, valstr = '$value'" if(is_null($id) || !$isUserValue) {
." WHERE keystr = '$key'"; // system pref
} $sql = "UPDATE cc_pref"
else if ($result == 1 && !is_null($id)){ ." SET subjid = NULL, valstr = '$value'"
if($isUserValue) {
$sql = "UPDATE cc_pref"
." SET valstr = '$value'"
." WHERE keystr = '$key' AND subjid = $id";
} else {
$sql = "UPDATE cc_pref"
." SET subjid = $id, valstr = '$value'"
." WHERE keystr = '$key'"; ." WHERE keystr = '$key'";
} } else {
} // user pref
else if(is_null($id)) { $sql = "UPDATE cc_pref"
$sql = "INSERT INTO cc_pref (keystr, valstr)" . " SET valstr = '$value'"
." VALUES ('$key', '$value')"; . " WHERE keystr = '$key' AND subjid = $id";
} }
else { } else {
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" // result not found
." VALUES ($id, '$key', '$value')"; if(is_null($id) || !$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', '$value')";
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', '$value')";
}
} }
return $CC_DBC->query($sql); return $CC_DBC->query($sql);
} }