diff --git a/Documents/Diagram/Analyse/Besoins/DiagrammeCasUtilisationFitWeb.drawio b/Documents/Diagram/Analyse/Besoins/DiagrammeCasUtilisationFitWeb.drawio new file mode 100755 index 00000000..8704a129 --- /dev/null +++ b/Documents/Diagram/Analyse/Besoins/DiagrammeCasUtilisationFitWeb.drawio @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Documents/Diagram/Analyse/Sequence/AjouterAmis.png b/Documents/Diagram/Analyse/Sequence/AjouterAmis.png new file mode 100644 index 00000000..1d66820f Binary files /dev/null and b/Documents/Diagram/Analyse/Sequence/AjouterAmis.png differ diff --git a/Documents/Diagramme/DiagrammeDeClasses/README_accesDonnees.md b/Documents/Diagramme/DiagrammeDeClasses/README_accesDonnees.md new file mode 100644 index 00000000..5ec32a60 --- /dev/null +++ b/Documents/Diagramme/DiagrammeDeClasses/README_accesDonnees.md @@ -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() +} +``` diff --git a/Sources/public/fitFiles/biking.fit b/Sources/public/fitFiles/biking.fit new file mode 100644 index 00000000..f1dd4fe1 Binary files /dev/null and b/Sources/public/fitFiles/biking.fit differ diff --git a/Sources/public/fitFiles/cycling.fit b/Sources/public/fitFiles/cycling.fit new file mode 100644 index 00000000..f63df29a Binary files /dev/null and b/Sources/public/fitFiles/cycling.fit differ diff --git a/Sources/public/fitFiles/power.fit b/Sources/public/fitFiles/power.fit new file mode 100644 index 00000000..7ebd96a1 Binary files /dev/null and b/Sources/public/fitFiles/power.fit differ diff --git a/Sources/public/fitFiles/swim.fit b/Sources/public/fitFiles/swim.fit new file mode 100644 index 00000000..6ba7f561 Binary files /dev/null and b/Sources/public/fitFiles/swim.fit differ diff --git a/Sources/src/console/Model.php b/Sources/src/console/Model.php new file mode 100644 index 00000000..0e4e6de8 --- /dev/null +++ b/Sources/src/console/Model.php @@ -0,0 +1,32 @@ +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); + } +} \ No newline at end of file diff --git a/Sources/src/data/core/network/IFriendRequestService.php b/Sources/src/data/core/network/IFriendRequestService.php new file mode 100644 index 00000000..b750efcd --- /dev/null +++ b/Sources/src/data/core/network/IFriendRequestService.php @@ -0,0 +1,13 @@ +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; + } +} \ No newline at end of file diff --git a/Sources/src/data/model/Coach.php b/Sources/src/data/model/Coach.php new file mode 100644 index 00000000..1c15134b --- /dev/null +++ b/Sources/src/data/model/Coach.php @@ -0,0 +1,8 @@ +getRole()); + if($user->getRole() instanceof \Model\Athlete){ + echo "Yo 5 david"; + return true; + } + return false; + } + + +} + +?> \ No newline at end of file diff --git a/Sources/src/data/model/Notification.php b/Sources/src/data/model/Notification.php new file mode 100644 index 00000000..7472632a --- /dev/null +++ b/Sources/src/data/model/Notification.php @@ -0,0 +1,72 @@ +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); + } +} \ No newline at end of file diff --git a/Sources/src/data/model/Observable.php b/Sources/src/data/model/Observable.php new file mode 100644 index 00000000..a3aa3d0e --- /dev/null +++ b/Sources/src/data/model/Observable.php @@ -0,0 +1,24 @@ +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); + } + } +} \ No newline at end of file diff --git a/Sources/src/data/model/Observer.php b/Sources/src/data/model/Observer.php new file mode 100644 index 00000000..ca7c152d --- /dev/null +++ b/Sources/src/data/model/Observer.php @@ -0,0 +1,8 @@ +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 + ); + } + +} \ No newline at end of file diff --git a/Sources/src/data/model/Training.php b/Sources/src/data/model/Training.php new file mode 100644 index 00000000..98291d77 --- /dev/null +++ b/Sources/src/data/model/Training.php @@ -0,0 +1,49 @@ +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; + } +} \ No newline at end of file diff --git a/Sources/src/data/model/manager/CoachManager.php b/Sources/src/data/model/manager/CoachManager.php new file mode 100644 index 00000000..eebd2827 --- /dev/null +++ b/Sources/src/data/model/manager/CoachManager.php @@ -0,0 +1,89 @@ +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; + }*/ + +} \ No newline at end of file diff --git a/Sources/src/data/model/repository/INotificationRepository.php b/Sources/src/data/model/repository/INotificationRepository.php new file mode 100644 index 00000000..c81ef1b2 --- /dev/null +++ b/Sources/src/data/model/repository/INotificationRepository.php @@ -0,0 +1,7 @@ +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', 'Don’t 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; + } +} diff --git a/Sources/src/data/stub/repository/RelationshipRequestRepository.php b/Sources/src/data/stub/repository/RelationshipRequestRepository.php new file mode 100644 index 00000000..56420592 --- /dev/null +++ b/Sources/src/data/stub/repository/RelationshipRequestRepository.php @@ -0,0 +1,63 @@ +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; + } +} \ No newline at end of file diff --git a/Sources/src/data/stub/repository/TrainingRepository.php b/Sources/src/data/stub/repository/TrainingRepository.php new file mode 100644 index 00000000..f43c5cb4 --- /dev/null +++ b/Sources/src/data/stub/repository/TrainingRepository.php @@ -0,0 +1,73 @@ +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; + } +} diff --git a/Sources/src/data/stub/service/NotificationService.php b/Sources/src/data/stub/service/NotificationService.php new file mode 100644 index 00000000..084f2908 --- /dev/null +++ b/Sources/src/data/stub/service/NotificationService.php @@ -0,0 +1,61 @@ +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; + } + } + } + + +} +