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
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Weather\Db;
|
|
|
|
|
2017-05-23 06:44:54 +00:00
|
|
|
use \OCP\IDBConnection;
|
2015-07-18 13:58:51 +00:00
|
|
|
|
|
|
|
use \OCP\AppFramework\Db\Mapper;
|
|
|
|
|
|
|
|
class SettingsMapper extends Mapper {
|
2017-05-23 06:44:54 +00:00
|
|
|
public function __construct (IDBConnection $db) {
|
2015-07-18 13:58:51 +00:00
|
|
|
parent::__construct($db, 'weather_city');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHome ($userId, $cityId) {
|
2015-10-25 09:57:07 +00:00
|
|
|
$this->setSetting("home", $userId, $cityId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHome ($userId) {
|
|
|
|
return $this->getSetting($userId, "home");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setApiKey ($userId, $apiKey) {
|
|
|
|
$this->setSetting("apikey", $userId, $apiKey);
|
|
|
|
}
|
|
|
|
|
2015-10-25 10:30:05 +00:00
|
|
|
public function getApiKey ($userId) {
|
2015-10-25 09:57:07 +00:00
|
|
|
return $this->getSetting($userId, "apikey");
|
|
|
|
}
|
|
|
|
|
2015-10-25 10:30:05 +00:00
|
|
|
public function setMetric ($userId, $metric) {
|
|
|
|
$this->setSetting("metric", $userId, $metric);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMetric ($userId) {
|
|
|
|
return $this->getSetting($userId, "metric");
|
|
|
|
}
|
|
|
|
|
2015-10-25 09:57:07 +00:00
|
|
|
public function setSetting ($settingName, $userId, $settingValue) {
|
2015-07-18 13:58:51 +00:00
|
|
|
\OCP\DB::beginTransaction();
|
|
|
|
$query = \OCP\DB::prepare('DELETE FROM *PREFIX*weather_config ' .
|
|
|
|
'WHERE `user` = ? and `key` = ?');
|
2015-10-25 09:57:07 +00:00
|
|
|
$query->execute(array($userId, $settingName));
|
2015-07-18 13:58:51 +00:00
|
|
|
|
|
|
|
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*weather_config ' .
|
|
|
|
'(`user`,`key`,`value`) VALUES (?,?,?)');
|
2015-10-25 09:57:07 +00:00
|
|
|
$query->execute(array($userId, $settingName, $settingValue));
|
2015-07-18 13:58:51 +00:00
|
|
|
\OCP\DB::commit();
|
|
|
|
}
|
|
|
|
|
2015-10-25 09:57:07 +00:00
|
|
|
public function getSetting ($userId, $settingName) {
|
2015-07-18 13:58:51 +00:00
|
|
|
$sql = 'SELECT value FROM ' .
|
|
|
|
'*PREFIX*weather_config WHERE `user` = ? and `key` = ?';
|
|
|
|
$query = \OCP\DB::prepare($sql);
|
2015-10-25 09:57:07 +00:00
|
|
|
$result = $query->execute(array($userId, $settingName));
|
2015-07-18 13:58:51 +00:00
|
|
|
|
|
|
|
if ($row = $result->fetchRow()) {
|
|
|
|
return $row["value"];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-25 09:57:07 +00:00
|
|
|
|
2015-07-18 13:58:51 +00:00
|
|
|
};
|
|
|
|
?>
|