Skip to content

Commit

Permalink
Merge branch 'develop' into feature/manage-an-exercise-page
Browse files Browse the repository at this point in the history
  • Loading branch information
EthannSchneider committed Sep 26, 2024
2 parents 56a7cb7 + adb93e4 commit 685d1f9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/models/databases_connectors/databases_access.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ public function doesExerciseExist(int $id): bool;
public function createExercise(string $title): int;

public function getExerciseTitle(int $id): string;

public function getExercises(): array;

public function getExercisesAnswering(): array;
}
13 changes: 12 additions & 1 deletion src/models/databases_connectors/postgresql/postgresql_access.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ public function createExercise(string $title): int

public function getExerciseTitle(int $id): string
{
return $this->postgresql->select('SELECT title FROM exercises WHERE id = :id', [':id' => $id]);
$result = $this->postgresql->select('SELECT title FROM exercises WHERE id = :id', [':id' => $id]);
return $result[0]['title'];
}

public function getExercises(): array
{
return $this->postgresql->select('SELECT id FROM exercises;');
}

public function getExercisesAnswering(): array
{
return $this->postgresql->select('SELECT id FROM exercises WHERE status = 1;');
}

private function create_db_if_not_exist()
Expand Down
28 changes: 28 additions & 0 deletions src/models/exercise.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@ public function getTitle()
{
return $this->database_access->getexerciseTitle($this->id);
}

public static function getExercises()
{
$database_access = (new DatabasesChoose())->getDatabase();
$exercises_data = $database_access->getExercises();

$exercises = [];
foreach ($exercises_data as $exercise_data) {
$exercise = new self($exercise_data['id']);
$exercises[] = $exercise;
}

return $exercises;
}

public static function getExercisesAnswering()
{
$database_access = (new DatabasesChoose())->getDatabase();
$exercises_data = $database_access->getExercisesAnswering();

$exercises = [];
foreach ($exercises_data as $exercise_data) {
$exercise = new self($exercise_data['id']);
$exercises[] = $exercise;
}

return $exercises;
}
}
19 changes: 5 additions & 14 deletions src/views/exercises_root.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
$title = 'ExerciseLooper';
include_once MODEL_DIR . '/exercise.php';
$exercises = exercises::getExercisesAnswering();

ob_start();
?>
Expand All @@ -13,27 +15,16 @@
</header>

<main class="container">
<?php
$exercises = [
[
'id' => 1,
'name' => 'Anglais'
],
[
'id' => 2,
'name' => 'Francais'
]
]
?>

<ul class="answering-list">
<?php foreach ($exercises as $exercise): ?>
<li class="row">
<div class="column card">
<div class="title">
<?= htmlspecialchars($exercise['name']); ?>
<?= htmlspecialchars($exercise->getTitle()); ?>
</div>
<a class="button"
href="/exercises/<?= $exercise['id']; ?>/fulfillments/new">Take
href="/exercises/<?= $exercise->getId(); ?>/fulfillments/new">Take
it</a>
</div>
</li>
Expand Down

0 comments on commit 685d1f9

Please sign in to comment.