moved body to repository

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-31 20:53:50 +01:00
parent 276764b5f9
commit 7976c2387e
1 changed files with 0 additions and 186 deletions

View File

@ -3,8 +3,6 @@ namespace App\Controller;
error_reporting(error_level: E_ALL);
use PDO;
use PDOException;
/**
*
@ -16,189 +14,5 @@ class NameserverController
{}
/**
* @return array|false
*/
public function findAll(): bool|array
{
$sql = "
SELECT id, name, a, aaaa, apikey
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
ORDER BY name";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->execute();
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
/**
* @param String $name
*
* @return array|false
*/
public function findByName(String $name): bool|array
{
$sql = "
SELECT id, name, a, aaaa, apikey
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
WHERE name = :name";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name);
$statement->execute();
return $statement->fetch(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
/**
* @param Int $id
*
* @return array|false
*/
public function findByID(Int $id): bool|array
{
$sql = "
SELECT id, name, a, aaaa, apikey
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param:':id', var: $id);
$statement->execute();
return $statement->fetch(mode: PDO::FETCH_ASSOC);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
/**
* @param String $name
* @param String $a
* @param String $aaaa
* @param String $apikey
*
* @return string|false
*/
public function insert(String $name, String $a, String $aaaa, String $apikey): bool|string
{
$sql = "
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey)
VALUES (:name, :a, :aaaa, :apikey)";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':name', var: $name);
$statement->bindParam(param: ':a', var: $a);
$statement->bindParam(param: ':aaaa', var: $aaaa);
$statement->bindParam(param: ':apikey', var: $apikey);
$statement->execute();
return $this->databaseConnection->getConnection()->lastInsertId();
} catch (PDOException $e) {
exit($e->getMessage());
}
}
/**
* @param Int $id
* @param String $name
* @param String $a
* @param String $aaaa
* @param String $apikey
*
* @return false|int
*/
public function update(Int $id, String $name, String $a, String $aaaa, String $apikey): bool|int
{
$current = $this->findByID(id: $id);
if (empty($name)) {
$name = $current['name'] ?? '';
}
if (empty($a)) {
$a = $current['a'] ?? '';
}
if (empty($aaaa)) {
$aaaa = $current['aaaa'] ?? '';
}
if (empty($apikey)) {
$apikey = $current['apikey'] ?? '';
}
$sql = "
UPDATE " . DatabaseConnection::TABLE_NAMESERVERS . " SET
name = :name,
a = :a,
aaaa = :aaaa,
apikey = :apikey
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id);
$statement->bindParam(param: 'name', var: $name);
$statement->bindParam(param: 'a', var: $a);
$statement->bindParam(param: 'aaaa', var: $aaaa);
$statement->bindParam(param: 'apikey', var: $apikey);
$statement->execute();
return $statement->rowCount();
} catch (PDOException $e) {
print($e->getMessage());
return false;
}
}
/**
* @param $id
*
* @return int
*/
public function delete($id): int
{
$sql = "
DELETE FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
WHERE id = :id";
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: 'id', var: $id);
$statement->execute();
return $statement->rowCount();
} catch (PDOException $e) {
exit($e->getMessage());
}
}
/**
* @param String $field
*
* @return int
*/
public function getLongestEntry(String $field): int
{
$sql = "
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_NAMESERVERS;
try {
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
return $result['length'];
} catch (PDOException $e) {
exit($e->getMessage());
}
}
}