✨ 💩 🚧 add TrainingRepository and and Training Menu in Console.php
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
5c925326a9
commit
a696e4eb5a
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Repository;
|
||||||
|
|
||||||
|
interface ITrainingRepository extends IGenericRepository {
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Stub;
|
||||||
|
|
||||||
|
use Model\Athlete;
|
||||||
|
use Model\CoachAthlete;
|
||||||
|
use Model\Training;
|
||||||
|
use Model\User;
|
||||||
|
use Repository\ITrainingRepository;
|
||||||
|
|
||||||
|
class TrainingRepository implements ITrainingRepository {
|
||||||
|
private array $training = [];
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->training[] = new Training(1, new \DateTime("1985-05-10"), 48.5, 55.8, "john.doe@example.com", "hello");
|
||||||
|
$this->training[] = new Training(2, new \DateTime("1986-06-12"), 48.5, 55.8, "john.doe@exavdffgmple.com", "hedfdfllo");
|
||||||
|
$this->training[] = new Training(3, new \DateTime("1989-07-14"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedfdfllo");
|
||||||
|
$this->training[] = new Training(4, new \DateTime("1990-08-16"), 48.5, 55.8, "john.doe@exdfdfample.com", "hedffdllo");
|
||||||
|
$this->training[] = new Training(5, new \DateTime("2000-09-18"), 48.5, 55.8, "john.doe@exdffdample.com", "hedfdfllo");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItemById(int $id): ?Training {
|
||||||
|
foreach ($this->training as $training) {
|
||||||
|
if ($training->getId() === $id) {
|
||||||
|
return $training;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetNbItems(): int {
|
||||||
|
return count($this->training);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
|
||||||
|
// Cette méthode est un exemple simple, on ne gère pas l'ordonnancement ici
|
||||||
|
return array_slice($this->training, $index, $count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
|
||||||
|
$filteredTrainings = array_filter($this->training, function ($training) use ($substring) {
|
||||||
|
return strpos(strtolower($training->getDescription()), strtolower($substring)) !== false || strpos(strtolower($training->getFeedback()), strtolower($substring)) !== false;
|
||||||
|
});
|
||||||
|
return array_slice($filteredTrainings, $index, $count);
|
||||||
|
}
|
||||||
|
public function GetItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): ?Training {
|
||||||
|
$filteredTrainings = $this->GetItemsByName($substring, $index, $count, $orderingPropertyName, $descending);
|
||||||
|
return isset($filteredTrainings[0]) ? $filteredTrainings[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// should have type here
|
||||||
|
public function UpdateItem($oldTraining, $newTraining): void {
|
||||||
|
$index = array_search($oldTraining, $this->training);
|
||||||
|
if ($index !== false) {
|
||||||
|
$this->training[$index] = $newTraining;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// should have type here
|
||||||
|
public function AddItem($training): void {
|
||||||
|
$this->training[] = $training;
|
||||||
|
}
|
||||||
|
|
||||||
|
// should have type here
|
||||||
|
public function DeleteItem($training): bool {
|
||||||
|
$index = array_search($training, $this->training);
|
||||||
|
if ($index !== false) {
|
||||||
|
unset($this->training[$index]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue