return the different types of workouts from the api #3

Manually merged
goeranh merged 1 commits from development into master 2020-03-29 22:52:02 +02:00
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
class WorkoutType{
public $id, $name, $description, $type, $unit;
/**
* WorkoutType constructor.
* @param $id
* @param $name
* @param $description
* @param $type
* @param $unit
*/
public function __construct($id, $name, $description, $type, $unit)
{
$this->id = $id;
$this->name = $name;
$this->description = $description;
$this->type = $type;
$this->unit = $unit;
}
}

37
html/api/exercises.php Normal file
View File

@ -0,0 +1,37 @@
<?php
include "../../config.php";
include "Models/WorkoutType.php";
if (isset($_GET['token'])){
$sql = "SELECT * FROM tokens INNER JOIN users ON users.id=tokens.user WHERE token=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['token']);
if ($stmt->execute()){
if ($stmt->rowCount() == 1){
$userData = $stmt->fetchAll(PDO::FETCH_ASSOC);
$username = $userData[0]['username'];
$userID = $userData[0]['user'];
$sql = "select workout_types.id, name, description, type, unit from workout_types inner join workout_type_measurements on workout_types.measurement=workout_type_measurements.id ";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $userID);
if ($stmt->execute()){
$workoutTypes = $stmt->fetchAll(PDO::FETCH_ASSOC);
$returnTypes = array();
foreach ($workoutTypes as $workoutType){
$returnTypes[] = new WorkoutType($workoutType['id'], $workoutType['name'], $workoutType['description'], $workoutType['unit'], $workoutType['unit']);
}
header('Content-Type: application/json');
echo json_encode($workoutTypes);
}
}else{
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
}
}else{
var_dump($stmt->errorInfo());
}
//header('Content-Type: application/json');
}else{
}