parent
2049a8285c
commit
471e0cdb80
@ -0,0 +1,79 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: Témoignages_Formulaire
|
||||
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
|
||||
|
||||
steps:
|
||||
|
||||
#PHP compilation with php -l
|
||||
- name: PHP_Compilation
|
||||
image: php:8.1
|
||||
commands:
|
||||
- find -name "*.php" -exec php -l "{}" \;
|
||||
|
||||
|
||||
- name: setup_PHP_for_SonarQube
|
||||
image: sonarsource/sonar-scanner-cli
|
||||
environment:
|
||||
SONAR_TOKEN:
|
||||
from_secret: SONARQ_TOKEN
|
||||
commands:
|
||||
|
||||
- sonar-scanner -Dsonar.projectKey=SAE4.01_FORMULAIRE -Dsonar.sources=. -Dsonar.login=$${SONAR_TOKEN} -Dsonar.language=php -Dsonar.host.url=https://codefirst.iut.uca.fr/sonar -Dsonar.php.coverage.reportPaths=coverage.xml
|
||||
|
||||
|
||||
# docker image build
|
||||
- name: set_api_form
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: ./Source/API/Dockerfile
|
||||
context: Source/API
|
||||
registry: hub.codefirst.iut.uca.fr
|
||||
repo: hub.codefirst.iut.uca.fr/dorian.hodin/sae4.01_formulaire
|
||||
username:
|
||||
from_secret: SECRET_USERNAME
|
||||
password:
|
||||
from_secret: SECRET_PASSWD
|
||||
|
||||
# conteneur deployment
|
||||
- name: deploy_api_form
|
||||
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||
environment:
|
||||
IMAGENAME: hub.codefirst.iut.uca.fr/dorian.hodin/sae4.01_formulaire:latest
|
||||
CONTAINERNAME: deploy_api_form
|
||||
COMMAND: create
|
||||
OVERWRITE: true
|
||||
CODEFIRST_CLIENTDRONE_ENV_HOST:
|
||||
from_secret: db_host
|
||||
CODEFIRST_CLIENTDRONE_ENV_DATABASE:
|
||||
from_secret: db_database
|
||||
CODEFIRST_CLIENTDRONE_ENV_USER:
|
||||
from_secret: db_user
|
||||
CODEFIRST_CLIENTDRONE_ENV_PASSWORD:
|
||||
from_secret: db_password
|
||||
CODEFIRST_CLIENTDRONE_ENV_ROOT_PASSWORD:
|
||||
from_secret: db_root_password
|
||||
ADMINS: dorianhodin,alexislamande,baptistebaverel,johanlachenal
|
||||
depends_on: [ set_api_form ]
|
||||
|
||||
# database container deployment
|
||||
- name: db_form
|
||||
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
|
||||
environment:
|
||||
IMAGENAME: mariadb:10.5
|
||||
CONTAINERNAME: db_form
|
||||
COMMAND: create
|
||||
CODEFIRST_CLIENTDRONE_ENV_MARIADB_ROOT_PASSWORD:
|
||||
from_secret: db_root_password
|
||||
CODEFIRST_CLIENTDRONE_ENV_MARIADB_DATABASE:
|
||||
from_secret: db_database
|
||||
CODEFIRST_CLIENTDRONE_ENV_MARIADB_USER:
|
||||
from_secret: db_user
|
||||
CODEFIRST_CLIENTDRONE_ENV_MARIADB_PASSWORD:
|
||||
from_secret: db_password
|
||||
depends_on: [ deploy_api_form ]
|
@ -0,0 +1 @@
|
||||
/Source/API/script/Config/vendor
|
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/SAE4.01_API_FORM.iml" filepath="$PROJECT_DIR$/.idea/SAE4.01_API_FORM.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,7 @@
|
||||
FROM php:8.1-apache
|
||||
RUN apt-get update && apt-get upgrade -y && apt-get install -y git
|
||||
RUN docker-php-ext-install pdo pdo_mysql
|
||||
COPY ./script /var/www/html
|
||||
WORKDIR /var/www/html/Config
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
RUN composer update && composer install
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
class Connection extends PDO
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/** * @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();
|
||||
}
|
||||
|
||||
public function getResults(): array
|
||||
{
|
||||
return $this->stmt->fetchAll();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "dorian/script",
|
||||
"description": "Composer for API",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"slim/slim": "^4.11",
|
||||
"slim/psr7": "dev-master",
|
||||
"psr/http-message": "^1.0",
|
||||
"guzzlehttp/psr7": "^2.4",
|
||||
"guzzlehttp/guzzle": "^7.5",
|
||||
"selective/basepath": "^2.1"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Config\Connection;
|
||||
|
||||
require_once __DIR__ ."/Connection.php";
|
||||
|
||||
|
||||
function connect(): int|Connection
|
||||
{
|
||||
|
||||
$dsn = "mysql:host=".$_ENV["HOST"].";dbname=".$_ENV["DATABASE"].";";
|
||||
$login = $_ENV["USER"];
|
||||
$password = $_ENV["PASSWORD"];
|
||||
|
||||
try {
|
||||
|
||||
$connection = new Connection($dsn,$login,$password);
|
||||
|
||||
}catch (PDOException){
|
||||
|
||||
http_response_code(404);
|
||||
return http_response_code();
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
use Config\Connection;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayForm
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function insertForm(array $parameters): void
|
||||
{
|
||||
if(empty($this->getForm(array())))
|
||||
{
|
||||
$query = "INSERT INTO Form(title, description) VALUES(:title, :description)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':title' => array($parameters[0], PDO::PARAM_STR), //parameters[0] = title of the form
|
||||
':description' => array($parameters[1], PDO::PARAM_STR) //parameters[1] = description of the form
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function getForm(array $ignore): array //parameters never used cause every function require this parameter
|
||||
{
|
||||
$query = "SELECT * FROM Form";
|
||||
$this->connection->executeQuery($query);
|
||||
$result = $this->connection->getResults();
|
||||
print(json_encode($result));
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function deleteForm(array $idform): void
|
||||
{
|
||||
$query = "DELETE FROM Form WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($idform[0], PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function selectForDeleteAndInsert(int $idQuestion, string $response){
|
||||
$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)
|
||||
));
|
||||
|
||||
return $this->connection->getResults()[0][0];
|
||||
}
|
||||
|
||||
public function assignKeywordToQuestion(array $parameters): void
|
||||
{
|
||||
$query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':possibleResponse' => array($this->selectForDeleteAndInsert($parameters[2],$parameters[1]), PDO::PARAM_INT),
|
||||
':keyword' => array($parameters[0], PDO::PARAM_STR) //parameters[0] = keyword
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteKeywordFromQuestion(array $parameters): void
|
||||
{
|
||||
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':possibleResponse' => array($this->selectForDeleteAndInsert($parameters[2],$parameters[1]), PDO::PARAM_INT),
|
||||
':keyword' => array($parameters[0], PDO::PARAM_STR) //parameters[0] = keyword
|
||||
));
|
||||
}
|
||||
|
||||
public function updateTitleToForm(array $parameters): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':title' => array($parameters[0], PDO::PARAM_STR), //parameters[0] = title
|
||||
':id' => array($parameters[1], PDO::PARAM_INT) //parameters[1] = idForm
|
||||
));
|
||||
}
|
||||
|
||||
public function updateDescriptionToForm(array $parameters): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE description = :description";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':description' => array($parameters[0], PDO::PARAM_STR), //parameters[0] = description
|
||||
':id' => array($parameters[1], PDO::PARAM_INT) //parameters[1] = idForm
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteDescriptionToForm(array $idForm): void
|
||||
{
|
||||
$query = "UPDATE Form SET title = :title WHERE description = :description";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':description' => array('', PDO::PARAM_STR),
|
||||
':id' => array($idForm[0], PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayKeyword
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function insertKeyword(array $keyword): void
|
||||
{
|
||||
$query = "INSERT INTO Keyword(word) VALUES(:word)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':word' => array($keyword[0], PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function deleteKeyword(array $keyword): void
|
||||
{
|
||||
$query = "DELETE FROM Keyword WHERE word = :word";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':word' => array($keyword[0], PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function getAllKeyword(array $ignore): void
|
||||
{
|
||||
$query = "SELECT * FROM Keyword";
|
||||
$this->connection->executeQuery($query);
|
||||
$result = $this->connection->getResults();
|
||||
print(json_encode($result));
|
||||
}
|
||||
|
||||
public function getKeywordsContentByReference(array $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[0], PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
|
||||
$tab = [];
|
||||
foreach ($this->connection->getResults() as $result)
|
||||
{
|
||||
$tab[] = $result["word"];
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayListResponseOfCandidate
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getDetailsListResponsesOfCandidate(array $idListResponse): void
|
||||
{
|
||||
$gatewayResponse = new GatewayResponse();
|
||||
$gatewayKeyword = new GatewayKeyword();
|
||||
$tabKeywords = [];
|
||||
|
||||
$query = "SELECT * FROM ListResponsesOfCandidate WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($idListResponse[0], PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$questionList = $this->connection->getResults()[0];
|
||||
|
||||
$responses = $gatewayResponse->getResponsesByIdListCandidate($questionList['id']);
|
||||
|
||||
foreach ($responses as $row) {
|
||||
$tabKeywords[] = $gatewayKeyword->getKeywordsContentByReference(array($row['id']));
|
||||
}
|
||||
|
||||
print(json_encode(array($questionList, $responses, $tabKeywords)));
|
||||
}
|
||||
|
||||
public function getAllListResponsesOfCandidate(array $ignore): void
|
||||
{
|
||||
$query = "SELECT * FROM ListResponsesOfCandidate";
|
||||
$this->connection->executeQuery($query);
|
||||
|
||||
print(json_encode($this->connection->getResults()));
|
||||
}
|
||||
|
||||
public function deleteListResponseOfCandidate(array $id): void
|
||||
{
|
||||
$gatewayResponse = new GatewayResponse();
|
||||
|
||||
foreach ( $gatewayResponse->getResponsesIdByIdListCandidate($id[0]) as $response){
|
||||
$gatewayResponse->deleteResponseById(array($response));
|
||||
}
|
||||
|
||||
$query = "DELETE FROM ListResponsesOfCandidate WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
'id' => array($id[0], PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function insertListResponsesOfCandidate(array $parameters): 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($parameters[3], PDO::PARAM_STR) //parameters[3] = titleForm
|
||||
));
|
||||
|
||||
$idListQuestion = $this->connection->lastInsertId();
|
||||
|
||||
for($i = 0; $i < count($parameters[1]); $i++) //parameters[1] = answer
|
||||
{
|
||||
$idResponse = $gatewayResponse->insertResponse(array($gatewayQuestion->getQuestionContentById(array($parameters[0][$i])), $parameters[1][$i], $parameters[2][$i])); //parameters[1] = answer, parameters[2] = category, parameters[3] = id
|
||||
|
||||
$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)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayPossibleResponse
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getPossibleResponseByQuestion(array $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[0], PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function insertPossibleResponse(array $contentPossibleResponse): int
|
||||
{
|
||||
$query = "INSERT INTO PossibleResponse(content) VALUES(:content)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($contentPossibleResponse[0], PDO::PARAM_STR)
|
||||
));
|
||||
|
||||
return $this->connection->lastInsertId();
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use BusinessClassAPI\BoxQuestionAPI;
|
||||
use BusinessClassAPI\QuestionAPI;
|
||||
use BusinessClassAPI\TextQuestionAPI;
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayQuestion
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function insertQuestion(QuestionAPI $question, int $idForm): void
|
||||
{
|
||||
$gatewayPossibleResponse = new GatewayPossibleResponse();
|
||||
|
||||
$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)
|
||||
));
|
||||
|
||||
$idQuestion = $this->connection->lastInsertId();
|
||||
|
||||
if(get_class($question) != TextQuestionAPI::class){
|
||||
$listPossibleResponse = $question->getPossibleResponses();
|
||||
|
||||
for($i = 0; $i < count($listPossibleResponse); $i++){
|
||||
|
||||
$idPossibleResponse = $gatewayPossibleResponse->insertPossibleResponse($listPossibleResponse[$i]);
|
||||
|
||||
$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 ($question->getCategories()[$i] as $keyword){
|
||||
$gatewayForm = new GatewayForm();
|
||||
$gatewayForm->assignKeywordToQuestion(array($keyword, $listPossibleResponse[$i], $idQuestion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteQuestion(QuestionAPI $question): void
|
||||
{
|
||||
if(get_class($question) == BoxQuestionAPI::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(QuestionAPI $question): void
|
||||
{
|
||||
$query = "UPDATE Question SET content = :content, type = :type, form = :form WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($question->getContent(), PDO::PARAM_STR),
|
||||
':type' => array(get_class($question), PDO::PARAM_STR),
|
||||
':form' => array($question->getForm(), PDO::PARAM_STR),
|
||||
':id' => array($question->getId(), PDO::PARAM_STR)
|
||||
));
|
||||
}
|
||||
|
||||
public function getAllQuestions(array $idForm): void //print en json un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox
|
||||
{
|
||||
$query = "SELECT * FROM Question WHERE form = :form";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':form' => array($idForm[0], 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") {
|
||||
$possibleResponses = $gatewayPossibleResponse->getPossibleResponseByQuestion(array($listQuestions[$i]["id"])); //$this->connection->getResults();
|
||||
|
||||
$tmpTabKeyword = [];
|
||||
$tmpTabPossibleResponse = [];
|
||||
foreach ($possibleResponses as $row){
|
||||
$tmpTabKeyword[] = $gatewayKeyword->getKeywordsContentByReference(array($row["id"]));
|
||||
|
||||
$tmpTabPossibleResponse[] = $row["content"];
|
||||
}
|
||||
$possibleResponsesContent[] = $tmpTabPossibleResponse;
|
||||
$keywordsResponses[] = $tmpTabKeyword;
|
||||
}
|
||||
else{
|
||||
$possibleResponsesContent[] = null;
|
||||
$keywordsResponses[] = null;
|
||||
}
|
||||
}
|
||||
print(json_encode(array($listQuestions, $possibleResponsesContent, $keywordsResponses)));
|
||||
}
|
||||
print (json_encode(array()));
|
||||
}
|
||||
|
||||
public function getQuestionContentById(array $id): string
|
||||
{
|
||||
$query = "SELECT content FROM Question WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($id[0], PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
return $this->connection->getResults()[0][0];
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
use Config\Connection;
|
||||
use PDO;
|
||||
|
||||
class GatewayResponse
|
||||
{
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->connection = connect();
|
||||
}
|
||||
|
||||
public function getResponsesByIdListCandidate(array $listResponsesOfCandidateId): array
|
||||
{
|
||||
|
||||
$result = $this->getResponsesIdByIdListCandidate(array($listResponsesOfCandidateId[0]));
|
||||
$tab = [];
|
||||
foreach ($result as $row){
|
||||
$tab[] = (new GatewayKeyword())->getKeywordsContentByReference(array($row['id']));
|
||||
}
|
||||
|
||||
return array($result, $tab);
|
||||
}
|
||||
|
||||
public function getResponsesIdByIdListCandidate(array $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[0], PDO::PARAM_INT)
|
||||
));
|
||||
return $this->connection->getResults();
|
||||
}
|
||||
|
||||
public function deleteResponseById(array $responseId): void
|
||||
{
|
||||
$query = "DELETE FROM Categorize WHERE response = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId[0], PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$query = "DELETE FROM Submit WHERE response = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId[0], PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$query = "DELETE FROM Response WHERE id = :id";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':id' => array($responseId[0], PDO::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
public function insertResponse(array $parameters): int
|
||||
{
|
||||
$query = "INSERT INTO Response(content, questionContent) VALUES (:content, :questionContent)";
|
||||
$this->connection->executeQuery($query, array(
|
||||
':content' => array($parameters[0], PDO::PARAM_STR), //parameters[0] = content
|
||||
':questionContent' => array($parameters[1], PDO::PARAM_STR) //parameters[1] = questionContent
|
||||
));
|
||||
|
||||
$idResponse = $this->connection->lastInsertId();
|
||||
|
||||
|
||||
foreach ($parameters[2] as $keyword){ //parameters[2] = category (array)
|
||||
$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;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Exception\HttpNotFoundException;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Selective\BasePath\BasePathMiddleware;
|
||||
|
||||
try{
|
||||
require 'Config/vendor/autoload.php';
|
||||
|
||||
/**
|
||||
* Instantiate App
|
||||
*/
|
||||
$app = AppFactory::create();
|
||||
|
||||
// Add Routing Middleware
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
// Set the base path to run the app in a subdirectory.
|
||||
// This path is used in urlFor().
|
||||
$app->add(new BasePathMiddleware($app));
|
||||
/**
|
||||
* Add Error Handling Middleware
|
||||
*
|
||||
* @param bool $displayErrorDetails -> Should be set to false in production
|
||||
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
|
||||
* @param bool $logErrorDetails -> Display error details in error log
|
||||
*/
|
||||
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
||||
|
||||
$app->get('/', function (Request $request, Response $response) {
|
||||
$response->getBody()->write("Hello, this is the base page");
|
||||
return $response;
|
||||
});
|
||||
|
||||
|
||||
$app->get('/api/{method}', function (Request $request, Response $response, $args) {
|
||||
$method = $args['method'];
|
||||
$parameters = $request->getQueryParams();
|
||||
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
|
||||
foreach ($listGateway as $gateway) // Pour chaque Gateway
|
||||
{
|
||||
if (method_exists($gateway, $method)) {
|
||||
(new $gateway)->$method($parameters); // Si oui, on appelle cette fonction
|
||||
}
|
||||
}
|
||||
$response->getBody()->write("Use the method $method, with the parameters ");
|
||||
return $response;
|
||||
});
|
||||
// Run app
|
||||
$app->run();
|
||||
}catch (HttpNotFoundException|Exception $e){
|
||||
echo "Error :".$e->getMessage();
|
||||
}
|
||||
|
Loading…
Reference in new issue