Delete API Folder, update .drone.yml (removing API Part)
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
d1f8f345c0
commit
c65d78d33c
@ -1,4 +0,0 @@
|
||||
FROM php:8.0-apache
|
||||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN docker-php-ext-install pdo pdo_mysql
|
||||
COPY ./script /var/www/html
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Permet de choisir quelle Gateway appeller en fonction de la
|
||||
* requête de notre utilisateur.
|
||||
*/
|
||||
class APIController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
if (empty($_REQUEST['action'])) {
|
||||
$action = null;
|
||||
} else {
|
||||
$action = $_REQUEST['action'];
|
||||
}
|
||||
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
|
||||
foreach ($listGateway as $gateway) {
|
||||
if (method_exists($gateway, $action)) {
|
||||
(new $gateway)->$action();
|
||||
}
|
||||
}
|
||||
} catch (PDOException) {
|
||||
return http_response_code(404);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Config;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
/**
|
||||
* Définit une connection à la base de données.
|
||||
*/
|
||||
class Connection extends PDO
|
||||
{
|
||||
/**
|
||||
* @var PDOStatement
|
||||
*/
|
||||
private PDOStatement $stmt;
|
||||
|
||||
public function __construct(string $dsn, string $username, string $password)
|
||||
{
|
||||
parent::__construct($dsn, $username, $password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Éxécute une réquête SQL.
|
||||
*
|
||||
* @param string $query
|
||||
* @param array $parameters
|
||||
* @return bool Returns `true` on success, `false` otherwise
|
||||
*/
|
||||
public function executeQuery(string $query, array $parameters = []): bool
|
||||
{
|
||||
$this->stmt = parent::prepare($query);
|
||||
foreach ($parameters as $name => $value) {
|
||||
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
return $this->stmt->execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Permet de récupère le résultat de la dernière réquête éxecuté avec
|
||||
* la fonction executeQuery().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResults(): array
|
||||
{
|
||||
return $this->stmt->fetchAll();
|
||||
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
use API\script\Config\Connection;
|
||||
|
||||
function connect()
|
||||
{
|
||||
$dsn = "mysql:host=localhost;dbname=formulaire;charset=utf8";
|
||||
$login = "root";
|
||||
|
||||
try {
|
||||
$connection = new Connection($dsn, $login, "root");
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(404);
|
||||
return http_response_code();
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
class ScriptDatabase
|
||||
{
|
||||
private Connection $con;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->con = connect();
|
||||
}
|
||||
|
||||
public function executeScript(): void
|
||||
{
|
||||
$queryScript = 'CREATE TABLE `Categorize` (
|
||||
`response` int(11) NOT NULL,
|
||||
`keyword` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Form` (
|
||||
`id` int(11) NOT NULL,
|
||||
`title` varchar(50) NOT NULL,
|
||||
`description` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Keyword` (
|
||||
`id` int(11) NOT NULL,
|
||||
`word` varchar(50) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `ListResponsesOfCandidate` (
|
||||
`id` int(11) NOT NULL,
|
||||
`date` datetime NOT NULL,
|
||||
`titleForm` varchar(50) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `PossibleResponse` (
|
||||
`id` int(11) NOT NULL,
|
||||
`content` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Propose` (
|
||||
`question` int(11) NOT NULL,
|
||||
`possibleResponse` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Question` (
|
||||
`id` int(11) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`type` varchar(50) NOT NULL,
|
||||
`form` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Reference` (
|
||||
`possibleResponse` int(11) NOT NULL,
|
||||
`keyword` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Response` (
|
||||
`id` int(11) NOT NULL,
|
||||
`content` varchar(200) NOT NULL,
|
||||
`questionContent` text NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
CREATE TABLE `Submit` (
|
||||
`responsesCandidate` int(11) NOT NULL,
|
||||
`response` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
ALTER TABLE `Categorize`
|
||||
ADD PRIMARY KEY (`response`,`keyword`),
|
||||
ADD KEY `keyword` (`keyword`);
|
||||
ALTER TABLE `Form`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
ALTER TABLE `Keyword`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
ALTER TABLE `ListResponsesOfCandidate`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
ALTER TABLE `PossibleResponse`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
ALTER TABLE `Propose`
|
||||
ADD PRIMARY KEY (`question`,`possibleResponse`),
|
||||
ADD KEY `possibleResponse` (`possibleResponse`);
|
||||
ALTER TABLE `Question`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `form` (`form`);
|
||||
ALTER TABLE `Reference`
|
||||
ADD PRIMARY KEY (`possibleResponse`,`keyword`),
|
||||
ADD KEY `keyword` (`keyword`);
|
||||
ALTER TABLE `Response`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
ALTER TABLE `Submit`
|
||||
ADD PRIMARY KEY (`responsesCandidate`,`response`),
|
||||
ADD KEY `response` (`response`);
|
||||
ALTER TABLE `Form`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `Keyword`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `ListResponsesOfCandidate`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `PossibleResponse`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `Question`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `Response`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
||||
ALTER TABLE `Categorize`
|
||||
ADD CONSTRAINT `Categorize_ibfk_1` FOREIGN KEY (`keyword`) REFERENCES `Keyword` (`id`),
|
||||
ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`response`) REFERENCES `Response` (`id`);
|
||||
ALTER TABLE `Propose`
|
||||
ADD CONSTRAINT `Propose_ibfk_1` FOREIGN KEY (`possibleResponse`) REFERENCES `PossibleResponse` (`id`),
|
||||
ADD CONSTRAINT `Propose_ibfk_2` FOREIGN KEY (`question`) REFERENCES `Question` (`id`);
|
||||
ALTER TABLE `Question`
|
||||
ADD CONSTRAINT `Question_ibfk_1` FOREIGN KEY (`form`) REFERENCES `Form` (`id`);
|
||||
ALTER TABLE `Reference`
|
||||
ADD CONSTRAINT `Reference_ibfk_1` FOREIGN KEY (`keyword`) REFERENCES `Keyword` (`id`),
|
||||
ADD CONSTRAINT `Reference_ibfk_2` FOREIGN KEY (`possibleResponse`) REFERENCES `PossibleResponse` (`id`);
|
||||
ALTER TABLE `Submit`
|
||||
ADD CONSTRAINT `Submit_ibfk_1` FOREIGN KEY (`response`) REFERENCES `Response` (`id`),
|
||||
ADD CONSTRAINT `Submit_ibfk_2` FOREIGN KEY (`responsesCandidate`) REFERENCES `ListResponsesOfCandidate` (`id`);
|
||||
COMMIT;';
|
||||
|
||||
$this->con->executeQuery($queryScript);
|
||||
|
||||
try {
|
||||
$test = "SELECT * FROM Categorize;";
|
||||
$this->con->executeQuery($test);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use BusinessClass\Form;
|
||||
use BusinessClass\Question;
|
||||
use PDO;
|
||||
|
||||
class GatewayForm
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function insertForm(Form $form): void
|
||||
{
|
||||
if (empty($this->getForm())) {
|
||||
$query = "INSERT INTO Form(title, description) VALUES(:title, :desc)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':title' => array($form->getTitle(), PDO::PARAM_STR),
|
||||
':desc' => array($form->getDescription(), PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function getForm(): array
|
||||
{
|
||||
$query = "SELECT * FROM Form";
|
||||
$this->connection->executeQuery($query);
|
||||
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function deleteForm(Form $form): void
|
||||
{
|
||||
$query = "DELETE FROM Form WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($form->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function assignKeywordToQuestion(string $keyword, string $response, int $idQuestion): void
|
||||
{
|
||||
$query = "SELECT pr.id
|
||||
FROM Propose p, PossibleResponse pr
|
||||
WHERE p.question = :id AND p.possibleResponse = pr.id
|
||||
AND pr.content = :response";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($idQuestion, PDO::PARAM_INT),
|
||||
':response' => array($response, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
$idPossibleResponse = $this->connection->getResults()[0][0];
|
||||
|
||||
$query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT),
|
||||
':keyword' => array($keyword, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteKeywordFromQuestion(string $keyword, string $response, Question $question): void
|
||||
{
|
||||
$query = "SELECT pr.id FROM Propose p, PossibleResponse r
|
||||
WHERE p.question = :id AND p.possibleResponse = pr.id
|
||||
AND pr.content = :response";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($question->getId(), PDO::PARAM_INT),
|
||||
':response' => array($response, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
$idPossibleResponse = $this->connection->getResults()[0][0];
|
||||
|
||||
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':idResponse' => array($idPossibleResponse, PDO::PARAM_INT),
|
||||
':idKeword' => array($keyword, PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function updateTitleToForm(string $title, Form $form): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':title' => array($title, PDO::PARAM_STR),
|
||||
':id' => array($form->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function updateDescriptionToForm(string $description, Form $form): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE description = :description";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':description' => array($description, PDO::PARAM_STR),
|
||||
':id' => array($form->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteDescriptionToForm(Form $form): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE description = :descript";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':descript' => array('', PDO::PARAM_STR),
|
||||
':id' => array($form->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayKeyword
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function insertKeyword(string $keyword)
|
||||
{
|
||||
$query = "INSERT INTO Keyword(word) VALUES(:word)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':word' => array($keyword, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteKeyword(string $keyword)
|
||||
{
|
||||
$query = "DELETE FROM Keyword WHERE word = :word";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':word' => array($keyword, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function getAllKeyword(): array
|
||||
{
|
||||
$query = "SELECT * FROM Keyword";
|
||||
$this->connection->executeQuery($query);
|
||||
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function getKeywordsContentByReference(int $id): array
|
||||
{
|
||||
$query = "SELECT k.* FROM Keyword k, Reference r
|
||||
WHERE k.word = r.keyword AND r.possibleResponse = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($id, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
|
||||
$tab = [];
|
||||
foreach ($this->connection->getResults() as $result) {
|
||||
$tab[] = $result["word"];
|
||||
}
|
||||
|
||||
return $tab;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayListResponseOfCandidate
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getDetailsListResponsesOfCandidate(int $idListResponse)
|
||||
{
|
||||
$gatewayResponse = new GatewayResponse();
|
||||
$gatewayKeyword = new GatewayKeyword();
|
||||
$tabKeywords = [];
|
||||
|
||||
$query = "SELECT * FROM ListResponsesOfCandidate WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($idListResponse, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$questionList = $this->connection->getResults()[0];
|
||||
|
||||
$responses = $gatewayResponse->getResponsesByIdListCandidate($questionList['id']);
|
||||
|
||||
foreach ($responses as $row) {
|
||||
$tabKeywords[] = $gatewayKeyword->getKeywordsContentByCategorieze($row['id']);
|
||||
}
|
||||
|
||||
return array($questionList, $responses, $tabKeywords);
|
||||
}
|
||||
|
||||
public function getAllListResponsesOfCandidate(): array
|
||||
{
|
||||
$query = "SELECT * FROM ListResponsesOfCandidate";
|
||||
$this->connection->executeQuery($query);
|
||||
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function deleteListResponseOfCandidate($id): void
|
||||
{
|
||||
$gatewayResponse = new GatewayResponse();
|
||||
|
||||
foreach ($gatewayResponse->getResponsesIdByIdListCandidate($id) as $response) {
|
||||
$gatewayResponse->deleteResponseById($response);
|
||||
}
|
||||
|
||||
$query = "DELETE FROM ListResponsesOfCandidate WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
'id' => array($id, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function insertListResponsesOfCandidate($id, $answer, $category, $titleForm): void
|
||||
{
|
||||
$gatewayResponse = new GatewayResponse();
|
||||
$gatewayQuestion = new GatewayQuestion();
|
||||
|
||||
$query = "INSERT INTO ListResponsesOfCandidate(date, titleForm) VALUES(:date, :titleForm)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':date' => array(date('Y-m-d H:i:s'), PDO::PARAM_STR),
|
||||
':titleForm' => array($titleForm, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
$idListQuestion = $this->connection->lastInsertId();
|
||||
|
||||
for ($i = 0; $i < count($answer); $i++) {
|
||||
$question = $gatewayQuestion->getQuestionContentById($id[$i]);
|
||||
$idResponse = $gatewayResponse->insertResponse($question, $answer[$i], $category[$i]);
|
||||
|
||||
$query = "INSERT INTO Submit (responsesCandidate, response) VALUES(:responsesCandidate, :response)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':responsesCandidate' => array($idListQuestion, PDO::PARAM_STR),
|
||||
'response' => array($idResponse, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayPossibleResponse
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getPossibleResponseByQuestion(string $idQuestion): array
|
||||
{
|
||||
$query = "SELECT pr.* FROM Propose p, PossibleResponse pr
|
||||
WHERE p.question = :questionId AND p.possibleResponse = pr.id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':questionId' => array($idQuestion, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function insertPossibleResponse(string $contentPossibleResponse): int
|
||||
{
|
||||
$query = "INSERT INTO PossibleResponse(content) VALUES(:content)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($contentPossibleResponse, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
return $this->connection->lastInsertId();
|
||||
}
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use BusinessClass\BoxQuestion;
|
||||
use BusinessClass\Question;
|
||||
use BusinessClass\TextQuestion;
|
||||
use PDO;
|
||||
|
||||
class GatewayQuestion
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function addQuestion(Question $question, int $idForm): int
|
||||
{
|
||||
$query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($question->getContent(), PDO::PARAM_STR),
|
||||
':type' => array(get_class($question), PDO::PARAM_STR),
|
||||
':form' => array($idForm, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
return $this->connection->lastInsertId();
|
||||
}
|
||||
|
||||
public function insertResponseInQuestion(string $response, array $categories, int $idQuestion): int
|
||||
{
|
||||
$gatewayPossibleResponse = new GatewayPossibleResponse();
|
||||
$idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($response);
|
||||
|
||||
$query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':question' => array($idQuestion, PDO::PARAM_INT),
|
||||
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
|
||||
foreach ($categories as $keyword) {
|
||||
$gatewayForm = new GatewayForm();
|
||||
$gatewayForm->assignKeywordToQuestion($keyword, $response, $idQuestion);
|
||||
}
|
||||
|
||||
return $idQuestion;
|
||||
}
|
||||
|
||||
public function deleteQuestion(Question $question): void
|
||||
{
|
||||
if (get_class($question) == BoxQuestion::class) {
|
||||
$query = "DELETE FROM Propose WHERE question = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($question->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$listPossibleResponse = $question->getPossibleResponses();
|
||||
for ($i = 0; $i < count($listPossibleResponse); $i++) {
|
||||
$query = "DELETE FROM Reference WHERE response = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$query = "DELETE FROM PossibleResponse WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($listPossibleResponse[$i]->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$query = "DELETE FROM Question WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($question->getId(), PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function updateQuestion(Question $question): void
|
||||
{
|
||||
$query = "UPDATE Question SET content = :content, type = :type, form = :frm WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($question->getContent(), PDO::PARAM_STR),
|
||||
':type' => array(get_class($question), PDO::PARAM_STR),
|
||||
':frm' => array($question->getForm(), PDO::PARAM_STR),
|
||||
':id' => array($question->getId(), PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function getAllQuestions(string $idForm): array
|
||||
{
|
||||
$query = "SELECT * FROM Question WHERE form = :fom";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':fom' => array($idForm, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$listQuestions = $this->connection->getResults();
|
||||
$possibleResponsesContent = [];
|
||||
$keywordsResponses = [];
|
||||
$gatewayKeyword = new GatewayKeyword();
|
||||
$gatewayPossibleResponse = new GatewayPossibleResponse();
|
||||
|
||||
if (!empty($listQuestions)) {
|
||||
|
||||
for ($i = 0; $i < count($listQuestions); $i++) {
|
||||
|
||||
if ($listQuestions[$i]["type"] != "BusinessClass/TextQuestion") {
|
||||
$idQuestion = $listQuestions[$i]["id"];
|
||||
$possibleResponses = $gatewayPossibleResponse->getPossibleResponseByQuestion($idQuestion);
|
||||
$tmpTabKeyword = [];
|
||||
$tmpTabPossibleResponse = [];
|
||||
|
||||
foreach ($possibleResponses as $row) {
|
||||
$tmpTabKeyword[] = $gatewayKeyword->getKeywordsContentByReference($row["id"]);
|
||||
$tmpTabPossibleResponse[] = $row["content"];
|
||||
}
|
||||
|
||||
$possibleResponsesContent[] = $tmpTabPossibleResponse;
|
||||
$keywordsResponses[] = $tmpTabKeyword;
|
||||
} else {
|
||||
$possibleResponsesContent[] = null;
|
||||
$keywordsResponses[] = null;
|
||||
}
|
||||
}
|
||||
return array($listQuestions, $possibleResponsesContent, $keywordsResponses);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getQuestionContentById(string $id): string
|
||||
{
|
||||
$query = "SELECT content FROM Question WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($id, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
return $this->connection->getResults()[0][0];
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace API\script\Gateway;
|
||||
|
||||
use API\script\Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayResponse
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getResponsesByIdListCandidate(int $listResponsesOfCandidateId): array
|
||||
{
|
||||
|
||||
$result = $this->getResponsesIdByIdListCandidate($listResponsesOfCandidateId);
|
||||
$tab = [];
|
||||
foreach ($result as $row) {
|
||||
$tab[] = (new GatewayKeyword())->getKeywordsContentByCategorieze($row['id']);
|
||||
}
|
||||
|
||||
return array($result, $tab);
|
||||
}
|
||||
|
||||
public function getResponsesIdByIdListCandidate(int $listResponsesOfCandidateId): array
|
||||
{
|
||||
$query = "SELECT r.id FROM Response r, Submit s WHERE s.responseCandidate = :id AND r.id = s.response";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($listResponsesOfCandidateId, PDO::PARAM_INT)
|
||||
));
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function deleteResponseById(int $responseId): void
|
||||
{
|
||||
$query = "DELETE FROM Categorize WHERE response = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$query = "DELETE FROM Submit WHERE response = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId, PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$query = "DELETE FROM Response WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId, PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function insertResponse(string $content, string $questionContent, array $category): int
|
||||
{
|
||||
$query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($content, PDO::PARAM_STR),
|
||||
':questionContent' => array($questionContent, PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
$idResponse = $this->connection->lastInsertId();
|
||||
|
||||
|
||||
foreach ($category as $keyword) {
|
||||
$query = "INSERT INTO Categorize (response, keyword) VALUES(:response, :keyword)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':response' => array($idResponse, PDO::PARAM_STR),
|
||||
':keyword' => array($keyword, PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
return $idResponse;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue