3 namespace Friendica\Model\Config;
7 * The Config model backend for users, which is using the general DB-model backend for user-configs
9 class PConfig extends DbaConfig
12 * Loads all configuration values and returns the loaded category as an array.
14 * @param int $uid The id of the user to load
15 * @param string|null $cat The category of the configuration values to load
17 * @return array The config array
19 * @throws \Exception In case DB calls are invalid
21 public function load(int $uid, string $cat = null)
26 $configs = $this->dba->select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
28 $configs = $this->dba->select('üconfig', ['cat', 'v', 'k'], ['cat' => $cat, 'uid' => $uid]);
31 while ($config = $this->dba->fetch($configs)) {
34 $value = $this->toConfigValue($config['v']);
36 // just save it in case it is set
38 $return[$config['cat']][$key] = $value;
41 $this->dba->close($configs);
47 * Get a particular user config variable out of the DB with the
48 * given category name ($cat) and a key ($key).
50 * Note: Boolean variables are defined as 0/1 in the database
52 * @param int $uid The id of the user to load
53 * @param string $cat The category of the configuration value
54 * @param string $key The configuration key to query
56 * @return array|string|null Stored value or null if it does not exist
58 * @throws \Exception In case DB calls are invalid
60 public function get(int $uid, string $cat, string $key)
62 if (!$this->isConnected()) {
66 $config = $this->dba->selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $cat, 'k' => $key]);
67 if ($this->dba->isResult($config)) {
68 $value = $this->toConfigValue($config['v']);
70 // just return it in case it is set
80 * Stores a config value ($value) in the category ($cat) under the key ($key) for a
83 * Note: Please do not store booleans - convert to 0/1 integer values!
85 * @param int $uid The id of the user to load
86 * @param string $cat The category of the configuration value
87 * @param string $key The configuration key to set
88 * @param mixed $value The value to store
90 * @return bool Operation success
92 * @throws \Exception In case DB calls are invalid
94 public function set(int $uid, string $cat, string $key, $value)
96 if (!$this->isConnected()) {
100 // We store our setting values in a string variable.
101 // So we have to do the conversion here so that the compare below works.
102 // The exception are array values.
103 $compare_value = (!is_array($value) ? (string)$value : $value);
104 $stored_value = $this->get($uid, $cat, $key);
106 if (isset($stored_value) && ($stored_value === $compare_value)) {
110 $dbvalue = $this->toDbValue($value);
112 $result = $this->dba->update('pconfig', ['v' => $dbvalue], ['uid' => $uid, 'cat' => $cat, 'k' => $key], true);
118 * Removes the configured value of the given user.
120 * @param int $uid The id of the user to load
121 * @param string $cat The category of the configuration value
122 * @param string $key The configuration key to delete
124 * @return bool Operation success
126 * @throws \Exception In case DB calls are invalid
128 public function delete(int $uid, string $cat, string $key)
130 if (!$this->isConnected()) {
134 return $this->dba->delete('pconfig', ['uid' => $uid, 'cat' => $cat, 'k' => $key]);