|
|
@ -4,6 +4,8 @@ namespace App\Controller;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Container;
|
|
|
|
use App\Container;
|
|
|
|
use App\Router\Request\IRequest;
|
|
|
|
use App\Router\Request\IRequest;
|
|
|
|
|
|
|
|
use App\Router\Response\IResponse;
|
|
|
|
|
|
|
|
use App\Router\Response\RedirectResponse;
|
|
|
|
use App\Router\Response\Response;
|
|
|
|
use App\Router\Response\Response;
|
|
|
|
use Manager\ActivityManager;
|
|
|
|
use Manager\ActivityManager;
|
|
|
|
use Shared\Attributes\Route;
|
|
|
|
use Shared\Attributes\Route;
|
|
|
@ -41,67 +43,53 @@ class HeartRateController extends BaseController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[Route(path: '/upload', name: 'upload', methods: ['POST'])]
|
|
|
|
#[Route(path: '/upload', name: 'upload', methods: ['POST'])]
|
|
|
|
public function uploadFile(string $activityType, int $effort, IRequest $req): Response
|
|
|
|
public function uploadFile(string $activityType, int $effort, IRequest $req): IResponse
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$error = [];
|
|
|
|
$error = $this->validateRequest($effort);
|
|
|
|
/*$fileType = strtolower(pathinfo($_FILES["uploaded_file"]["name"], PATHINFO_EXTENSION));
|
|
|
|
if (!empty($error)) {
|
|
|
|
if (!$fileType == "fit") {
|
|
|
|
return $this->renderError($error);
|
|
|
|
$error [] = "";
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// Validate effort
|
|
|
|
|
|
|
|
if ($effort < 0 || $effort > 5) {
|
|
|
|
|
|
|
|
$error [] = 'Invalid effort level.';
|
|
|
|
|
|
|
|
$resp = new Response('Invalid effort level.', 400);
|
|
|
|
|
|
|
|
return $this->render('./page/import.html.twig', [
|
|
|
|
|
|
|
|
'css' => $this->preference->getCookie(),
|
|
|
|
|
|
|
|
'pp' => "test2",
|
|
|
|
|
|
|
|
'user' => "Doe",
|
|
|
|
|
|
|
|
'role' => "Athlète",
|
|
|
|
|
|
|
|
'friendship' => [],
|
|
|
|
|
|
|
|
'analyzes' => [],
|
|
|
|
|
|
|
|
'mails' => [],
|
|
|
|
|
|
|
|
'users' => [],
|
|
|
|
|
|
|
|
'infoUser' => [],
|
|
|
|
|
|
|
|
'exos' => [],
|
|
|
|
|
|
|
|
'member' => [],
|
|
|
|
|
|
|
|
'error' => $error
|
|
|
|
|
|
|
|
], $resp);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* $error [] = 'Le fichier doit être de type d\'une taille inferieur à 10 MB.';*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Move the file to the directory where files are stored
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$tmp_file = $_FILES['uploaded_file']['tmp_name'];
|
|
|
|
$tmp_file = $_FILES['uploaded_file']['tmp_name'];
|
|
|
|
if(file_exists($tmp_file)) {
|
|
|
|
if (!$this->isValidFile($tmp_file)) {
|
|
|
|
$fileExtension = pathinfo($_FILES['uploaded_file']['name'], PATHINFO_EXTENSION);
|
|
|
|
return $this->renderError(['Failed to get file be sure that you provide the file']);
|
|
|
|
if ($fileExtension === 'fit') {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$content = file_get_contents($tmp_file);
|
|
|
|
$content = file_get_contents($tmp_file);
|
|
|
|
if ($this->activityMgr->uploadFile($activityType, 5, $content)) {
|
|
|
|
try {
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
return $this->render('./page/home.html.twig', [
|
|
|
|
|
|
|
|
'css' => $this->preference->getCookie(),
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
Log::dd('Ratter Model');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->activityMgr->uploadFile($activityType, 5, $content)) {
|
|
|
|
|
|
|
|
return new RedirectResponse('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::dd('Le fichier doit être de type .fit.');
|
|
|
|
return $this->renderError([$e->getMessage()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
return $this->renderError(['Failed to save activity.']);
|
|
|
|
Log::dd("failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
private function validateRequest(int $effort): array
|
|
|
|
Log::dd($e);
|
|
|
|
{
|
|
|
|
return new Response('File upload error.', 500);
|
|
|
|
$error = [];
|
|
|
|
|
|
|
|
if ($effort < 0 || $effort > 5) {
|
|
|
|
|
|
|
|
$error[] = 'Invalid effort level.';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$fileExtension = pathinfo($_FILES['uploaded_file']['name'], PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
if ($fileExtension !== 'fit') {
|
|
|
|
|
|
|
|
$error[] = 'Invalid file type. Only .fit files are allowed.';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new Response('Invalid file type.', 400);
|
|
|
|
private function isValidFile(string $tmp_file): bool
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return file_exists($tmp_file) && is_uploaded_file($tmp_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function renderError(array $error): Response
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Consolidez la logique de rendu ici
|
|
|
|
|
|
|
|
return $this->render('./error/error.html.twig', ['title'=> "Failed" , "code" => 400, "name" => "error import", "descr" => $error[0] ], new Response('$error', 400));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|