upaded merged branch
continuous-integration/drone/push Build is failing Details

master
Antoine PEREDERII 1 year ago
parent 74a79a055c
commit 8d1953c4c4

@ -0,0 +1,107 @@
<mxfile host="app.diagrams.net" modified="2023-09-25T06:43:46.406Z" agent="Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0" etag="e-4pS3rH9xNpreRilvi5" version="21.8.2" type="device">
<diagram name="Page-1" id="2OfyMqm8PIhWsBFCJvOv">
<mxGraphModel dx="2049" dy="1071" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="Ym5UIEUMnJ661rIFWdHi-1" value="Sportif&lt;br&gt;" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" parent="1" vertex="1">
<mxGeometry x="100" y="240" width="30" height="60" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-6" value="" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="230" y="170" width="340" height="890" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-7" value="Application FitWeb" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="340" y="170" width="120" height="30" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-8" value="" style="endArrow=none;html=1;rounded=0;exitX=-0.006;exitY=0.037;exitDx=0;exitDy=0;exitPerimeter=0;" parent="1" source="Ym5UIEUMnJ661rIFWdHi-6" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="230" y="201" as="sourcePoint" />
<mxPoint x="570" y="200" as="targetPoint" />
<Array as="points" />
</mxGeometry>
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-9" value="" style="ellipse;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="320" y="220" width="160" height="100" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-10" value="Analyser la fréquence cardique" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="332" y="255" width="136" height="30" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-22" value="" style="ellipse;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="320" y="355" width="160" height="100" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-23" value="Statistique condition physique&amp;nbsp;&amp;nbsp;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="340" y="375" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="Ym5UIEUMnJ661rIFWdHi-26" value="Améliorer les entrainements" style="ellipse;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="320" y="485" width="158" height="100" as="geometry" />
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-7" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" target="Ym5UIEUMnJ661rIFWdHi-9" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="130" y="270" as="sourcePoint" />
<mxPoint x="310" y="270" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-9" value="" style="endArrow=classic;html=1;rounded=0;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="130" y="280" as="sourcePoint" />
<mxPoint x="320" y="390" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-10" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0;entryDx=0;entryDy=0;" parent="1" target="Ym5UIEUMnJ661rIFWdHi-26" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="130" y="290" as="sourcePoint" />
<mxPoint x="320" y="485" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-11" value="Développeur" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" parent="1" vertex="1">
<mxGeometry x="712" y="930" width="30" height="60" as="geometry" />
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-13" value="" style="endArrow=classic;html=1;rounded=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" edge="1" source="gRiRGuH9TPFdmmPZYA_R-11">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="132" y="857.5" as="sourcePoint" />
<mxPoint x="480" y="960" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="gRiRGuH9TPFdmmPZYA_R-15" value="&lt;font style=&quot;font-size: 16px;&quot;&gt;Diagramme de cas d&#39;utilisation de l&#39;application Fit Web&lt;/font&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="199" y="60" width="400" height="30" as="geometry" />
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-1" value="Coach Sportif" style="shape=umlActor;verticalLabelPosition=bottom;verticalAlign=top;html=1;outlineConnect=0;" vertex="1" parent="1">
<mxGeometry x="712" y="630" width="30" height="60" as="geometry" />
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-5" value="Consulter les statistiques de son équipe" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="318" y="610" width="158" height="100" as="geometry" />
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-6" value="Développer et maintenir l&#39;application" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320" y="910" width="158" height="100" as="geometry" />
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-7" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="710" y="660" as="sourcePoint" />
<mxPoint x="480" y="660" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-8" value="&amp;nbsp;Reporter un bug" style="ellipse;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="318" y="740" width="158" height="100" as="geometry" />
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-9" value="" style="endArrow=classic;html=1;rounded=0;entryX=1;entryY=0.41;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" target="aGqo4vDs0eBD3chBgCWU-8">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="710" y="670" as="sourcePoint" />
<mxPoint x="792" y="730" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-12" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" target="aGqo4vDs0eBD3chBgCWU-8">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="140" y="330" as="sourcePoint" />
<mxPoint x="160" y="385" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="aGqo4vDs0eBD3chBgCWU-13" value="" style="endArrow=none;dashed=1;html=1;dashPattern=1 3;strokeWidth=2;rounded=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="aGqo4vDs0eBD3chBgCWU-8" target="aGqo4vDs0eBD3chBgCWU-6">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="268" y="930" as="sourcePoint" />
<mxPoint x="318" y="880" as="targetPoint" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

@ -0,0 +1,27 @@
sdfg
pour gerer l'accès aux données, nous avons cette structure la :
```plantuml couche d'accès aux données
class abstract IGenericRepository {
+ getItemById(int id) : object
+ getNbItems() : int
+ getItems(int index, int count, string orderingPropertyName, bool descending) : array
+ getItemsByName(string substring, int index, int count, string orderingPropertyName, bool descending) : array
+ getItemByName(string substring, int index, int count, string orderingPropertyName, bool descending) : object
+ updateItem(oldItem, newItem) : void
+ addItem(item) : void
+ deleteItem(item) : bool
}
class abstract IUserRepository extends IGenericRepository {
+ addFriend(int user1,int user2) : void
+ deleteFriend(int user1,int user2) : void
}
interface INotificationRepository extends IGenericRepository {
}
interface IRelationshipRequestRepository extends IGenericRepository {
}
class abstract dataManager {
//possede tout les IRepository extends de IGenericRepository
+ void save()
+ void load()
}
```

Binary file not shown.

Binary file not shown.

@ -0,0 +1,32 @@
<?php
namespace Console;
use Manager\ActivityManager;
use Manager\AthleteManager;
use Manager\CoachManager;
use Manager\DataManager;
use Manager\UserManager;
use Network\RelationshipService;
use Stub\NotificationService;
use Stub\StubData;
class Model
{
public UserManager $userMgr;
public CoachManager $coachMgr;
public DataManager $dataManager;
public AthleteManager $athleteMgr;
public ActivityManager $activityMgr;
public function __construct()
{
$this->dataManager = new StubData();
$authService = new \Stub\AuthService($this->dataManager->userRepository, new \Shared\HashPassword());
$notificationService = new NotificationService($this->dataManager->notificationRepository,$this->dataManager->userRepository);
$relationshipService = new RelationshipService($this->dataManager->relationshipRequestRepository,$notificationService);
$this->userMgr = new UserManager($this->dataManager,$authService,$relationshipService);
$this->athleteMgr = new AthleteManager($this->dataManager,$authService);
$this->coachMgr = new CoachManager($this->dataManager,$authService);
$this->activityMgr = new ActivityManager($this->dataManager,$authService);
}
}

@ -0,0 +1,13 @@
<?php
namespace Network;
use Model\RelationshipRequest;
use Model\User;
interface IFriendRequestService {
public function sendRequest(User $fromUser, User $toUser);
public function acceptRequest(RelationshipRequest $request);
public function declineRequest(RelationshipRequest $request);
}

@ -0,0 +1,8 @@
<?php
namespace Network;
use Model\Notification;
interface INotificationService extends \Model\Observer {
public function sendNotification(int $toUserId,Notification $notification);
}

@ -0,0 +1,60 @@
<?php
namespace Network;
use Model\Notification;
use Model\RelationshipRequest;
use Model\User;
use Repository\IUserRepository;
use Stub\RelationshipRequestRepository;
class RelationshipService implements IFriendRequestService
{
private RelationshipRequestRepository $relationshipRequestRepository;
private INotificationService $notificationService;
/**
* @param RelationshipRequestRepository $relationshipRequestRepository
*/
public function __construct(RelationshipRequestRepository $relationshipRequestRepository,INotificationService $notificationService)
{
$this->relationshipRequestRepository = $relationshipRequestRepository;
$this->notificationService = $notificationService;
}
public function sendRequest(User $fromUser, User $toUser): bool
{
try {
$friendRequest = new RelationshipRequest(random_int(1,150), $fromUser->getId(), $toUser->getId());
} catch (\Exception $e) {
return false;
}
$friendRequest->attachObserver($this->notificationService);
$friendRequest->updateStatus( 'pending');
$this->relationshipRequestRepository->addItem($friendRequest);
$toUser->getRole()->addUsersRequests($friendRequest);
return true;
}
public function acceptRequest(RelationshipRequest $request): bool
{
// Mark the request as accepted
$request->updateStatus('accepted');
$request->detachObserver($this->notificationService);
$this->relationshipRequestRepository->deleteItem($request);
return true;
}
public function declineRequest(RelationshipRequest $request): bool
{
$request->updateStatus('declined') ;
$request->detachObserver($this->notificationService);
$this->relationshipRequestRepository->deleteItem($request);
return true;
}
}

@ -0,0 +1,8 @@
<?php
namespace Model;
abstract class Coach extends Role
{
}

@ -0,0 +1,22 @@
<?php
namespace Model;
class CoachAthlete extends Coach {
/**
* @param User $user
* @return bool
*/
public function CheckAdd(User $user): bool
{
var_dump($user->getRole());
if($user->getRole() instanceof \Model\Athlete){
echo "Yo 5 david";
return true;
}
return false;
}
}
?>

@ -0,0 +1,72 @@
<?php
namespace Model;
class Notification
{
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* @param string $message
*/
public function setMessage(string $message): void
{
$this->message = $message;
}
private string $type;
private string $message;
private int $toUserId;
/**
* @return int
*/
public function getToUserId(): int
{
return $this->toUserId;
}
/**
* @param int $toUserId
*/
public function setToUserId(int $toUserId): void
{
$this->toUserId = $toUserId;
}
/**
* @param string $type
* @param string $message
*/
public function __construct(int $toUserId,string $type, string $message)
{
$this->type = $type;
$this->toUserId =$toUserId;
$this->message = $message;
}
public function __toString(): string
{
return var_export($this, true);
}
}

@ -0,0 +1,24 @@
<?php
namespace Model;
abstract class Observable {
private array $observers = array();
public function attachObserver(Observer $observer) {
$this->observers[] = $observer;
}
public function detachObserver(Observer $observer) {
$key = array_search($observer, $this->observers);
if ($key !== false) {
unset($this->observers[$key]);
}
}
public function notifyObservers() {
foreach ($this->observers as $observer) {
$observer->update($this);
}
}
}

@ -0,0 +1,8 @@
<?php
namespace Model;
interface Observer
{
public function update(Observable $observable);
}

@ -0,0 +1,99 @@
<?php
namespace Model;
class RelationshipRequest extends Observable
{
private int $id;
private int $fromUser;
private int $toUser;
private string $status = ''; // 'pending', 'accepted', 'declined'
private array $observers = [];
// TODO maybe need to change do User or Tiny User or User DTO
public function __construct(int $id, int $fromUser, int $toUser) {
$this->id = $id;
$this->fromUser = $fromUser;
$this->toUser = $toUser;
}
public function updateStatus(string $newStatus): void {
if (in_array($newStatus, ['pending', 'accepted', 'declined'])) {
$this->status = $newStatus;
$this->notifyObservers();
} else {
throw new \InvalidArgumentException("Invalid status: $newStatus");
}
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return int
*/
public function getFromUser(): int
{
return $this->fromUser;
}
/**
* @param int $fromUser
*/
public function setFromUser(int $fromUser): void
{
$this->fromUser = $fromUser;
}
/**
* @return int
*/
public function getToUser(): int
{
return $this->toUser;
}
/**
* @param int $toUser
*/
public function setToUser(int $toUser): void
{
$this->toUser = $toUser;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
public function __toString(): string
{
return sprintf(
"RelationshipRequest: ID: %d, FromUser: %d, ToUser: %d, Status: %s",
$this->id,
$this->fromUser,
$this->toUser,
$this->status
);
}
}

@ -0,0 +1,49 @@
<?php
namespace Model;
class Training
{
private int $idTraining;
private \DateTime $date;
private float $latitude;
private float $longitude;
private ?String $description;
private ?String $feedback;
public function __construct(
int $idTraining,
\DateTime $date,
float $latitude,
float $longitude,
?String $description = null,
?String $feedback = null
) {
$this->idTraining = $idTraining;
$this->date = $date;
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->description = $description;
$this->feedback = $feedback;
}
public function getId():int {
return $this->idTraining;
}
public function getDate():\DateTime {
return $this->date;
}
public function getLocation(): String {
return $this->longitude . $this->latitude;
}
public function getDescription(): String
{
return $this->description;
}
public function getFeedback(): String {
return $this->feedback;
}
public function __toString(): String {
return $this->idTraining . " - " . $this->description;
}
}

@ -0,0 +1,89 @@
<?php
namespace Manager;
use Model\Coach;
use Model\Training;
use Network\IAuthService;
class CoachManager
{
private IAuthService $authService;
private DataManager $dataManager;
public function __construct(DataManager $dataManager,IAuthService $authService)
{
$this->authService = $authService;
$this->dataManager = $dataManager;
}
public function getUsersList(): ?array
{
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole()->getUsersList()) {
return $this->authService->getCurrentUser()->getRole()->getUsersList();
}
return null;
}
public function getTrainingsList(): ?array {
return $this->dataManager->trainingRepository->getItems(0,10);
}
public function addUser(string $username): bool
{
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole()) {
$useToAdd = $this->dataManager->userRepository->getItemByName($username, 0, 1);
if($useToAdd) { // count 1 seul et debuis 0 (debut)
if ($this->authService->getCurrentUser()->getRole()->addUser($useToAdd)) {
return true;
}
}
}
return false;
}
public function removeUser(String $username): bool
{
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole()) {
if(($user = $this->dataManager->userRepository->getItemByName($username, 0, 1))) { // count 1 seul et debuis 0 (debut)
if ($this->authService->getCurrentUser()->getRole()->removeUser($user)) {
return true;
}
}
}
return false;
}
public function addTraining(Training $training): bool
{
if ($this->authService->getCurrentUser() && $this->authService->getCurrentUser()->getRole() instanceof Coach) {
if ($this->authService->getCurrentUser()->getRole()->addTraining($training)) {
$this->dataManager->trainingRepository->addItem($training);
return true;
}
}
return false;
}
public function removeTraining(String $trainingId): bool
{
$index = array_search($trainingId, $this->authService->getCurrentUser()->getRole()->getTrainingsList());
if ($index !== false) {
unset($this->authService->getCurrentUser()->getRole()->getTrainingsList()[$index]);
return true;
}
return false;
}
/* public function getStatistics(User $user) : ?Statistic {
if ($this->authService->currentUser && $this->authService->currentUser->getRole()) {
if (($arrayStat = $this->authService->currentUser->getRole()->getUserList($user)->getStatistic())) {
return $arrayStat;
}
}
return null;
}
public function getAnalyse(User $user): bool {
return false;
}*/
}

@ -0,0 +1,7 @@
<?php
namespace Repository;
interface INotificationRepository extends IGenericRepository
{
}

@ -0,0 +1,8 @@
<?php
namespace Repository;
interface IRelationshipRequestRepository extends IGenericRepository
{
}

@ -0,0 +1,85 @@
<?php
namespace Stub;
use Repository\INotificationRepository;
use Model\Notification;
class NotificationRepository implements INotificationRepository
{
private $notifications = []; // Array to store notifications
public function __construct()
{
// Initialize with some sample notifications for user IDs 1, 2, and 3
$this->notifications[] = new Notification(1, 'info', 'Welcome to our service!');
$this->notifications[] = new Notification(2, 'alert', 'Your subscription is about to expire.');
$this->notifications[] = new Notification(3, 'info', 'New features available.');
$this->notifications[] = new Notification(1, 'reminder', 'Dont forget your upcoming appointment.');
$this->notifications[] = new Notification(2, 'update', 'Service update completed.');
// Add more notifications as needed
}
public function getItemById(int $id)
{
// Assuming each notification has a unique ID
foreach ($this->notifications as $notification) {
if ($notification->getId() == $id) {
return $notification;
}
}
return null;
}
public function getNbItems(): int
{
return count($this->notifications);
}
public function getItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array
{
// For simplicity, returning a slice of the array
return array_slice($this->notifications, $index, $count);
}
public function getItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array
{
$filtered = array_filter($this->notifications, function($notification) use ($substring) {
return strpos($notification->getMessage(), $substring) !== false;
});
// For simplicity, just returning a slice without ordering
return array_slice($filtered, $index, $count);
}
public function getItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false)
{
$items = $this->getItemsByName($substring, $index, $count, $orderingPropertyName, $descending);
return $items ? $items[0] : null;
}
public function updateItem($oldItem, $newItem): void
{
// Find and update the item. This is a simplistic implementation.
foreach ($this->notifications as $key => $notification) {
if ($notification === $oldItem) {
$this->notifications[$key] = $newItem;
break;
}
}
}
public function addItem($item): void
{
$this->notifications[] = $item;
}
public function deleteItem($item): bool
{
foreach ($this->notifications as $key => $notification) {
if ($notification === $item) {
unset($this->notifications[$key]);
return true;
}
}
return false;
}
}

@ -0,0 +1,63 @@
<?php
namespace Stub;
use Model\RelationshipRequest;
use Repository\IRelationshipRequestRepository;
class RelationshipRequestRepository implements IRelationshipRequestRepository {
private array $requests = [];
public function __construct() {
// Example Relationship Requests
/* $this->requests[] = new RelationshipRequest(1, 1, 2); // Request from User 1 to User 2
$this->requests[] = new RelationshipRequest(2, 3, 4); // Request from User 3 to User 4*/
// ... more sample requests as needed
}
public function getItemById(int $id): ?RelationshipRequest {
foreach ($this->requests as $request) {
if ($request->id === $id) {
return $request;
}
}
return null;
}
public function getNbItems(): int {
return count($this->requests);
}
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->requests, $index, $count);
}
public function getItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
throw new \Exception('Search Not applicable on this entity');
}
public function getItemByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false) {
throw new \Exception('Search Not applicable on this entity');
}
public function updateItem($oldRequest, $newRequest): void {
$index = array_search($oldRequest, $this->requests);
if ($index !== false) {
$this->requests[$index] = $newRequest;
}
}
public function addItem($request): void {
$this->requests[] = $request;
}
public function deleteItem($request): bool {
$index = array_search($request, $this->requests);
if ($index !== false) {
unset($this->requests[$index]);
return true;
}
return false;
}
}

@ -0,0 +1,73 @@
<?php
namespace Stub;
use Model\Training;
use Repository\ITrainingRepository;
class TrainingRepository implements ITrainingRepository {
private array $trainings = [];
public function __construct() {
}
public function getItemById(int $id): ?Training {
foreach ($this->trainings as $training) {
if ($training->getId() === $id) {
return $training;
}
}
return null;
}
public function getNbItems(): int {
return count($this->trainings);
}
public function getItems(int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
// Implement the logic for ordering and slicing the array
return array_slice($this->trainings, $index, $count);
}
public function getItemsByDate(\DateTime $date, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
$filteredTrainings = array_filter($this->trainings, function ($training) use ($date) {
return $training->getDate() == $date;
});
// Implement sorting if necessary
return array_slice($filteredTrainings, $index, $count);
}
public function updateItem( $oldTraining, $newTraining): void {
$index = array_search($oldTraining, $this->trainings);
if ($index !== false) {
$this->trainings[$index] = $newTraining;
}
}
public function addItem( $training): void {
$this->trainings[] = $training;
}
public function deleteItem( $training): bool {
$index = array_search($training, $this->trainings);
if ($index !== false) {
unset($this->trainings[$index]);
return true;
}
return false;
}
public function getItemsByName(string $substring, int $index, int $count, ?string $orderingPropertyName = null, bool $descending = false): array {
$filteredTrainings = array_filter($this->trainings, function ($training) use ($substring) {
// Assuming the 'description' field is the one to be searched
return str_contains(strtolower($training->getDescription()), strtolower($substring));
});
// Implement sorting if necessary
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 $filteredTrainings[0] ?? null;
}
}

@ -0,0 +1,61 @@
<?php
namespace Stub;
use Model\Notification;
use Model\Observable;
use Model\Observer;
use Model\RelationshipRequest;
use Network\INotificationService;
use Repository\INotificationRepository;
use Repository\IUserRepository;
class NotificationService implements INotificationService
{
private INotificationRepository $repository;
private IUserRepository $userRepository;
public function __construct(INotificationRepository $repository,IUserRepository $userRepository)
{
$this->repository = $repository;
$this->userRepository = $userRepository;
}
public function sendNotification($toUserId, $notification)
{
$this->repository->addItem($notification);
$this->userRepository->getItemById($toUserId)->addNotification($notification);
}
public function update(Observable $observable)
{
echo "======================";
echo "======================";
var_dump("999999999999999");
if ($observable instanceof RelationshipRequest) {
$request = $observable;
switch ($request->getStatus()) {
case 'pending':
$msg = "You have a new friend request from user " . $request->getFromUser();
$notification = new Notification($request->getToUser(),"social", $msg);
$this->sendNotification($request->getToUser(), $notification);
break;
case 'accepted':
$msg = "User " . $request->getToUser() . " has accepted your request.";
$notification = new Notification($request->getFromUser(),"social", $msg);
$this->sendNotification($request->getFromUser(), $notification);
break;
case 'declined':
$msg = "User " . $request->getToUser() . " has declined your request.";
$notification = new Notification($request->getFromUser(),"social", $msg);
$this->sendNotification($request->getFromUser(), $notification);
break;
}
}
}
}
Loading…
Cancel
Save