172 lines
3.3 KiB
PHP
172 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use PDO;
|
|
use PDOException;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class DomainController
|
|
{
|
|
private PDO $dbConnection;
|
|
|
|
public function __construct(PDO $dbConnection)
|
|
{
|
|
$this->dbConnection = $dbConnection;
|
|
}
|
|
|
|
/**
|
|
* @return array|false
|
|
*/
|
|
public function findAll(): bool|array
|
|
{
|
|
$statement = "
|
|
SELECT id, name, a, aaaa
|
|
FROM domains";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->query($statement);
|
|
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @param String $name
|
|
*
|
|
* @return array|false
|
|
*/
|
|
public function findByName(String $name): bool|array
|
|
{
|
|
$statement = "
|
|
SELECT id, name, a, aaaa
|
|
FROM domains
|
|
WHERE name = :name";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->prepare($statement);
|
|
$statement->bindParam(':name', $name);
|
|
$statement->execute();
|
|
|
|
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param Int $id
|
|
*
|
|
* @return array|false
|
|
*/
|
|
public function findByID(Int $id): bool|array
|
|
{
|
|
$statement = "
|
|
SELECT id, name, a, aaaa
|
|
FROM domains
|
|
WHERE id = :id";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->prepare($statement);
|
|
$statement->bindParam(':id', $id);
|
|
$statement->execute();
|
|
|
|
return $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @param String $name
|
|
* @param String $a
|
|
* @param String $aaaa
|
|
*
|
|
* @return int
|
|
*/
|
|
public function insert(String $name, String $a, String $aaaa): int
|
|
{
|
|
// TODO create zone file and include
|
|
$statement = "
|
|
INSERT INTO domains (name, a, aaaa)
|
|
VALUES (:name, :a, :aaaa)";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->prepare($statement);
|
|
$statement->bindParam(':name', $name);
|
|
$statement->bindParam(':a', $a);
|
|
$statement->bindParam(':aaaa', $aaaa);
|
|
$statement->execute();
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
|
|
// TODO
|
|
// create zone file
|
|
// add zone file to include file
|
|
}
|
|
|
|
|
|
/**
|
|
* @param Int $id
|
|
* @param String $name
|
|
* @param String $a
|
|
* @param String $aaaa
|
|
*
|
|
* @return int|void
|
|
*/
|
|
public function update(Int $id, String $name, String $a, String $aaaa)
|
|
{
|
|
// TODO UPDATE Zone file
|
|
$statement = "
|
|
UPDATE domains SET
|
|
name = :name,
|
|
a = :a,
|
|
aaaa = :aaaa
|
|
WHERE id = :id";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->prepare($statement);
|
|
$statement->bindParam('id', $id);
|
|
$statement->bindParam('name', $name);
|
|
$statement->bindParam('a', $a);
|
|
$statement->bindParam('aaaa', $aaaa);
|
|
$statement->execute();
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
|
|
// TODO
|
|
// recreate zone file
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $id
|
|
*
|
|
* @return int
|
|
*/
|
|
public function delete($id): int
|
|
{
|
|
// TODO delete zone file and include
|
|
$statement = "
|
|
DELETE FROM domains
|
|
WHERE id = :id";
|
|
|
|
try {
|
|
$statement = $this->dbConnection->prepare($statement);
|
|
$statement->bindParam('id', $id);
|
|
$statement->execute();
|
|
return $statement->rowCount();
|
|
} catch (\PDOException $e) {
|
|
exit($e->getMessage());
|
|
}
|
|
}
|
|
} |