From 96b9ad4baae4b4c77fba1d8cf6ea9c7afb64f38e Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Sat, 20 Jan 2024 16:33:27 +0000 Subject: [PATCH] add notification response for ticket replay and bug fix in send sms to admins for replay tickets.now each user has role_admin resicive sms message. --- .../src/Controller/NotificationsController.php | 13 +++++++++++-- hesabixCore/src/Controller/SupportController.php | 13 +++++++++++-- hesabixCore/src/Entity/Notification.php | 2 +- hesabixCore/src/Repository/UserRepository.php | 14 ++++++++++++++ hesabixCore/src/Service/Notification.php | 2 +- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/hesabixCore/src/Controller/NotificationsController.php b/hesabixCore/src/Controller/NotificationsController.php index 3f1ddc1..7a06580 100644 --- a/hesabixCore/src/Controller/NotificationsController.php +++ b/hesabixCore/src/Controller/NotificationsController.php @@ -32,14 +32,23 @@ class NotificationsController extends AbstractController $items = $entityManager->getRepository(\App\Entity\Notification::class)->findBy([ 'bid'=>$business, 'user'=>$this->getUser() - ]); + ],['id'=>'DESC']); + $userItems = $entityManager->getRepository(\App\Entity\Notification::class)->findBy([ + 'user'=>$this->getUser() + ],['id'=>'DESC']); + $items = array_merge($items,$userItems); } elseif ($type = 'new'){ $items = $entityManager->getRepository(\App\Entity\Notification::class)->findBy([ 'bid'=>$business, 'user'=>$this->getUser(), 'viewed' => false - ]); + ],['id'=>'DESC']); + $userItems = $entityManager->getRepository(\App\Entity\Notification::class)->findBy([ + 'user'=>$this->getUser(), + 'viewed' => false + ],['id'=>'DESC']); + $items = array_merge($items,$userItems); } $temps = []; diff --git a/hesabixCore/src/Controller/SupportController.php b/hesabixCore/src/Controller/SupportController.php index 6718700..8ad5972 100644 --- a/hesabixCore/src/Controller/SupportController.php +++ b/hesabixCore/src/Controller/SupportController.php @@ -2,8 +2,11 @@ namespace App\Controller; +use App\Entity\Settings; use App\Entity\Support; +use App\Entity\User; use App\Service\Jdate; +use App\Service\Notification; use App\Service\Provider; use App\Service\SMS; use Doctrine\ORM\EntityManagerInterface; @@ -46,7 +49,7 @@ class SupportController extends AbstractController ]); } #[Route('/api/admin/support/mod/{id}', name: 'app_admin_support_mod')] - public function app_admin_support_mod(SMS $SMS,Request $request, EntityManagerInterface $entityManager,string $id = ''): JsonResponse + public function app_admin_support_mod(SMS $SMS,Request $request, EntityManagerInterface $entityManager,string $id = '',Notification $notifi): JsonResponse { $params = []; if ($content = $request->getContent()) { @@ -71,6 +74,10 @@ class SupportController extends AbstractController //send sms to customer if($item->getSubmitter()->getMobile()) $SMS->send([$item->getId()],'162251',$item->getSubmitter()->getMobile()); + //send notification to user + $settings = $entityManager->getRepository(Settings::class)->findAll()[0]; + $url = $settings->getAppSite() . '/profile/support-view/' . $item->getId(); + $notifi->insert("به درخواست پشتیبانی پاسخ داده شد",$url,null,$item->getSubmitter()); return $this->json([ 'error'=> 0, 'message'=> 'successful' @@ -141,7 +148,9 @@ class SupportController extends AbstractController $entityManager->persist($upper); $entityManager->flush(); //send sms to manager - $SMS->send([$item->getId()],'162214','09183282405'); + $admins = $entityManager->getRepository(User::class)->findByRole('ROLE_ADMIN'); + foreach($admins as $admin) + $SMS->send([$item->getId()],'162214',$admin->getMobile()); return $this->json([ 'error'=> 0, 'message'=> 'ok', diff --git a/hesabixCore/src/Entity/Notification.php b/hesabixCore/src/Entity/Notification.php index 9c045d9..d4a9254 100644 --- a/hesabixCore/src/Entity/Notification.php +++ b/hesabixCore/src/Entity/Notification.php @@ -19,7 +19,7 @@ class Notification private ?User $user = null; #[ORM\ManyToOne(inversedBy: 'notifications')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: true)] private ?Business $bid = null; #[ORM\Column(type: Types::TEXT, nullable: true)] diff --git a/hesabixCore/src/Repository/UserRepository.php b/hesabixCore/src/Repository/UserRepository.php index 9b60483..71d7e62 100644 --- a/hesabixCore/src/Repository/UserRepository.php +++ b/hesabixCore/src/Repository/UserRepository.php @@ -56,6 +56,20 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader $this->save($user, true); } + public function findByRole($role) + { + $qb = $this->createQueryBuilder('u'); + + $qb + ->andWhere($qb->expr()->like('u.roles', ':role')) + ->setParameter('role', '%'.$role.'%') + ->orderBy('u.email', 'DESC'); + + return $qb + ->getQuery() + ->getResult(); + } + // /** // * @return User[] Returns an array of User objects // */ diff --git a/hesabixCore/src/Service/Notification.php b/hesabixCore/src/Service/Notification.php index 2a6c826..aadb278 100644 --- a/hesabixCore/src/Service/Notification.php +++ b/hesabixCore/src/Service/Notification.php @@ -14,7 +14,7 @@ class Notification { $this->em = $entityManager; } - public function insert(string $message,string $url,Business $business,User $user): bool + public function insert(string $message,string $url,Business | null $business,User $user): bool { $item = new \App\Entity\Notification(); $item->setBid($business);