Style fixes

This commit is contained in:
Bart Visscher 2013-08-25 22:34:54 +02:00
parent ca88cf93ae
commit 2f79e94a35
1 changed files with 25 additions and 21 deletions

View File

@ -42,8 +42,14 @@ use \OC\DB\Connection;
* database. * database.
*/ */
class AppConfig { class AppConfig {
/**
* @var \OC\DB\Connection $conn
*/
protected $conn; protected $conn;
/**
* @param \OC\DB\Connection $conn
*/
public function __construct(Connection $conn) { public function __construct(Connection $conn) {
$this->conn = $conn; $this->conn = $conn;
} }
@ -57,10 +63,10 @@ class AppConfig {
*/ */
public function getApps() { public function getApps() {
$query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`'; $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*appconfig`';
$result = $this->conn->executeQuery( $query ); $result = $this->conn->executeQuery($query);
$apps = array(); $apps = array();
while( $appid = $result->fetchColumn()) { while ($appid = $result->fetchColumn()) {
$apps[] = $appid; $apps[] = $appid;
} }
return $apps; return $apps;
@ -74,12 +80,12 @@ class AppConfig {
* This function gets all keys of an app. Please note that the values are * This function gets all keys of an app. Please note that the values are
* not returned. * not returned.
*/ */
public function getKeys( $app ) { public function getKeys($app) {
$query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?'; $query = 'SELECT `configkey` FROM `*PREFIX*appconfig` WHERE `appid` = ?';
$result = $this->conn->executeQuery( $query, array( $app )); $result = $this->conn->executeQuery($query, array($app));
$keys = array(); $keys = array();
while( $key = $result->fetchColumn()) { while ($key = $result->fetchColumn()) {
$keys[] = $key; $keys[] = $key;
} }
@ -96,11 +102,11 @@ class AppConfig {
* This function gets a value from the appconfig table. If the key does * This function gets a value from the appconfig table. If the key does
* not exist the default value will be returned * not exist the default value will be returned
*/ */
public function getValue( $app, $key, $default = null ) { public function getValue($app, $key, $default = null) {
$query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`' $query = 'SELECT `configvalue` FROM `*PREFIX*appconfig`'
.' WHERE `appid` = ? AND `configkey` = ?'; .' WHERE `appid` = ? AND `configkey` = ?';
$row = $this->conn->fetchAssoc($query, array( $app, $key )); $row = $this->conn->fetchAssoc($query, array($app, $key));
if($row) { if ($row) {
return $row['configvalue']; return $row['configvalue'];
} else { } else {
return $default; return $default;
@ -114,8 +120,8 @@ class AppConfig {
* @return bool * @return bool
*/ */
public function hasKey($app, $key) { public function hasKey($app, $key) {
$exists = $this->getKeys( $app ); $exists = $this->getKeys($app);
return in_array( $key, $exists ); return in_array($key, $exists);
} }
/** /**
@ -126,9 +132,9 @@ class AppConfig {
* *
* Sets a value. If the key did not exist before it will be created. * Sets a value. If the key did not exist before it will be created.
*/ */
public function setValue( $app, $key, $value ) { public function setValue($app, $key, $value) {
// Does the key exist? no: insert, yes: update. // Does the key exist? no: insert, yes: update.
if ( !$this->hasKey($app, $key)) { if (!$this->hasKey($app, $key)) {
$data = array( $data = array(
'appid' => $app, 'appid' => $app,
'configkey' => $key, 'configkey' => $key,
@ -155,7 +161,7 @@ class AppConfig {
* *
* Deletes a key. * Deletes a key.
*/ */
public function deleteKey( $app, $key ) { public function deleteKey($app, $key) {
$where = array( $where = array(
'appid' => $app, 'appid' => $app,
'configkey' => $key, 'configkey' => $key,
@ -170,7 +176,7 @@ class AppConfig {
* *
* Removes all keys in appconfig belonging to the app. * Removes all keys in appconfig belonging to the app.
*/ */
public function deleteApp( $app ) { public function deleteApp($app) {
$where = array( $where = array(
'appid' => $app, 'appid' => $app,
); );
@ -184,19 +190,19 @@ class AppConfig {
* @return array * @return array
*/ */
public function getValues($app, $key) { public function getValues($app, $key) {
if(($app!==false) == ($key!==false)) { if (($app !== false) == ($key !== false)) {
return false; return false;
} }
$fields = '`configvalue`'; $fields = '`configvalue`';
$where = 'WHERE'; $where = 'WHERE';
$params = array(); $params = array();
if($app!==false) { if ($app !== false) {
$fields .= ', `configkey`'; $fields .= ', `configkey`';
$where .= ' `appid` = ?'; $where .= ' `appid` = ?';
$params[] = $app; $params[] = $app;
$key = 'configkey'; $key = 'configkey';
}else{ } else {
$fields .= ', `appid`'; $fields .= ', `appid`';
$where .= ' `configkey` = ?'; $where .= ' `configkey` = ?';
$params[] = $key; $params[] = $key;
@ -206,12 +212,10 @@ class AppConfig {
$result = $this->conn->executeQuery( $query, $params ); $result = $this->conn->executeQuery( $query, $params );
$values = array(); $values = array();
while( $row = $result->fetch((\PDO::FETCH_ASSOC))) { while ($row = $result->fetch((\PDO::FETCH_ASSOC))) {
$values[$row[$key]] = $row['configvalue']; $values[$row[$key]] = $row['configvalue'];
} }
return $values; return $values;
} }
} }
require_once __DIR__.'/legacy/'.basename(__FILE__);