From b72981b103036ba0dd508840866434e7b02a9ac6 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Wed, 10 Apr 2024 18:42:03 +0000 Subject: [PATCH] add registry and registry manager to services accepted from version 4 --- hesabixCore/config/services.yaml | 7 +- .../src/Controller/AdminController.php | 20 ++- hesabixCore/src/Entity/Registry.php | 65 ++++++++ hesabixCore/src/Entity/Settings.php | 15 ++ .../src/Repository/RegistryRepository.php | 48 ++++++ hesabixCore/src/Service/SMS.php | 52 +++++-- hesabixCore/src/Service/registryMGR.php | 48 ++++++ hesabixCore/templates/app/base.html.twig | 4 +- hesabixCore/templates/base-new.html.twig | 14 +- hesabixCore/templates/base.html.twig | 26 ++-- hesabixCore/templates/blank.html.twig | 4 +- hesabixCore/templates/blog/list.html.twig | 2 +- .../TwigBundle/Exception/error404.html.twig | 4 +- hesabixCore/templates/general/about.html.twig | 4 +- .../templates/general/contact.html.twig | 10 +- hesabixCore/templates/general/faq.html.twig | 28 ++-- .../general/features/buy_sell.html.twig | 4 +- .../general/features/setup.html.twig | 6 +- .../general/features/user_managment.html.twig | 2 +- hesabixCore/templates/general/guide.html.twig | 2 +- hesabixCore/templates/general/home.html.twig | 142 ++---------------- .../templates/general/privacy.html.twig | 42 +++--- .../templates/general/sitemap.html.twig | 48 +++--- .../templates/general/sponsors.html.twig | 8 +- hesabixCore/templates/general/terms.html.twig | 62 ++++---- .../templates/general/woocommerce.html.twig | 14 +- .../templates/shortlinks/sell.html.twig | 8 +- hesabixCore/templates/store/base.html.twig | 4 +- hesabixCore/templates/test-pdf.html.twig | 2 +- .../user/confirmation_email.html.twig | 4 +- .../user/email/confrim-register.html.twig | 4 +- .../user/email/reset-password.html.twig | 4 +- hesabixCore/templates/user/login.html.twig | 4 +- hesabixCore/templates/user/register.html.twig | 4 +- 34 files changed, 409 insertions(+), 306 deletions(-) create mode 100644 hesabixCore/src/Entity/Registry.php create mode 100644 hesabixCore/src/Repository/RegistryRepository.php create mode 100644 hesabixCore/src/Service/registryMGR.php diff --git a/hesabixCore/config/services.yaml b/hesabixCore/config/services.yaml index 48b778a..5e830b2 100644 --- a/hesabixCore/config/services.yaml +++ b/hesabixCore/config/services.yaml @@ -42,6 +42,7 @@ services: twigFunctions: class: App\Service\twigFunctions arguments: [ "@doctrine.orm.entity_manager" ] - Access: - class: App\Service\Access - arguments: [ "@doctrine.orm.entity_manager","@Symfony.Component.Security.Core.Authentication.Token.Storage.TokenStorageInterface","@Symfony.Component.HttpFoundation.RequestStack" ] \ No newline at end of file + + registryMGR: + class: App\Service\registryMGR + arguments: [ "@doctrine.orm.entity_manager"] \ No newline at end of file diff --git a/hesabixCore/src/Controller/AdminController.php b/hesabixCore/src/Controller/AdminController.php index 6e257ef..cfec9ca 100644 --- a/hesabixCore/src/Controller/AdminController.php +++ b/hesabixCore/src/Controller/AdminController.php @@ -8,6 +8,7 @@ use App\Entity\ChangeReport; use App\Entity\Commodity; use App\Entity\HesabdariDoc; use App\Entity\Person; +use App\Entity\Registry; use App\Entity\Settings; use App\Entity\StoreroomTicket; use App\Entity\User; @@ -15,6 +16,7 @@ use App\Entity\WalletTransaction; use App\Service\Jdate; use App\Service\Notification; use App\Service\Provider; +use App\Service\registryMGR; use App\Service\SMS; use Doctrine\ORM\EntityManagerInterface; use Exception; @@ -192,6 +194,22 @@ class AdminController extends AbstractController throw $this->createNotFoundException(); } + #[Route('/api/admin/sms/plan/info', name: 'admin_sms_plan_info')] + public function admin_sms_plan_info(registryMGR $registryMGR,Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response + { + + $resp = []; + $resp['walletpay'] = $registryMGR->get('sms','walletPay'); + $resp['changePassword'] = $registryMGR->get('sms','changePassword'); + $resp['f2a'] = $registryMGR->get('sms','f2a'); + $resp['ticketReplay'] = $registryMGR->get('sms','ticketReplay'); + $resp['ticketRec'] = $registryMGR->get('sms','ticketRec'); + $resp['fromNum'] = $registryMGR->get('sms','fromNum'); + $resp['sharefaktor'] = $registryMGR->get('sms','sharefaktor'); + $resp['plan'] = $registryMGR->get('sms','plan'); + return $this->json($resp); + } + #[Route('/api/admin/settings/system/info', name: 'admin_settings_system_info')] public function admin_settings_system_info(Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response { @@ -209,7 +227,7 @@ class AdminController extends AbstractController #[Route('/api/admin/settings/system/info/save', name: 'admin_settings_system_info_save')] - public function admin_settings_system_info_save(EntityManagerInterface $entityManager,Request $request): Response + public function admin_settings_system_info_save(Registry $registry, EntityManagerInterface $entityManager,Request $request): Response { $params = []; if ($content = $request->getContent()) { diff --git a/hesabixCore/src/Entity/Registry.php b/hesabixCore/src/Entity/Registry.php new file mode 100644 index 0000000..7d8db42 --- /dev/null +++ b/hesabixCore/src/Entity/Registry.php @@ -0,0 +1,65 @@ +id; + } + + public function getRoot(): ?string + { + return $this->root; + } + + public function setRoot(?string $root): static + { + $this->root = $root; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getValueOfKey(): ?string + { + return $this->valueOfKey; + } + + public function setValueOfKey(string $valueOfKey): static + { + $this->valueOfKey = $valueOfKey; + + return $this; + } +} diff --git a/hesabixCore/src/Entity/Settings.php b/hesabixCore/src/Entity/Settings.php index e5e9e9f..98993f7 100644 --- a/hesabixCore/src/Entity/Settings.php +++ b/hesabixCore/src/Entity/Settings.php @@ -50,6 +50,9 @@ class Settings #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $footer = null; + #[ORM\Column(length: 50, nullable: true)] + private ?string $activeSmsPanel = null; + public function getId(): ?int { return $this->id; @@ -198,4 +201,16 @@ class Settings return $this; } + + public function getActiveSmsPanel(): ?string + { + return $this->activeSmsPanel; + } + + public function setActiveSmsPanel(?string $activeSmsPanel): static + { + $this->activeSmsPanel = $activeSmsPanel; + + return $this; + } } diff --git a/hesabixCore/src/Repository/RegistryRepository.php b/hesabixCore/src/Repository/RegistryRepository.php new file mode 100644 index 0000000..0d0eb6e --- /dev/null +++ b/hesabixCore/src/Repository/RegistryRepository.php @@ -0,0 +1,48 @@ + + * + * @method Registry|null find($id, $lockMode = null, $lockVersion = null) + * @method Registry|null findOneBy(array $criteria, array $orderBy = null) + * @method Registry[] findAll() + * @method Registry[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class RegistryRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Registry::class); + } + +// /** +// * @return Registry[] Returns an array of Registry objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('r.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Registry +// { +// return $this->createQueryBuilder('r') +// ->andWhere('r.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/src/Service/SMS.php b/hesabixCore/src/Service/SMS.php index 91e21fb..b2a2540 100644 --- a/hesabixCore/src/Service/SMS.php +++ b/hesabixCore/src/Service/SMS.php @@ -1,6 +1,7 @@ settings->getPayamakUsername(); - $password = $this->settings->getPayamakPassword(); - $api = new MelipayamakApi($username,$password); - $sms = $api->sms('soap'); - $response = $sms->sendByBaseNumber($params,$to,$bodyID); - $json = json_decode($response); - echo $json->Value; //RecId or Error Number - }catch(\Exception $e){ - //echo $e->getMessage(); + $settings = $this->entityManager->getRepository(Settings::class)->findAll()[0]; + if($settings->getActiveSmsPanel() == 'melipayamak'){ + try{ + $username = $this->settings->getPayamakUsername(); + $password = $this->settings->getPayamakPassword(); + $api = new MelipayamakApi($username,$password); + $sms = $api->sms('soap'); + $response = $sms->sendByBaseNumber($params,$to,$bodyID); + $json = json_decode($response); + echo $json->Value; //RecId or Error Number + }catch(\Exception $e){ + //echo $e->getMessage(); + } + } + elseif($settings->getActiveSmsPanel() == 'idePayam'){ + ini_set("soap.wsdl_cache_enabled", "0"); + $patternID = $this->entityManager->getRepository(Registry::class)->findOneBy([ + 'root'=>'sms', + 'name'=>$bodyID + ]); + $fromNum = $this->entityManager->getRepository(Registry::class)->findOneBy([ + 'root'=>'sms', + 'name'=>'fromNum' + ]); + //create next + $pt = []; + foreach($params as $param){ + $pt['{' + array_search($param,$params) + '}'] = $param; + } + $soap = new \SoapClient("http://185.112.33.61/wbs/send.php?wsdl"); + $soap->token = $this->settings->getMelipayamakToken(); + $soap->fromNum = $fromNum->getValueOfKey(); + $soap->toNum = array($to); + $soap->patternID = $patternID->getValueOfKey(); + $soap->Content = json_encode($pt,JSON_UNESCAPED_UNICODE); + $soap->Type = 0; + $array = $soap->SendSMSByPattern($soap->fromNum, $soap->toNum, $soap->Content, $soap->patternID, $soap->Type, $soap->token); + + } + + } public function sendByBalance(array $params,$bodyID,$to,Business $business,User $user,$balance = 500): int diff --git a/hesabixCore/src/Service/registryMGR.php b/hesabixCore/src/Service/registryMGR.php new file mode 100644 index 0000000..43bc59a --- /dev/null +++ b/hesabixCore/src/Service/registryMGR.php @@ -0,0 +1,48 @@ +em = $entityManager; + } + public function update(string $root,string $key ,string $v): bool + { + $item = $this->em->getRepository(Registry::class)->findOneBy([ + 'root'=>$root, + 'name'=>$key + ]); + if(! $item){ + $item = new Registry(); + } + $item->setRoot($root); + $item->setName($key); + $item->setValueOfKey($v); + $this->em->persist($item); + $this->em->flush(); + return true; + } + + public function get(string $root,string $key){ + $item = $this->em->getRepository(Registry::class)->findOneBy([ + 'root'=>$root, + 'name'=>$key + ]); + if(! $item){ + $item = new Registry(); + $item->setRoot($root); + $item->setName($key); + $item->setValueOfKey(''); + $this->em->persist($item); + $this->em->flush(); + } + return $item->getValueOfKey(); + } +} \ No newline at end of file diff --git a/hesabixCore/templates/app/base.html.twig b/hesabixCore/templates/app/base.html.twig index a1bfae2..d35a3d5 100644 --- a/hesabixCore/templates/app/base.html.twig +++ b/hesabixCore/templates/app/base.html.twig @@ -4,7 +4,7 @@ - + {% block title %}{% endblock %} @@ -51,7 +51,7 @@ - (مدیریت) حسابیکس + (مدیریت) حسابکس diff --git a/hesabixCore/templates/base-new.html.twig b/hesabixCore/templates/base-new.html.twig index 31d090c..bd406a1 100644 --- a/hesabixCore/templates/base-new.html.twig +++ b/hesabixCore/templates/base-new.html.twig @@ -4,10 +4,10 @@ - + - حسابیکس - {% block title %}{% endblock %} + حسابکس - {% block title %}{% endblock %} {# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #} {% block stylesheets %} {{ encore_entry_link_tags('app') }} @@ -40,15 +40,15 @@