-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add home setting to have a default city to show at application startup
- Loading branch information
Showing
9 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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\Controller; | ||
|
||
use \OCP\IRequest; | ||
use \OCP\AppFramework\Http\TemplateResponse; | ||
use \OCP\AppFramework\Controller; | ||
use \OCP\AppFramework\Http\JSONResponse; | ||
use \OCP\AppFramework\Http; | ||
|
||
use \OCA\Weather\Db\SettingsMapper; | ||
use \OCA\Weather\Db\CityMapper; | ||
|
||
class SettingsController extends Controller { | ||
|
||
private $userId; | ||
private $mapper; | ||
|
||
public function __construct ($appName, IRequest $request, $userId, SettingsMapper $mapper, CityMapper $cityMapper) { | ||
parent::__construct($appName, $request); | ||
$this->userId = $userId; | ||
$this->mapper = $mapper; | ||
$this->cityMapper = $cityMapper; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoCSRFRequired | ||
*/ | ||
public function homeSet ($city) { | ||
if (!$city || !is_numeric($city)) { | ||
return new JSONResponse(array(), Http::STATUS_BAD_REQUEST); | ||
} | ||
|
||
if (!$this->cityMapper->exists($city)) { | ||
return new JSONResponse(array(), Http::STATUS_NOT_FOUND); | ||
} | ||
|
||
$this->mapper->setHome($this->userId, $city); | ||
return new JSONResponse(array("set" => true)); | ||
} | ||
}; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?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; | ||
|
||
use \OCP\IDb; | ||
|
||
use \OCP\AppFramework\Db\Mapper; | ||
|
||
class SettingsMapper extends Mapper { | ||
public function __construct (IDb $db) { | ||
parent::__construct($db, 'weather_city'); | ||
} | ||
|
||
public function setHome ($userId, $cityId) { | ||
\OCP\DB::beginTransaction(); | ||
$query = \OCP\DB::prepare('DELETE FROM *PREFIX*weather_config ' . | ||
'WHERE `user` = ? and `key` = ?'); | ||
$query->execute(array($userId, "home")); | ||
|
||
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*weather_config ' . | ||
'(`user`,`key`,`value`) VALUES (?,?,?)'); | ||
$query->execute(array($userId, "home", $cityId)); | ||
\OCP\DB::commit(); | ||
} | ||
|
||
public function getHome ($userId) { | ||
$sql = 'SELECT value FROM ' . | ||
'*PREFIX*weather_config WHERE `user` = ? and `key` = ?'; | ||
$query = \OCP\DB::prepare($sql); | ||
$result = $query->execute(array($userId, "home")); | ||
|
||
if ($row = $result->fetchRow()) { | ||
return $row["value"]; | ||
} | ||
return 0; | ||
} | ||
}; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters