diff --git a/src/API/APIMuscles.php b/src/API/APIMuscles.php new file mode 100644 index 0000000..1cb4960 --- /dev/null +++ b/src/API/APIMuscles.php @@ -0,0 +1,54 @@ + [ + 'method' => 'POST', + 'params' => [ + 'muscle' => [ + 'require' => true, + 'type' => 'string' + ] + ] + ], + 'get-exercise' => [ + 'method' => 'POST', + 'params' => [ + 'id' => [ + 'required' => true, + 'type' => 'int' + ] + ] + ] + ]; + + public function __construct() { + parent::__construct( $this->declaredFunctions ); + } + + public function getList( $data ) { + $query = "SELECT " . BDTables::EXERCISE . ".id, title FROM " . BDTables::EXERCISE . + " LEFT JOIN " . BDTables::MUSCLES . " ON " . BDTables::MUSCLES . ".id = " . BDTables::EXERCISE . ".muscle + WHERE " . BDTables::MUSCLES . ".muscle = :muscle"; + $query = BDD::instance()->prepare( $query ); + $query->execute( $data ); + + $this->returnJson( json_encode( $query->fetchAll() ) ); + } + + public function getExercise( $data ) { + $query = "SELECT `title`, `video`, `description` FROM " . BDTables::EXERCISE . + " WHERE `id` = :id"; + $query = BDD::instance()->prepare( $query ); + $query->execute( $data ); + + $this->returnJson( json_encode( $query->fetch() ) ); + } + +} \ No newline at end of file diff --git a/src/API/APIUser.php b/src/API/APIUser.php index 16894d9..c7826e6 100644 --- a/src/API/APIUser.php +++ b/src/API/APIUser.php @@ -5,14 +5,12 @@ namespace WebProjectFitness\API; use WebProjectFitness\Model\BDTables; use WebProjectFitness\Model\Model; -class APIUser extends API -{ +class APIUser extends API { private $declaredFunctions = [ 'create' => [ 'method' => 'POST', - 'params' => [ - ] + 'params' => [] ], 'modify' => [ 'method' => 'POST', @@ -105,68 +103,58 @@ class APIUser extends API ] ] ] - - ]; - public function __construct() - { - parent::__construct($this->declaredFunctions); + public function __construct() { + parent::__construct( $this->declaredFunctions ); } //functions for user table. - public function create($data) - { + public function create() { $id = uniqid(); - $id = substr($id, 0, 6); - Model::insert(BDTables::USER, [ + $id = substr( $id, 0, 6 ); + Model::insert( BDTables::USER, [ "name" => "", "user_id" => $id - ]); - $this->returnJson(['id' => $id]); + ] ); + $this->returnJson( [ 'id' => $id ] ); } - public function modify($data) - { - Model::update(BDTables::USER, ['name' => $data['name']], "user_id", $data['user_id']); - $this->returnJson(['name' => $data['name'], 'id' => $data['user_id']]); + public function modify( $data ) { + Model::update( BDTables::USER, [ 'name' => $data[ 'name' ] ], "user_id", $data[ 'user_id' ] ); + $this->returnJson( [ 'name' => $data[ 'name' ], 'id' => $data[ 'user_id' ] ] ); } //Functions for favorite table. - public function favoriteAdd($data) - { - Model::insert(BDTables::FAVORITE, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]); - $this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]); + public function favoriteAdd( $data ) { + Model::insert( BDTables::FAVORITE, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] ); + $this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] ); } - public function favoriteDelete($data) - { - Model::delete(BDTables::FAVORITE, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]); - $this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise']]); + public function favoriteDelete( $data ) { + Model::delete( BDTables::FAVORITE, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] ); + $this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ] ] ); } //functions for training table - public function trainingAdd($data) - { - Model::insert(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]); - $this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]); + public function trainingAdd( $data ) { + Model::insert( BDTables::TRAINING, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] ); + $this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] ); } - public function trainingDelete($data) - { - Model::delete(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]); + public function trainingDelete( $data ) { + Model::delete( BDTables::TRAINING, [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] ); - $this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order']]); + $this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ] ] ); } - public function trainingChangeOrder($data) - { - Model::update_order(BDTables::TRAINING, ['id_user' => $data['id_user'], 'id_order' => $data['id_order'], 'id_exercise' => $data['id_exercise'] ], $data['new_order']); + public function trainingChangeOrder( $data ) { + Model::update_order( BDTables::TRAINING, [ 'id_user' => $data[ 'id_user' ], 'id_order' => $data[ 'id_order' ], 'id_exercise' => $data[ 'id_exercise' ] ], $data[ 'new_order' ] ); - $this->returnJson(['id_user' => $data['id_user'], 'id_exercise' => $data['id_exercise'], 'id_order' => $data['id_order'], 'new_order' => $data['new_order']]); + $this->returnJson( [ 'id_user' => $data[ 'id_user' ], 'id_exercise' => $data[ 'id_exercise' ], 'id_order' => $data[ 'id_order' ], 'new_order' => $data[ 'new_order' ] ] ); } } \ No newline at end of file diff --git a/src/Model/BDTables.php b/src/Model/BDTables.php index a13e582..3114873 100644 --- a/src/Model/BDTables.php +++ b/src/Model/BDTables.php @@ -12,6 +12,7 @@ abstract class BDTables { const FAVORITE = "favorite"; const EXERCISE = "exercise"; const TRAINING = "training"; + const MUSCLES = "muscles"; } ?> \ No newline at end of file diff --git a/src/Model/Model.php b/src/Model/Model.php index 98f8f35..8e1cc91 100644 --- a/src/Model/Model.php +++ b/src/Model/Model.php @@ -46,7 +46,7 @@ class Model { $req->execute( $data ); } - public static function delete (string $tableName, array $data){ + public static function delete( string $tableName, array $data ) { $reqStr = 'DELETE FROM ' . $tableName . ' WHERE '; $lastKey = endKey( $data ); foreach ( $data as $key => $value ) { @@ -63,7 +63,7 @@ class Model { } - public static function update_order( string $tableName, array $data, string $newOrder) { + public static function update_order( string $tableName, array $data, string $newOrder ) { $reqStr = 'UPDATE ' . $tableName . ' SET id_order = :newOrder WHERE '; $lastKey = endKey( $data ); foreach ( $data as $key => $value ) { diff --git a/src/View/Site/Index.php b/src/View/Site/Index.php index c3a2d5b..2295c7a 100644 --- a/src/View/Site/Index.php +++ b/src/View/Site/Index.php @@ -2,7 +2,7 @@
-
Selected part of the body
+
Selected part of the body
@@ -10,22 +10,15 @@
Exercise List
-
Please select a muscle
+
+
Please select a muscle
+
-
-

Title

-
- - - -
- Test -
-
+
\ No newline at end of file diff --git a/src/View/Site/tpl/footer.php b/src/View/Site/tpl/footer.php index 95da1ef..958b416 100644 --- a/src/View/Site/tpl/footer.php +++ b/src/View/Site/tpl/footer.php @@ -1,5 +1,23 @@ + +
+ +