Skip to content

Commit

Permalink
Added app settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Chernyshev committed Jun 18, 2014
1 parent b0552f2 commit c89bee4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions classes/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,62 @@ public function setPass($password) {
}
}

public function getSettings() {
$db = UserConfig::getDB();

$json = null;

$userid = $this->userid;

if ($stmt = $db->prepare('SELECT app_settings_json
FROM ' . UserConfig::$mysql_prefix . 'user_preferences
WHERE user_id = ?')
) {
if (!$stmt->bind_param('i', $userid)) {
throw new DBBindParamException($db, $stmt);
}
if (!$stmt->bind_result($json)) {
throw new DBBindResultException($db, $stmt);
}
if (!$stmt->execute()) {
throw new DBExecuteStmtException($db, $stmt);
}

$stmt->fetch();
$stmt->close();
} else {
throw new DBPrepareStmtException($db);
}

$settings = json_decode($json, true);
if (!is_array($settings)) {
$settings = array();
}

return $settings;
}

public function saveSettings($settings) {
$db = UserConfig::getDB();

$json = json_encode($settings);

if ($stmt = $db->prepare('UPDATE ' . UserConfig::$mysql_prefix . 'user_preferences
SET app_settings_json = ? WHERE user_id = ?')
) {
if (!$stmt->bind_param('si', $json, $this->userid)) {
throw new DBBindParamException($db, $stmt);
}
if (!$stmt->execute()) {
throw new DBExecuteStmtException($db, $stmt);
}

$stmt->close();
} else {
throw new DBPrepareStmtException($db);
}
}

/**
* Persists user's data into the database
*
Expand Down
10 changes: 10 additions & 0 deletions dbupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
$versions[_]['down'][] = "";
*/

/* -------------------------------------------------------------------------------------------------------
* VERSION 35
* Adding application settings for a user (free-form JSON)
*/
$versions[35]['up'][] = "ALTER TABLE `".UserConfig::$mysql_prefix."user_preferences`
ADD `app_settings_json` BLOB NULL DEFAULT NULL COMMENT 'Application settings'";
$versions[35]['down'][] = "ALTER TABLE `".UserConfig::$mysql_prefix."user_preferences`
DROP `app_settings_json`";


/* -------------------------------------------------------------------------------------------------------
* VERSION 34
* Setting plans for invitations
Expand Down

0 comments on commit c89bee4

Please sign in to comment.