Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Desafio Leandro ivanaga #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MYSQL_HOST=localhost
MYSQL_DATABASE=desafio_tecnofit_leandro_ivanaga;
MYSQL_USER=desafio_ivanaga
MYSQL_PASS=tecnofit
5 changes: 5 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
131 changes: 131 additions & 0 deletions Controllers/Admin/AthleteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
require PATH_PROJECT . "Controllers/Controller.php";
require PATH_PROJECT . "Services/UserServices.php";

class AthleteController extends Controller
{
public function index() {
$list = UserServices::getUsersByProfile("ATHLETE");

$this->view("admin/athlete/index.php", compact("list"));
}

public function getUser() {

$request["id"] = $_GET["id"];

$user = UserServices::getUserById($request);

if(isset($_GET["return"]) && $_GET["return"] == "JSON") {
echo json_encode($user->toArray());
}
}

public function getTrainingsByUser() {

$request["id"] = $_GET["id"];

// treinos disponiveis a vincular
$return["listTrainings"] = UserServices::getTrainingsAvaliableByUser($request);

// treinos vinculados
$list = UserServices::getTrainingsByUser($request);

$return["htmlTrainings"] = $this->partialView("admin/athlete/training-list.php", compact("list"));
echo json_encode($return);
}

public function linkTraining() {

$request["id"] = @$_POST["id"];
$request["id_user"] = $_POST["id_user"];
$request["id_training"] = $_POST["id_training"];

$result = UserServices::saveUserTraining($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Treino salvo com sucesso.";

$request["id"] = $request["id_user"];
// treinos disponiveis a vincular
$return["listTrainings"] = UserServices::getTrainingsAvaliableByUser($request);

// treinos vinculados
$list = UserServices::getTrainingsByUser($request);

$return["htmlTrainings"] = $this->partialView("admin/athlete/training-list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function removeTraining() {

$request["id"] = $_POST["id"];
$request["id_user"] = $_POST["id_user"];

$result = UserServices::deleteUserTraining($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Treino salvo com sucesso.";

$request["id"] = $request["id_user"];
// treinos disponiveis a vincular
$return["listTrainings"] = UserServices::getTrainingsAvaliableByUser($request);

// treinos vinculados
$list = UserServices::getTrainingsByUser($request);

$return["htmlTrainings"] = $this->partialView("admin/athlete/training-list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function save() {

$request["id"] = $_POST["id"];
$request["name"] = trim($_POST["name"]);
$request["login"] = trim($_POST["login"]);
$request["pass"] = md5(trim($_POST["pass"]));

$result = UserServices::saveUser($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Atleta salvo com sucesso.";

$list = UserServices::getUsersByProfile("ATHLETE");
$return["html"] = $this->partialView("admin/athlete/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function removeUser() {

$request["id"] = $_POST["id"];

if(UserServices::deleteUser($request)) {
$return["result"] = true;
$return["msg"] = "Removido com sucesso.";

$list = UserServices::getUsersByProfile("ATHLETE");
$return["html"] = $this->partialView("admin/athlete/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;;
}

echo json_encode($return);
}
}
?>
63 changes: 63 additions & 0 deletions Controllers/Admin/ExerciseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
require PATH_PROJECT . "Controllers/Controller.php";
require PATH_PROJECT . "Services/ExerciseServices.php";

class ExerciseController extends Controller
{
public function index() {
$list = ExerciseServices::getExercises();

$this->view("admin/exercise/index.php", compact("list"));
}

public function getExercise() {

$request["id"] = $_GET["id"];

$exercise = ExerciseServices::getExerciseById($request);

if(isset($_GET["return"]) && $_GET["return"] == "JSON") {
echo json_encode($exercise->toArray());
}
}

public function save() {

$request["id"] = $_POST["id"];
$request["name"] = trim($_POST["name"]);

$result = ExerciseServices::saveExercise($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Exercício salvo com sucesso.";

$list = ExerciseServices::getExercises();
$return["html"] = $this->partialView("admin/exercise/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function removeExercise() {

$request["id"] = $_POST["id"];

$result = ExerciseServices::deleteExercise($request);
if($result === true) {
$return["result"] = true;
$return["msg"] = "Removido com sucesso.";

$list = ExerciseServices::getExercises();
$return["html"] = $this->partialView("admin/exercise/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}
}
?>
134 changes: 134 additions & 0 deletions Controllers/Admin/TrainingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
require PATH_PROJECT . "Controllers/Controller.php";
require PATH_PROJECT . "Services/TrainingServices.php";

class TrainingController extends Controller
{
public function index() {
$list = TrainingServices::getTrainings();

$this->view("admin/training/index.php", compact("list"));
}

public function getTraining() {

$request["id"] = $_GET["id"];

$training = TrainingServices::getTrainingById($request);

if(isset($_GET["return"]) && $_GET["return"] == "JSON") {
echo json_encode($training->toArray());
}
}

public function getTrainingExercise() {

$request["id"] = $_GET["id"];

// exercicios disponiveis a vincular
$return["listExercises"] = TrainingServices::getExercisesAvaliableByTraining($request);

// exercicios vinculados
$list = TrainingServices::getTrainingExerciseById($request);

$return["htmlExercises"] = $this->partialView("admin/training/exercise-list.php", compact("list"));
echo json_encode($return);
}

public function linkExercise() {

$request["id"] = @$_POST["id"];
$request["id_training"] = $_POST["id_training"];
$request["id_exercise"] = $_POST["id_exercise"];
$request["session"] = $_POST["session"];

$result = TrainingServices::saveTrainingExercise($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Treino salvo com sucesso.";

$request["id"] = $request["id_training"];
$return["listExercises"] = TrainingServices::getExercisesAvaliableByTraining($request);

// exercicios vinculados
$list = TrainingServices::getTrainingExerciseById($request);
$return["htmlExercises"] = $this->partialView("admin/training/exercise-list.php", compact("list"));

// lista geral de treinos
$list = TrainingServices::getTrainings();
$return["html"] = $this->partialView("admin/training/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function removeExercise() {

$request["id"] = $_POST["id"];

$result = TrainingServices::deleteTrainingExercise($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Treino salvo com sucesso.";

$request["id"] = $_POST["id_training"];

$return["listExercises"] = TrainingServices::getExercisesAvaliableByTraining($request);

// exercicios vinculados
$list = TrainingServices::getTrainingExerciseById($request);
$return["htmlExercises"] = $this->partialView("admin/training/exercise-list.php", compact("list"));

// lista geral de treinos
$list = TrainingServices::getTrainings();
$return["html"] = $this->partialView("admin/training/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function save() {

$request["id"] = $_POST["id"];
$request["name"] = trim($_POST["name"]);

$result = TrainingServices::saveTraining($request);
if ($result === true) {
$return["result"] = true;
$return["msg"] = "Treino salvo com sucesso.";

$list = TrainingServices::getTrainings();
$return["html"] = $this->partialView("admin/training/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;
}

echo json_encode($return);
}

public function removeTraining() {

$request["id"] = $_POST["id"];

if(TrainingServices::deleteTraining($request)) {
$return["result"] = true;
$return["msg"] = "Removido com sucesso.";

$list = TrainingServices::getTrainings();
$return["html"] = $this->partialView("admin/training/list.php", compact("list"));
} else {
$return["result"] = false;
$return["msg"] = $result;;
}

echo json_encode($return);
}
}
?>
Loading