2015-07-18 13:58:51 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud - weather
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Loic Blot <loic.blot@unix-experience.fr>
|
|
|
|
* @copyright Loic Blot 2015
|
2018-09-28 11:51:45 +00:00
|
|
|
* @copyright e-alfred 2018
|
2015-07-18 13:58:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Weather\Db;
|
|
|
|
|
2017-05-23 06:44:54 +00:00
|
|
|
use \OCP\IDBConnection;
|
2015-07-18 13:58:51 +00:00
|
|
|
|
2023-07-24 18:21:43 +00:00
|
|
|
use \OCP\AppFramework\Db\QbMapper;
|
2015-07-18 13:58:51 +00:00
|
|
|
|
2023-07-24 18:21:43 +00:00
|
|
|
class SettingsMapper extends QbMapper {
|
2018-09-28 11:51:45 +00:00
|
|
|
public function __construct (IDBConnection $db) {
|
|
|
|
parent::__construct($db, 'weather_config');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHome ($userId, $cityId) {
|
|
|
|
$this->setSetting("home", $userId, $cityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHome ($userId) {
|
|
|
|
return $this->getSetting($userId, "home");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMetric ($userId, $metric) {
|
|
|
|
$this->setSetting("metric", $userId, $metric);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMetric ($userId) {
|
|
|
|
return $this->getSetting($userId, "metric");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSetting ($settingName, $userId, $settingValue) {
|
|
|
|
$sql = "DELETE FROM *PREFIX*weather_config WHERE `user` = '" . $userId . "' and `key` = '" . $settingName . "'";
|
|
|
|
$this->db->executequery($sql);
|
|
|
|
|
|
|
|
$sql = "INSERT INTO *PREFIX*weather_config (`user`,`key`,`value`) VALUES ('" . $userId . "','" . $settingName . "','" . $settingValue . "')";
|
|
|
|
$this->db->executequery($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSetting ($userId, $settingName) {
|
|
|
|
$sql = "SELECT value FROM *PREFIX*weather_config WHERE `user` ='" . $userId . "' and `key` ='" . $settingName . "'";
|
|
|
|
$result = $this->db->executeQuery($sql);
|
|
|
|
|
|
|
|
if ($row = $result->fetch()) {
|
|
|
|
return $row["value"];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-25 09:57:07 +00:00
|
|
|
|
2015-07-18 13:58:51 +00:00
|
|
|
};
|
|
|
|
?>
|