diff --git a/.idea/spt-crm-backend.iml b/.idea/spt-crm-backend.iml
index 624d9cb..dddca40 100644
--- a/.idea/spt-crm-backend.iml
+++ b/.idea/spt-crm-backend.iml
@@ -82,6 +82,8 @@
+
+
diff --git a/README.md b/README.md
index a7ed400..667c6ee 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,4 @@
# spt-crm-backend
+- password generation: bin/console security:hash-password
+- annotations to attributes: https://www.doctrine-project.org/2022/11/04/annotations-to-attributes.html
\ No newline at end of file
diff --git a/httpdocs/.gitignore b/httpdocs/.gitignore
index a67f91e..94c87d9 100644
--- a/httpdocs/.gitignore
+++ b/httpdocs/.gitignore
@@ -1,4 +1,4 @@
-
+/.idea
###> symfony/framework-bundle ###
/.env.local
/.env.local.php
diff --git a/httpdocs/composer.json b/httpdocs/composer.json
index 5d9aca5..99aa10a 100644
--- a/httpdocs/composer.json
+++ b/httpdocs/composer.json
@@ -12,10 +12,12 @@
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.15",
"dompdf/dompdf": "*",
+ "nelmio/cors-bundle": "^2.3",
"phpoffice/phpspreadsheet": "*",
"sensio/framework-extra-bundle": "*",
"symfony/console": "6.2.*",
"symfony/dotenv": "6.2.*",
+ "symfony/expression-language": "6.2.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.2.*",
"symfony/mailer": "6.2.*",
diff --git a/httpdocs/composer.lock b/httpdocs/composer.lock
index 47c3c6a..bb37e1d 100644
--- a/httpdocs/composer.lock
+++ b/httpdocs/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "15a7bf65293c8d623f82986b5c017838",
+ "content-hash": "6009e6bfd2cb0c417acb9969128399f7",
"packages": [
{
"name": "doctrine/annotations",
@@ -1896,6 +1896,68 @@
],
"time": "2022-08-04T09:53:51+00:00"
},
+ {
+ "name": "nelmio/cors-bundle",
+ "version": "2.3.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/nelmio/NelmioCorsBundle.git",
+ "reference": "185d2c0ae50a3f0b628790170164d5f1c5b7c281"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/185d2c0ae50a3f0b628790170164d5f1c5b7c281",
+ "reference": "185d2c0ae50a3f0b628790170164d5f1c5b7c281",
+ "shasum": ""
+ },
+ "require": {
+ "psr/log": "^1.0 || ^2.0 || ^3.0",
+ "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0"
+ },
+ "require-dev": {
+ "mockery/mockery": "^1.2",
+ "symfony/phpunit-bridge": "^4.4 || ^5.4 || ^6.0"
+ },
+ "type": "symfony-bundle",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Nelmio\\CorsBundle\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nelmio",
+ "homepage": "http://nelm.io"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://github.com/nelmio/NelmioCorsBundle/contributors"
+ }
+ ],
+ "description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application",
+ "keywords": [
+ "api",
+ "cors",
+ "crossdomain"
+ ],
+ "support": {
+ "issues": "https://github.com/nelmio/NelmioCorsBundle/issues",
+ "source": "https://github.com/nelmio/NelmioCorsBundle/tree/2.3.1"
+ },
+ "time": "2023-02-16T08:49:29+00:00"
+ },
{
"name": "phenx/php-font-lib",
"version": "0.5.4",
@@ -3559,6 +3621,69 @@
],
"time": "2023-03-01T10:32:47+00:00"
},
+ {
+ "name": "symfony/expression-language",
+ "version": "v6.2.7",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/expression-language.git",
+ "reference": "83e1fee4c018aa60bcbbecd585a2c54af6aca905"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/expression-language/zipball/83e1fee4c018aa60bcbbecd585a2c54af6aca905",
+ "reference": "83e1fee4c018aa60bcbbecd585a2c54af6aca905",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=8.1",
+ "symfony/cache": "^5.4|^6.0",
+ "symfony/service-contracts": "^1.1|^2|^3"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\ExpressionLanguage\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Provides an engine that can compile and evaluate expressions",
+ "homepage": "https://symfony.com",
+ "support": {
+ "source": "https://github.com/symfony/expression-language/tree/v6.2.7"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2023-02-16T09:57:23+00:00"
+ },
{
"name": "symfony/filesystem",
"version": "v6.2.10",
diff --git a/httpdocs/config/bundles.php b/httpdocs/config/bundles.php
index 49cc044..9d4ad19 100644
--- a/httpdocs/config/bundles.php
+++ b/httpdocs/config/bundles.php
@@ -7,4 +7,5 @@ return [
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
+ Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
];
diff --git a/httpdocs/config/packages/nelmio_cors.yaml b/httpdocs/config/packages/nelmio_cors.yaml
new file mode 100644
index 0000000..908aa12
--- /dev/null
+++ b/httpdocs/config/packages/nelmio_cors.yaml
@@ -0,0 +1,13 @@
+nelmio_cors:
+ defaults:
+ allow_credentials: true
+ origin_regex: true
+ allow_origin: [ '*' ]
+ allow_headers: [ '*' ]
+# allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
+ allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
+# allow_headers: ['Content-Type', 'Authorization']
+ expose_headers: ['Link']
+ max_age: 3600
+ paths:
+ '^/': null
diff --git a/httpdocs/config/packages/security.yaml b/httpdocs/config/packages/security.yaml
index f07ebaa..6210eb8 100644
--- a/httpdocs/config/packages/security.yaml
+++ b/httpdocs/config/packages/security.yaml
@@ -7,16 +7,19 @@ security:
users_in_memory: { memory: null }
app_entity_users:
entity:
- class: App\Entity\EntUser
+ class: App\Entity\User
+ property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
- provider: users_in_memory
+ #provider: app_entity_users
custom_authenticators:
- App\Security\JsonAuthenticator
+ logout:
+ path: security_logout
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
diff --git a/httpdocs/src/Command/CmdSendReminderEmails.php b/httpdocs/src/Command/CmdSendReminderEmails.php
index 815865a..a071829 100755
--- a/httpdocs/src/Command/CmdSendReminderEmails.php
+++ b/httpdocs/src/Command/CmdSendReminderEmails.php
@@ -2,12 +2,12 @@
namespace App\Command;
-use App\Entity\EntCustomer;
-use App\Entity\EntCustomerMeeting;
-use App\Entity\EntCustomerMeetingParticipant;
-use App\Entity\EntInternalMeeting;
-use App\Entity\EntInternalMeetingParticipant;
-use App\Entity\EntUser;
+use App\Entity\Customer;
+use App\Entity\CustomerMeeting;
+use App\Entity\CustomerMeetingParticipant;
+use App\Entity\InternalMeeting;
+use App\Entity\InternalMeetingParticipant;
+use App\Entity\User;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
@@ -60,8 +60,8 @@ class CmdSendReminderEmails extends Command
{
Utils::sendMail($this->mailer, 'test', 'd.knudsen@spawntree.de', 'this is a test', $this->environment);
- $usersById = Utils::getSortedObjectsById($this->em->getRepository(EntUser::class)->findAll());
- $customersById = Utils::getSortedObjectsById($this->em->getRepository(EntCustomer::class)->findAll());
+ $usersById = Utils::getSortedObjectsById($this->em->getRepository(User::class)->findAll());
+ $customersById = Utils::getSortedObjectsById($this->em->getRepository(Customer::class)->findAll());
$now = (new \DateTime())->format("Y-m-d H:i:s");
$checkStartDay = (new \DateTime())->modify('+2 day')->format("Y-m-d H:i:s");
@@ -137,22 +137,22 @@ class CmdSendReminderEmails extends Command
protected function sendCustomerReminder($meetings, $customersById, $usersById, $firstReminder)
{
- /** @var EntCustomerMeeting $meeting */
+ /** @var CustomerMeeting $meeting */
foreach ($meetings as $meeting) {
- /** @var EntUser $owner */
+ /** @var User $owner */
$owner = $usersById[$meeting->getOwnerUserId()];
- /** @var EntCustomer $customer */
+ /** @var Customer $customer */
$customer = $customersById[$meeting->getCustomerId()];
$participantsByUserId = Utils::getSortedObjects('getParticipantUserId',
- $this->em->getRepository('App:EntCustomerMeetingParticipant')->findBy(['customer_meeting_id' => $meeting->getId()]));
+ $this->em->getRepository(CustomerMeetingParticipant::class)->findBy(['customer_meeting_id' => $meeting->getId()]));
$subject = "Termin-Erinnerung: ". $customer->getName(). " ".$meeting->getStartDate()->format('d.m.Y H:i');
$body = $this->createCustomerMeetingReminderEmailBody($meeting, $subject, $customer, $owner, $participantsByUserId, $usersById);
Utils::sendMail($this->mailer, $subject, $owner->getEmail(), $body, $this->environment);
- /*** @var EntCustomerMeetingParticipant $participant */
+ /*** @var CustomerMeetingParticipant $participant */
foreach ($participantsByUserId as $userId => $participant) {
- /** @var EntUser $pUser */
+ /** @var User $pUser */
$pUser = $usersById[$participant->getParticipantUserId()];
Utils::sendMail($this->mailer, $subject, $pUser->getEmail(), $body, $this->environment);
}
@@ -165,20 +165,20 @@ class CmdSendReminderEmails extends Command
protected function sendInternalReminder($meetings, $usersById, $firstReminder)
{
- /** @var EntInternalMeeting $meeting */
+ /** @var InternalMeeting $meeting */
foreach ($meetings as $meeting) {
- /** @var EntUser $owner */
+ /** @var User $owner */
$owner = $usersById[$meeting->getOwnerUserId()];
$participantsByUserId = Utils::getSortedObjects('getParticipantUserId',
- $this->em->getRepository('App:EntInternalMeetingParticipant')->findBy(['internal_meeting_id' => $meeting->getId()]));
+ $this->em->getRepository(InternalMeetingParticipant::class)->findBy(['internal_meeting_id' => $meeting->getId()]));
$subject = "Termin-Erinnerung: PLP intern ".$meeting->getStartDate()->format('d.m.Y H:i');
$body = $this->createInternalMeetingReminderEmailBody($meeting, $subject, $owner, $participantsByUserId, $usersById);
Utils::sendMail($this->mailer, $subject, $owner->getEmail(), $body, $this->environment);
- /*** @var EntInternalMeetingParticipant $participant */
+ /*** @var InternalMeetingParticipant $participant */
foreach ($participantsByUserId as $userId => $participant) {
- /** @var EntUser $pUser */
+ /** @var User $pUser */
$pUser = $usersById[$participant->getParticipantUserId()];
Utils::sendMail($this->mailer, $subject, $pUser->getEmail(), $body, $this->environment);
}
@@ -189,7 +189,7 @@ class CmdSendReminderEmails extends Command
}
}
- protected function createCustomerMeetingReminderEmailBody(EntCustomerMeeting $meeting, $subject, EntCustomer $customer, EntUser $owner, $participantsByUserId, $usersById)
+ protected function createCustomerMeetingReminderEmailBody(CustomerMeeting $meeting, $subject, Customer $customer, User $owner, $participantsByUserId, $usersById)
{
$body = $subject." ";
$body.= "Kunde: ".$customer->getName()."";
@@ -217,14 +217,14 @@ class CmdSendReminderEmails extends Command
$body.= "Options-Termin: ".($meeting->getIsOptionMeeting() ? "ja" : "nein")."";
$body.= "Interne Teilnehmer: ";
foreach ($participantsByUserId as $pUserId => $item) {
- /** @var EntUser $participant */
+ /** @var User $participant */
$participant = $usersById[$pUserId];
$body.= $participant->getFirstname(). " ". $participant->getLastname(). "";
}
return $body;
}
- protected function createInternalMeetingReminderEmailBody(EntInternalMeeting $meeting, $subject, EntUser $owner, $participantsByUserId, $usersById)
+ protected function createInternalMeetingReminderEmailBody(InternalMeeting $meeting, $subject, User $owner, $participantsByUserId, $usersById)
{
$body = $subject." ";
$body.= "Betreff: ".$meeting->getTitle()."";
@@ -234,7 +234,7 @@ class CmdSendReminderEmails extends Command
$body.= "Bemerkung: ".$meeting->getDescription()."";
$body.= "Interne Teilnehmer: ";
foreach ($participantsByUserId as $pUserId => $item) {
- /** @var EntUser $participant */
+ /** @var User $participant */
$participant = $usersById[$pUserId];
$body.= $participant->getFirstname(). " ". $participant->getLastname(). "";
}
@@ -243,11 +243,11 @@ class CmdSendReminderEmails extends Command
protected function sendCustomerMeetingReportReminder($meetings, $customersById, $usersById)
{
- /** @var EntCustomerMeeting $meeting */
+ /** @var CustomerMeeting $meeting */
foreach ($meetings as $meeting) {
- /** @var EntUser $owner */
+ /** @var User $owner */
$owner = $usersById[$meeting->getOwnerUserId()];
- /** @var EntCustomer $customer */
+ /** @var Customer $customer */
$customer = $customersById[$meeting->getCustomerId()];
$subject = "Termin-Report-Erinnerung (Kundentermin) ". $customer->getName();
@@ -262,9 +262,9 @@ class CmdSendReminderEmails extends Command
protected function sendInternalMeetingReportReminder($meetings, $usersById)
{
- /** @var EntInternalMeeting $meeting */
+ /** @var InternalMeeting $meeting */
foreach ($meetings as $meeting) {
- /** @var EntUser $owner */
+ /** @var User $owner */
$owner = $usersById[$meeting->getOwnerUserId()];
$subject = "Termin-Report-Erinnerung (PLP intern)";
@@ -277,7 +277,7 @@ class CmdSendReminderEmails extends Command
}
}
- protected function createReportReminderEmailBody($meeting, $subject, EntUser $owner)
+ protected function createReportReminderEmailBody($meeting, $subject, User $owner)
{
$body = $subject." ";
$body.= "Für folgenden Termin wurde bisher noch kein Report angelegt.";
diff --git a/httpdocs/src/Controller/AdminController.php b/httpdocs/src/Controller/AdminController.php
index a2e08c5..4ff6f60 100644
--- a/httpdocs/src/Controller/AdminController.php
+++ b/httpdocs/src/Controller/AdminController.php
@@ -7,8 +7,9 @@
*/
namespace App\Controller;
-use App\Entity\EntCountry;
+use App\Entity\Country;
use App\Utils\Reply;
+use Doctrine\ORM\EntityManagerInterface;
use Dompdf\Dompdf;
use Dompdf\Options;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -22,17 +23,18 @@ class AdminController extends AbstractController
{
const XMAS_CONTACT_PDF_TYPE_CUSTOMER = 'customer';
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/create-xmas-pdf', name: 'create_xmas_pdf')]
public function createXmasPdf(Request $request)
{
$type = $request->request->get('type');
- $em = $this->getDoctrine()->getManager();
$entityCache = [];
switch ($type) {
case self::XMAS_CONTACT_PDF_TYPE_CUSTOMER:
$sql = "SELECT cc.*, c.name AS company FROM customer_contact cc, customer c WHERE cc.is_xmas_mail_recipient = 1 AND cc.customer_id = c.id ORDER BY cc.lastname ASC";
- $statement = $em->getConnection()->prepare($sql);
+ $statement = $this->em->getConnection()->prepare($sql);
$statement->execute();
$entries = $statement->fetchAll();
break;
@@ -45,8 +47,8 @@ class AdminController extends AbstractController
$cacheKey = trim($entry['firstname'].$entry['lastname'].$entry['street'].$entry['street_no'].$entry['zip'].$entry['city']);
if (!array_key_exists($cacheKey, $entityCache)) {
$entityCache[$cacheKey] = 1;
- /** @var EntCountry $entCountry */
- $entCountry = !is_null($entry['country_id']) ? EntCountry::getCountryById($em, $entry['country_id']) : null;
+ /** @var Country $entCountry */
+ $entCountry = !is_null($entry['country_id']) ? Country::getCountryById($this->em, $entry['country_id']) : null;
$data[] = [
'company' => $entry['company'],
'firstname' => $entry['firstname'],
diff --git a/httpdocs/src/Controller/CustomerEditController.php b/httpdocs/src/Controller/CustomerEditController.php
index bcd545f..f1e5d75 100644
--- a/httpdocs/src/Controller/CustomerEditController.php
+++ b/httpdocs/src/Controller/CustomerEditController.php
@@ -7,17 +7,18 @@
*/
namespace App\Controller;
-use App\Entity\EntCustomer;
-use App\Entity\EntCustomerContact;
-use App\Entity\EntCustomerMeeting;
-use App\Entity\EntCustomerMeetingParticipant;
-use App\Entity\EntCustomerNote;
-use App\Entity\EntMeetingType;
-use App\Entity\EntUser;
+use App\Entity\Customer;
+use App\Entity\CustomerContact;
+use App\Entity\CustomerMeeting;
+use App\Entity\CustomerMeetingParticipant;
+use App\Entity\CustomerNote;
+use App\Entity\MeetingType;
+use App\Entity\User;
use App\EntityVirtual\ServiceData;
use App\Utils\Message;
use App\Utils\Reply;
use App\Utils\Utils;
+use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -29,18 +30,19 @@ use Symfony\Component\Routing\Annotation\Route;
#[Security("is_granted('ROLE_ADMIN')")]
class CustomerEditController extends AbstractController
{
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/create-customer', name: 'create_customer')]
public function createCustomer(Request $request)
{
$customerClient = json_decode($request->request->get('customer'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomer $entCustomer */
- $entCustomer = new EntCustomer($em, $customerClient->name);
- $entCustomer->setClientData($em, $customerClient);
- $em->persist($entCustomer);
- $em->flush();
-
- $fullMappedCustomer = $entCustomer->clientMapper($em, true);
+ /** @var Customer $entCustomer */
+ $entCustomer = new Customer($this->em, $customerClient->name);
+ $entCustomer->setClientData($this->em, $customerClient);
+ $this->em->persist($entCustomer);
+ $this->em->flush();
+
+ $fullMappedCustomer = $entCustomer->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMERS, ServiceData::ACTION_ADD, $fullMappedCustomer);
return Reply::getResponse($fullMappedCustomer, Message::SUCCESS_CUSTOMER_CREATE, 0, $serviceData);
@@ -50,17 +52,16 @@ class CustomerEditController extends AbstractController
public function editCustomer(Request $request)
{
$customerClient = json_decode($request->request->get('customer'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($customerClient->id);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($customerClient->id);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $entCustomer->setClientData($em, $customerClient);
- $em->persist($entCustomer);
- $em->flush();
+ $entCustomer->setClientData($this->em, $customerClient);
+ $this->em->persist($entCustomer);
+ $this->em->flush();
- $fullMappedCustomer = $entCustomer->clientMapper($em, true);
+ $fullMappedCustomer = $entCustomer->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMERS, ServiceData::ACTION_EDIT, $fullMappedCustomer);
return Reply::getResponse($fullMappedCustomer, Message::SUCCESS_CUSTOMER_EDIT, 0, $serviceData);
@@ -70,158 +71,152 @@ class CustomerEditController extends AbstractController
public function createCustomerContact(Request $request)
{
$customerContactClient = json_decode($request->request->get('customerContact'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($customerContactClient->customer_id);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository('App:Customer')->find($customerContactClient->customer_id);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntCustomerContact $entCustomerContact */
- $entCustomerContact = new EntCustomerContact($em, $entCustomer, $customerContactClient->lastname);
- $entCustomerContact->setClientData($em, $customerContactClient);
- $em->persist($entCustomerContact);
- $em->flush();
+ /** @var CustomerContact $entCustomerContact */
+ $entCustomerContact = new CustomerContact($this->em, $entCustomer, $customerContactClient->lastname);
+ $entCustomerContact->setClientData($this->em, $customerContactClient);
+ $this->em->persist($entCustomerContact);
+ $this->em->flush();
- $fullMappedCustomerContact = $entCustomerContact->clientMapper($em, true);
+ $fullMappedCustomerContact = $entCustomerContact->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_CONTACTS, ServiceData::ACTION_ADD, $fullMappedCustomerContact);
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_CONTACT_CREATE, 0, $serviceData);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_CONTACT_CREATE, 0, $serviceData);
}
#[Route('/edit-customer-contact', name: 'edit_customer_contact')]
public function editCustomerContact(Request $request)
{
$customerContactClient = json_decode($request->request->get('customerContact'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomerContact $entCustomerContact */
- $entCustomerContact = $em->getRepository('App:EntCustomerContact')->find($customerContactClient->id);
+ /** @var CustomerContact $entCustomerContact */
+ $entCustomerContact = $this->em->getRepository(CustomerContact::class)->find($customerContactClient->id);
if (is_null($entCustomerContact)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($entCustomerContact->getCustomerId());
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerContact->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $entCustomerContact->setClientData($em, $customerContactClient);
- $em->persist($entCustomerContact);
- $em->flush();
+ $entCustomerContact->setClientData($this->em, $customerContactClient);
+ $this->em->persist($entCustomerContact);
+ $this->em->flush();
- $fullMappedCustomerContact = $entCustomerContact->clientMapper($em, true);
+ $fullMappedCustomerContact = $entCustomerContact->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_CONTACTS, ServiceData::ACTION_EDIT, $fullMappedCustomerContact);
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_CONTACT_EDIT, 0, $serviceData);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_CONTACT_EDIT, 0, $serviceData);
}
#[Route('/delete-customer-contact', name: 'delete_customer_contact')]
public function deleteCustomerContact(Request $request)
{
$customerContactIdClient = json_decode($request->request->get('customerContactId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomerContact $entCustomerContact */
- $entCustomerContact = $em->getRepository('App:EntCustomerContact')->find($customerContactIdClient);
+ /** @var CustomerContact $entCustomerContact */
+ $entCustomerContact = $this->em->getRepository(CustomerContact::class)->find($customerContactIdClient);
if (is_null($entCustomerContact)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($entCustomerContact->getCustomerId());
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerContact->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $fullMappedCustomerContact = $entCustomerContact->clientMapper($em, true);
- $em->remove($entCustomerContact);
- $em->flush();
+ $fullMappedCustomerContact = $entCustomerContact->clientMapper($this->em, true);
+ $this->em->remove($entCustomerContact);
+ $this->em->flush();
$sql = "UPDATE `customer_meeting` SET `customer_contact_id` = NULL WHERE `customer_contact_id` = ". $customerContactIdClient;
- $statement = $em->getConnection()->prepare($sql);
+ $statement = $this->em->getConnection()->prepare($sql);
$statement->execute();
$sql = "UPDATE `customer_note` SET `customer_contact_id` = NULL WHERE `customer_contact_id` = ". $customerContactIdClient;
- $statement = $em->getConnection()->prepare($sql);
+ $statement = $this->em->getConnection()->prepare($sql);
$statement->execute();
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_CONTACTS, ServiceData::ACTION_DELETE, $fullMappedCustomerContact);
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_CONTACT_DELETE, 0, $serviceData);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_CONTACT_DELETE, 0, $serviceData);
}
#[Route('/create-customer-note', name: 'create_customer_note')]
public function createCustomerNote(Request $request)
{
$customerNoteClient = json_decode($request->request->get('customerNote'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($customerNoteClient->customer_id);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($customerNoteClient->customer_id);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntCustomerNote $entCustomerNote */
- $entCustomerNote = new EntCustomerNote($em, $entCustomer, $user, $customerNoteClient->title);
- $entCustomerNote->setClientData($em, $customerNoteClient);
- $em->persist($entCustomerNote);
- $em->flush();
+ /** @var CustomerNote $entCustomerNote */
+ $entCustomerNote = new CustomerNote($this->em, $entCustomer, $user, $customerNoteClient->title);
+ $entCustomerNote->setClientData($this->em, $customerNoteClient);
+ $this->em->persist($entCustomerNote);
+ $this->em->flush();
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_NOTE_CREATE);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_NOTE_CREATE);
}
#[Route('/edit-customer-note', name: 'edit_customer_note')]
public function editCustomerNote(Request $request)
{
$customerNoteClient = json_decode($request->request->get('customerNote'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomerNote $entCustomerNote */
- $entCustomerNote = $em->getRepository(EntCustomerNote::class)->find($customerNoteClient->id);
+ /** @var CustomerNote $entCustomerNote */
+ $entCustomerNote = $this->em->getRepository(CustomerNote::class)->find($customerNoteClient->id);
$bHasRightsToEdit = $entCustomerNote->getCreationUserId() == $user->getId() || $user->isAdmin();
if (is_null($entCustomerNote) || !$bHasRightsToEdit) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository(EntCustomer::class)->find($entCustomerNote->getCustomerId());
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerNote->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $entCustomerNote->setClientData($em, $customerNoteClient);
- $em->persist($entCustomerNote);
- $em->flush();
+ $entCustomerNote->setClientData($this->em, $customerNoteClient);
+ $this->em->persist($entCustomerNote);
+ $this->em->flush();
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_NOTE_EDIT);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_NOTE_EDIT);
}
#[Route('/delete-customer-note', name: 'delete_customer_note')]
public function deleteCustomerNote(Request $request)
{
$customerNoteIdClient = json_decode($request->request->get('customerNoteId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomerNote $entCustomerNote */
- $entCustomerNote = $em->getRepository('App:EntCustomerNote')->find($customerNoteIdClient);
+ /** @var CustomerNote $entCustomerNote */
+ $entCustomerNote = $this->em->getRepository(CustomerNote::class)->find($customerNoteIdClient);
$bHasRightsToDelete = $entCustomerNote->getCreationUserId() == $user->getId() || $user->isAdmin();
if (is_null($entCustomerNote) || !$bHasRightsToDelete) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($entCustomerNote->getCustomerId());
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerNote->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $em->remove($entCustomerNote);
- $em->flush();
+ $this->em->remove($entCustomerNote);
+ $this->em->flush();
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_NOTE_DELETE);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_NOTE_DELETE);
}
}
\ No newline at end of file
diff --git a/httpdocs/src/Controller/CustomerMeetingEditController.php b/httpdocs/src/Controller/CustomerMeetingEditController.php
index 8ff207e..ae6a495 100644
--- a/httpdocs/src/Controller/CustomerMeetingEditController.php
+++ b/httpdocs/src/Controller/CustomerMeetingEditController.php
@@ -7,15 +7,16 @@
*/
namespace App\Controller;
-use App\Entity\EntCustomer;
-use App\Entity\EntCustomerMeeting;
-use App\Entity\EntCustomerMeetingParticipant;
-use App\Entity\EntMeetingType;
-use App\Entity\EntUser;
+use App\Entity\Customer;
+use App\Entity\CustomerMeeting;
+use App\Entity\CustomerMeetingParticipant;
+use App\Entity\MeetingType;
+use App\Entity\User;
use App\EntityVirtual\ServiceData;
use App\Utils\Message;
use App\Utils\Reply;
use App\Utils\Utils;
+use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -27,55 +28,56 @@ use Symfony\Component\Routing\Annotation\Route;
#[Security("is_granted('ROLE_ADMIN') and is_granted('ROLE_SALES')")]
class CustomerMeetingEditController extends AbstractController
{
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/create-customer-meeting', name: 'create_customer_meeting')]
public function createCustomerMeeting(Request $request)
{
$customerMeetingClient = json_decode($request->request->get('customerMeeting'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository(EntCustomer::class)->find($customerMeetingClient->customer_id);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($customerMeetingClient->customer_id);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntUser $entOwnerUser */
- $entOwnerUser = $em->getRepository(EntUser::class)->find($customerMeetingClient->owner_user_id);
+ /** @var User $entOwnerUser */
+ $entOwnerUser = $this->em->getRepository(User::class)->find($customerMeetingClient->owner_user_id);
if (is_null($entOwnerUser)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntMeetingType $entMeetingType */
- $entMeetingType = $em->getRepository(EntMeetingType::class)->find($customerMeetingClient->meeting_type_id);
+ /** @var MeetingType $entMeetingType */
+ $entMeetingType = $this->em->getRepository(MeetingType::class)->find($customerMeetingClient->meeting_type_id);
if (is_null($entMeetingType)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
// Database manipulation in transaction
- $dbCon = $this->getDoctrine()->getConnection();
+ $dbCon = $this->em->getConnection();
$dbCon->beginTransaction();
try {
- /** @var EntCustomerMeeting $entCustomerMeeting */
- $entCustomerMeeting = new EntCustomerMeeting($em, $entCustomer, $user, $entOwnerUser, $entMeetingType, $customerMeetingClient->is_option_meeting,
+ /** @var CustomerMeeting $entCustomerMeeting */
+ $entCustomerMeeting = new CustomerMeeting($this->em, $entCustomer, $user, $entOwnerUser, $entMeetingType, $customerMeetingClient->is_option_meeting,
$customerMeetingClient->title, $customerMeetingClient->start_date, $customerMeetingClient->end_date);
- $entCustomerMeeting->setClientData($em, $customerMeetingClient);
- $em->persist($entCustomerMeeting);
- $em->flush();
+ $entCustomerMeeting->setClientData($this->em, $customerMeetingClient);
+ $this->em->persist($entCustomerMeeting);
+ $this->em->flush();
$cntParticipants = count($customerMeetingClient->v_participants);
for ($i = 0; $i < $cntParticipants; $i++) {
- /** @var EntUser $participantUser */
- $participantUser = $em->getRepository('App:EntUser')->find($customerMeetingClient->v_participants[$i]->participant_user_id);
+ /** @var User $participantUser */
+ $participantUser = $this->em->getRepository(User::class)->find($customerMeetingClient->v_participants[$i]->participant_user_id);
if (is_null($participantUser)) {
throw new Exception('invalid participant user');
}
- /** @var EntCustomerMeetingParticipant $entParticipant */
- $entParticipant = new EntCustomerMeetingParticipant($em, $entCustomerMeeting, $participantUser);
- $em->persist($entParticipant);
+ /** @var CustomerMeetingParticipant $entParticipant */
+ $entParticipant = new CustomerMeetingParticipant($this->em, $entCustomerMeeting, $participantUser);
+ $this->em->persist($entParticipant);
}
- $em->flush();
+ $this->em->flush();
} catch (Exception $e) {
return Reply::getErrorResponse(Message::ERROR_INVALID_DATA);
@@ -84,37 +86,36 @@ class CustomerMeetingEditController extends AbstractController
$dbCon->commit();
$serviceData = new ServiceData();
- $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_ADD, $entCustomerMeeting->clientMapper($em, true));
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_MEETING_CREATE, 0, $serviceData);
+ $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_ADD, $entCustomerMeeting->clientMapper($this->em, true));
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_MEETING_CREATE, 0, $serviceData);
}
#[Route('/edit-customer-meeting', name: 'edit_customer_meeting')]
public function editCustomerMeeting(Request $request)
{
$customerMeetingClient = json_decode($request->request->get('customerMeeting'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($customerMeetingClient->customer_id);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($customerMeetingClient->customer_id);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntUser $entOwnerUser */
- $entOwnerUser = $em->getRepository('App:EntUser')->find($customerMeetingClient->owner_user_id);
+ /** @var User $entOwnerUser */
+ $entOwnerUser = $this->em->getRepository(User::class)->find($customerMeetingClient->owner_user_id);
if (is_null($entOwnerUser)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntMeetingType $entMeetingType */
- $entMeetingType = $em->getRepository('App:EntMeetingType')->find($customerMeetingClient->meeting_type_id);
+ /** @var MeetingType $entMeetingType */
+ $entMeetingType = $this->em->getRepository(MeetingType::class)->find($customerMeetingClient->meeting_type_id);
if (is_null($entMeetingType)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntCustomerMeeting $entCustomerMeeting */
- $entCustomerMeeting = $em->getRepository('App:EntCustomerMeeting')->find($customerMeetingClient->id);
+ /** @var CustomerMeeting $entCustomerMeeting */
+ $entCustomerMeeting = $this->em->getRepository(CustomerMeeting::class)->find($customerMeetingClient->id);
if (is_null($entCustomerMeeting)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
@@ -132,41 +133,41 @@ class CustomerMeetingEditController extends AbstractController
}
// Database manipulation in transaction
- $dbCon = $this->getDoctrine()->getConnection();
+ $dbCon = $this->em->getConnection();
$dbCon->beginTransaction();
try {
- $entCustomerMeeting->setClientData($em, $customerMeetingClient);
- $em->persist($entCustomerMeeting);
- $em->flush();
+ $entCustomerMeeting->setClientData($this->em, $customerMeetingClient);
+ $this->em->persist($entCustomerMeeting);
+ $this->em->flush();
$formerParticipantsByUserId = Utils::getSortedObjects('getParticipantUserId',
- $em->getRepository('App:EntCustomerMeetingParticipant')->findBy(['customer_meeting_id' => $entCustomerMeeting->getId()]));
+ $this->em->getRepository(CustomerMeetingParticipant::class)->findBy(['customer_meeting_id' => $entCustomerMeeting->getId()]));
$pUserIdsToKeep = [];
$cntParticipants = count($customerMeetingClient->v_participants);
for ($i = 0; $i < $cntParticipants; $i++) {
if (!array_key_exists($customerMeetingClient->v_participants[$i]->participant_user_id, $formerParticipantsByUserId)) {
- /** @var EntUser $participantUser */
- $participantUser = $em->getRepository('App:EntUser')->find($customerMeetingClient->v_participants[$i]->participant_user_id);
+ /** @var User $participantUser */
+ $participantUser = $this->em->getRepository(User::class)->find($customerMeetingClient->v_participants[$i]->participant_user_id);
if (is_null($participantUser)) {
throw new Exception('invalid participant user');
}
- /** @var EntCustomerMeetingParticipant $entParticipant */
- $entParticipant = new EntCustomerMeetingParticipant($em, $entCustomerMeeting, $participantUser);
- $em->persist($entParticipant);
+ /** @var CustomerMeetingParticipant $entParticipant */
+ $entParticipant = new CustomerMeetingParticipant($this->em, $entCustomerMeeting, $participantUser);
+ $this->em->persist($entParticipant);
} else {
$pUserIdsToKeep[$customerMeetingClient->v_participants[$i]->participant_user_id] = 1;
}
}
- /** @var EntCustomerMeetingParticipant $formerParticipant */
+ /** @var CustomerMeetingParticipant $formerParticipant */
foreach ($formerParticipantsByUserId as $pUserId => $formerParticipant) {
if (!array_key_exists($pUserId, $pUserIdsToKeep)) {
- $em->remove($formerParticipant);
+ $this->em->remove($formerParticipant);
}
}
- $em->flush();
+ $this->em->flush();
} catch (Exception $e) {
return Reply::getErrorResponse(Message::ERROR_INVALID_DATA);
@@ -174,20 +175,19 @@ class CustomerMeetingEditController extends AbstractController
// All data stored correctly
$dbCon->commit();
$serviceData = new ServiceData();
- $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_EDIT, $entCustomerMeeting->clientMapper($em, true));
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_MEETING_EDIT, 0, $serviceData);
+ $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_EDIT, $entCustomerMeeting->clientMapper($this->em, true));
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_MEETING_EDIT, 0, $serviceData);
}
#[Route('/delete-customer-meeting', name: 'delete_customer_meeting')]
public function deleteCustomerMeeting(Request $request)
{
$customerMeetingIdClient = json_decode($request->request->get('customerMeetingId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomerMeeting $entCustomerMeeting */
- $entCustomerMeeting = $em->getRepository('App:EntCustomerMeeting')->find($customerMeetingIdClient);
+ /** @var CustomerMeeting $entCustomerMeeting */
+ $entCustomerMeeting = $this->em->getRepository(CustomerMeeting::class)->find($customerMeetingIdClient);
if (is_null($entCustomerMeeting)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
@@ -204,36 +204,35 @@ class CustomerMeetingEditController extends AbstractController
return Reply::getErrorResponse(Message::ERROR_MEETING_NOT_EDIT_DELETABLE);
}
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($entCustomerMeeting->getCustomerId());
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerMeeting->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $mappedCustomerMeeting = $entCustomerMeeting->clientMapper($em, true);
- $em->remove($entCustomerMeeting);
+ $mappedCustomerMeeting = $entCustomerMeeting->clientMapper($this->em, true);
+ $this->em->remove($entCustomerMeeting);
- $participants = $em->getRepository('App:EntCustomerMeetingParticipant')->findBy(['customer_meeting_id' => $entCustomerMeeting->getId()]);
- /** @var EntCustomerMeetingParticipant $participant */
+ $participants = $this->em->getRepository(CustomerMeetingParticipant::class)->findBy(['customer_meeting_id' => $entCustomerMeeting->getId()]);
+ /** @var CustomerMeetingParticipant $participant */
foreach ($participants as $participant) {
- $em->remove($participant);
+ $this->em->remove($participant);
}
- $em->flush();
+ $this->em->flush();
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_DELETE, $mappedCustomerMeeting);
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_MEETING_DELETE, 0, $serviceData);
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_MEETING_DELETE, 0, $serviceData);
}
#[Route('/check-customer-meeting-report', name: 'check_customer_meeting_report')]
public function checkCustomerMeetingReport(Request $request)
{
$customerMeetingIdClient = json_decode($request->request->get('customerMeetingId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomerMeeting $entCustomerMeeting */
- $entCustomerMeeting = $em->getRepository('App:EntCustomerMeeting')->find($customerMeetingIdClient);
+ /** @var CustomerMeeting $entCustomerMeeting */
+ $entCustomerMeeting = $this->em->getRepository(CustomerMeeting::class)->find($customerMeetingIdClient);
$bHasRightsToMakeReport =
$entCustomerMeeting->getCreationUserId() == $user->getId() ||
$entCustomerMeeting->getOwnerUserId() == $user->getId() ||
@@ -251,13 +250,12 @@ class CustomerMeetingEditController extends AbstractController
{
$customerMeetingIdClient = json_decode($request->request->get('customerMeetingId'));
$customerMeetingReportClient = json_decode($request->request->get('customerMeetingReport'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntCustomerMeeting $entCustomerMeeting */
- $entCustomerMeeting = $em->getRepository('App:EntCustomerMeeting')->find($customerMeetingIdClient);
+ /** @var CustomerMeeting $entCustomerMeeting */
+ $entCustomerMeeting = $this->em->getRepository(CustomerMeeting::class)->find($customerMeetingIdClient);
$bHasRightsToMakeReport =
$entCustomerMeeting->getOwnerUserId() == $user->getId() ||
$user->isAdmin();
@@ -265,17 +263,17 @@ class CustomerMeetingEditController extends AbstractController
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- $entCustomer = $em->getRepository('App:EntCustomer')->find($entCustomerMeeting->getCustomerId());
+ $entCustomer = $this->em->getRepository(Customer::class)->find($entCustomerMeeting->getCustomerId());
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
$entCustomerMeeting->setReport($customerMeetingReportClient);
- $em->persist($entCustomerMeeting);
- $em->flush();
+ $this->em->persist($entCustomerMeeting);
+ $this->em->flush();
$serviceData = new ServiceData();
- $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_EDIT, $entCustomerMeeting->clientMapper($em, true));
- return Reply::getResponse($entCustomer->clientMapper($em, true), Message::SUCCESS_CUSTOMER_MEETING_REPORT_SET, 0, $serviceData);
+ $serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_CUSTOMER_MEETINGS, ServiceData::ACTION_EDIT, $entCustomerMeeting->clientMapper($this->em, true));
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true), Message::SUCCESS_CUSTOMER_MEETING_REPORT_SET, 0, $serviceData);
}
}
\ No newline at end of file
diff --git a/httpdocs/src/Controller/CustomerViewController.php b/httpdocs/src/Controller/CustomerViewController.php
index a557534..3e9737d 100644
--- a/httpdocs/src/Controller/CustomerViewController.php
+++ b/httpdocs/src/Controller/CustomerViewController.php
@@ -7,10 +7,13 @@
*/
namespace App\Controller;
-use App\Entity\EntCustomer;
+use App\Entity\Customer;
+use App\Entity\CustomerContact;
+use App\Entity\CustomerMeeting;
use App\Utils\Message;
use App\Utils\Reply;
use App\Utils\Utils;
+use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -19,15 +22,16 @@ use Symfony\Component\Routing\Annotation\Route;
#[Security("is_granted('ROLE_USER')")]
class CustomerViewController extends AbstractController
{
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/get-customer-data', name: 'get_customer_data')]
public function getCustomerData()
{
- $em = $this->getDoctrine()->getManager();
return Reply::getResponse(
[
- 'customers' => Utils::clientMap($em, $em->getRepository('App:EntCustomer')->findAll()),
- 'customerContacts' => Utils::clientMap($em, $em->getRepository('App:EntCustomerContact')->findAll()),
- 'customerMeetings' => Utils::clientMap($em, $em->getRepository('App:EntCustomerMeeting')->findAll()),
+ 'customers' => Utils::clientMap($this->em, $this->em->getRepository(Customer::class)->findAll()),
+ 'customerContacts' => Utils::clientMap($this->em, $this->em->getRepository(CustomerContact::class)->findAll()),
+ 'customerMeetings' => Utils::clientMap($this->em, $this->em->getRepository(CustomerMeeting::class)->findAll()),
]
);
}
@@ -36,14 +40,13 @@ class CustomerViewController extends AbstractController
public function getCustomerFull(Request $request)
{
$customerId = json_decode($request->request->get('customerId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntCustomer $entCustomer */
- $entCustomer = $em->getRepository('App:EntCustomer')->find($customerId);
+ /** @var Customer $entCustomer */
+ $entCustomer = $this->em->getRepository(Customer::class)->find($customerId);
if (is_null($entCustomer)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- return Reply::getResponse($entCustomer->clientMapper($em, true));
+ return Reply::getResponse($entCustomer->clientMapper($this->em, true));
}
}
\ No newline at end of file
diff --git a/httpdocs/src/Controller/ExportController.php b/httpdocs/src/Controller/ExportController.php
index 4153f8a..f5309be 100644
--- a/httpdocs/src/Controller/ExportController.php
+++ b/httpdocs/src/Controller/ExportController.php
@@ -7,8 +7,9 @@
*/
namespace App\Controller;
-use App\Entity\EntUser;
+use App\Entity\User;
use App\Utils\Reply;
+use Doctrine\ORM\EntityManagerInterface;
use Dompdf\Dompdf;
use Dompdf\Options;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
@@ -22,15 +23,16 @@ class ExportController extends AbstractController
{
const CONTACT_PDF_TYPE_CUSTOMER = 'customer';
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/get-customer-full', name: 'get_customer_full')]
public function exportContacts(Request $request)
{
ini_set('max_execution_time', '300');
ini_set('memory_limit','1024');
$type = $request->request->get('type');
- $em = $this->getDoctrine()->getManager();
$title = "";
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
@@ -43,7 +45,7 @@ class ExportController extends AbstractController
FROM customer_contact cc, customer c
WHERE cc.customer_id = c.id
ORDER BY company ASC, cc.lastname ASC";
- $statement = $em->getConnection()->prepare($sql);
+ $statement = $this->em->getConnection()->prepare($sql);
$statement->execute();
$entries = $statement->fetchAll();
$title = "Kunden Kontakte";
diff --git a/httpdocs/src/Controller/InternalMeetingEditController.php b/httpdocs/src/Controller/InternalMeetingEditController.php
index e0206ad..2229580 100644
--- a/httpdocs/src/Controller/InternalMeetingEditController.php
+++ b/httpdocs/src/Controller/InternalMeetingEditController.php
@@ -7,13 +7,14 @@
*/
namespace App\Controller;
-use App\Entity\EntInternalMeeting;
-use App\Entity\EntInternalMeetingParticipant;
-use App\Entity\EntUser;
+use App\Entity\InternalMeeting;
+use App\Entity\InternalMeetingParticipant;
+use App\Entity\User;
use App\EntityVirtual\ServiceData;
use App\Utils\Message;
use App\Utils\Reply;
use App\Utils\Utils;
+use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Config\Definition\Exception\Exception;
@@ -23,16 +24,17 @@ use Symfony\Component\Routing\Annotation\Route;
#[Security("is_granted('ROLE_USER')")]
class InternalMeetingEditController extends AbstractController
{
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/create-internal-meeting', name: 'create_internal_meeting')]
public function createInternalMeeting(Request $request)
{
$internalMeetingClient = json_decode($request->request->get('internalMeeting'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntUser $entOwnerUser */
- $entOwnerUser = $em->getRepository('App:EntUser')->find($internalMeetingClient->owner_user_id);
+ /** @var User $entOwnerUser */
+ $entOwnerUser = $this->em->getRepository(User::class)->find($internalMeetingClient->owner_user_id);
if (is_null($entOwnerUser)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
@@ -42,24 +44,24 @@ class InternalMeetingEditController extends AbstractController
$dbCon->beginTransaction();
try {
- /** @var EntInternalMeeting $entInternalMeeting */
- $entInternalMeeting = new EntInternalMeeting($em, $user, $entOwnerUser, $internalMeetingClient->title, $internalMeetingClient->start_date, $internalMeetingClient->end_date);
- $entInternalMeeting->setClientData($em, $internalMeetingClient);
- $em->persist($entInternalMeeting);
- $em->flush();
+ /** @var InternalMeeting $entInternalMeeting */
+ $entInternalMeeting = new InternalMeeting($this->em, $user, $entOwnerUser, $internalMeetingClient->title, $internalMeetingClient->start_date, $internalMeetingClient->end_date);
+ $entInternalMeeting->setClientData($this->em, $internalMeetingClient);
+ $this->em->persist($entInternalMeeting);
+ $this->em->flush();
$cntParticipants = count($internalMeetingClient->v_participants);
for ($i = 0; $i < $cntParticipants; $i++) {
- /** @var EntUser $participantUser */
- $participantUser = $em->getRepository('App:EntUser')->find($internalMeetingClient->v_participants[$i]->participant_user_id);
+ /** @var User $participantUser */
+ $participantUser = $this->em->getRepository(User::class)->find($internalMeetingClient->v_participants[$i]->participant_user_id);
if (is_null($participantUser)) {
throw new Exception('invalid participant user');
}
- /** @var EntInternalMeetingParticipant $entParticipant */
- $entParticipant = new EntInternalMeetingParticipant($em, $entInternalMeeting, $participantUser);
- $em->persist($entParticipant);
+ /** @var InternalMeetingParticipant $entParticipant */
+ $entParticipant = new InternalMeetingParticipant($this->em, $entInternalMeeting, $participantUser);
+ $this->em->persist($entParticipant);
}
- $em->flush();
+ $this->em->flush();
} catch (Exception $e) {
return Reply::getErrorResponse(Message::ERROR_INVALID_DATA);
@@ -67,7 +69,7 @@ class InternalMeetingEditController extends AbstractController
// All data stored correctly
$dbCon->commit();
- $mappedInternalMeeting = $entInternalMeeting->clientMapper($em, true);
+ $mappedInternalMeeting = $entInternalMeeting->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_INTERNAL_MEETINGS, ServiceData::ACTION_ADD, $mappedInternalMeeting);
return Reply::getResponse($mappedInternalMeeting, Message::SUCCESS_INTERNAL_MEETING_CREATE, 0, $serviceData);
@@ -77,18 +79,17 @@ class InternalMeetingEditController extends AbstractController
public function editInternalMeeting(Request $request)
{
$internalMeetingClient = json_decode($request->request->get('internalMeeting'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntUser $entOwnerUser */
- $entOwnerUser = $em->getRepository('App:EntUser')->find($internalMeetingClient->owner_user_id);
+ /** @var User $entOwnerUser */
+ $entOwnerUser = $this->em->getRepository(User::class)->find($internalMeetingClient->owner_user_id);
if (is_null($entOwnerUser)) {
return Reply::getErrorResponse(Message::ERROR_DEFAULT);
}
- /** @var EntInternalMeeting $entInternalMeeting */
- $entInternalMeeting = $em->getRepository('App:EntInternalMeeting')->find($internalMeetingClient->id);
+ /** @var InternalMeeting $entInternalMeeting */
+ $entInternalMeeting = $this->em->getRepository(InternalMeeting::class)->find($internalMeetingClient->id);
if (is_null($entInternalMeeting)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
@@ -110,37 +111,37 @@ class InternalMeetingEditController extends AbstractController
$dbCon->beginTransaction();
try {
- $entInternalMeeting->setClientData($em, $internalMeetingClient);
- $em->persist($entInternalMeeting);
- $em->flush();
+ $entInternalMeeting->setClientData($this->em, $internalMeetingClient);
+ $this->em->persist($entInternalMeeting);
+ $this->em->flush();
$formerParticipantsByUserId = Utils::getSortedObjects('getParticipantUserId',
- $em->getRepository('App:EntInternalMeetingParticipant')->findBy(['internal_meeting_id' => $entInternalMeeting->getId()]));
+ $this->em->getRepository(InternalMeetingParticipant::class)->findBy(['internal_meeting_id' => $entInternalMeeting->getId()]));
$pUserIdsToKeep = [];
$cntParticipants = count($internalMeetingClient->v_participants);
for ($i = 0; $i < $cntParticipants; $i++) {
if (!array_key_exists($internalMeetingClient->v_participants[$i]->participant_user_id, $formerParticipantsByUserId)) {
- /** @var EntUser $participantUser */
- $participantUser = $em->getRepository('App:EntUser')->find($internalMeetingClient->v_participants[$i]->participant_user_id);
+ /** @var User $participantUser */
+ $participantUser = $this->em->getRepository(User::class)->find($internalMeetingClient->v_participants[$i]->participant_user_id);
if (is_null($participantUser)) {
throw new Exception('invalid participant user');
}
- /** @var EntInternalMeetingParticipant $entParticipant */
- $entParticipant = new EntInternalMeetingParticipant($em, $entInternalMeeting, $participantUser);
- $em->persist($entParticipant);
+ /** @var InternalMeetingParticipant $entParticipant */
+ $entParticipant = new InternalMeetingParticipant($this->em, $entInternalMeeting, $participantUser);
+ $this->em->persist($entParticipant);
} else {
$pUserIdsToKeep[$internalMeetingClient->v_participants[$i]->participant_user_id] = 1;
}
}
- /** @var EntInternalMeetingParticipant $formerParticipant */
+ /** @var InternalMeetingParticipant $formerParticipant */
foreach ($formerParticipantsByUserId as $pUserId => $formerParticipant) {
if (!array_key_exists($pUserId, $pUserIdsToKeep)) {
- $em->remove($formerParticipant);
+ $this->em->remove($formerParticipant);
}
}
- $em->flush();
+ $this->em->flush();
} catch (Exception $e) {
return Reply::getErrorResponse(Message::ERROR_INVALID_DATA);
@@ -148,7 +149,7 @@ class InternalMeetingEditController extends AbstractController
// All data stored correctly
$dbCon->commit();
- $mappedInternalMeeting = $entInternalMeeting->clientMapper($em, true);
+ $mappedInternalMeeting = $entInternalMeeting->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_INTERNAL_MEETINGS, ServiceData::ACTION_EDIT, $mappedInternalMeeting);
return Reply::getResponse($mappedInternalMeeting, Message::SUCCESS_INTERNAL_MEETING_EDIT, 0, $serviceData);
@@ -158,12 +159,11 @@ class InternalMeetingEditController extends AbstractController
public function deleteInternalMeeting(Request $request)
{
$internalMeetingIdClient = json_decode($request->request->get('internalMeetingId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntInternalMeeting $entInternalMeeting */
- $entInternalMeeting = $em->getRepository('App:EntInternalMeeting')->find($internalMeetingIdClient);
+ /** @var InternalMeeting $entInternalMeeting */
+ $entInternalMeeting = $this->em->getRepository(InternalMeeting::class)->find($internalMeetingIdClient);
if (is_null($entInternalMeeting)) {
return Reply::getErrorResponse(Message::ERROR_NON_EXISTING_DATA);
}
@@ -180,15 +180,15 @@ class InternalMeetingEditController extends AbstractController
return Reply::getErrorResponse(Message::ERROR_MEETING_NOT_EDIT_DELETABLE);
}
- $mappedInternalMeeting = $entInternalMeeting->clientMapper($em, true);
- $em->remove($entInternalMeeting);
+ $mappedInternalMeeting = $entInternalMeeting->clientMapper($this->em, true);
+ $this->em->remove($entInternalMeeting);
- $participants = $em->getRepository('App:EntInternalMeetingParticipant')->findBy(['internal_meeting_id' => $entInternalMeeting->getId()]);
- /** @var EntInternalMeetingParticipant $participant */
+ $participants = $this->em->getRepository(InternalMeetingParticipant::class)->findBy(['internal_meeting_id' => $entInternalMeeting->getId()]);
+ /** @var InternalMeetingParticipant $participant */
foreach ($participants as $participant) {
- $em->remove($participant);
+ $this->em->remove($participant);
}
- $em->flush();
+ $this->em->flush();
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_INTERNAL_MEETINGS, ServiceData::ACTION_DELETE, $mappedInternalMeeting);
@@ -199,12 +199,11 @@ class InternalMeetingEditController extends AbstractController
public function checkInternalMeetingReport(Request $request)
{
$internalMeetingIdClient = json_decode($request->request->get('internalMeetingId'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntInternalMeeting $entInternalMeeting */
- $entInternalMeeting = $em->getRepository('App:EntInternalMeeting')->find($internalMeetingIdClient);
+ /** @var InternalMeeting $entInternalMeeting */
+ $entInternalMeeting = $this->em->getRepository(InternalMeeting::class)->find($internalMeetingIdClient);
$bHasRightsToMakeReport =
$entInternalMeeting->getOwnerUserId() == $user->getId() ||
$user->isAdmin();
@@ -221,13 +220,12 @@ class InternalMeetingEditController extends AbstractController
{
$internalMeetingIdClient = json_decode($request->request->get('internalMeetingId'));
$internalMeetingReportClient = json_decode($request->request->get('internalMeetingReport'));
- $em = $this->getDoctrine()->getManager();
- /** @var EntUser $user */
+ /** @var User $user */
$user = $this->getUser();
- /** @var EntInternalMeeting $entInternalMeeting */
- $entInternalMeeting = $em->getRepository('App:EntInternalMeeting')->find($internalMeetingIdClient);
+ /** @var InternalMeeting $entInternalMeeting */
+ $entInternalMeeting = $this->em->getRepository(InternalMeeting::class)->find($internalMeetingIdClient);
$bHasRightsToMakeReport =
$entInternalMeeting->getOwnerUserId() == $user->getId() ||
$user->isAdmin();
@@ -236,10 +234,10 @@ class InternalMeetingEditController extends AbstractController
}
$entInternalMeeting->setReport($internalMeetingReportClient);
- $em->persist($entInternalMeeting);
- $em->flush();
+ $this->em->persist($entInternalMeeting);
+ $this->em->flush();
- $mappedInternalMeeting = $entInternalMeeting->clientMapper($em, true);
+ $mappedInternalMeeting = $entInternalMeeting->clientMapper($this->em, true);
$serviceData = new ServiceData();
$serviceData->addServiceData(ServiceData::SERVICE_DATA_TYPE_INTERNAL_MEETINGS, ServiceData::ACTION_EDIT, $mappedInternalMeeting);
return Reply::getResponse($mappedInternalMeeting, Message::SUCCESS_INTERNAL_MEETING_REPORT_SET, 0, $serviceData);
diff --git a/httpdocs/src/Controller/MeetingViewController.php b/httpdocs/src/Controller/MeetingViewController.php
index 6bee147..f445578 100644
--- a/httpdocs/src/Controller/MeetingViewController.php
+++ b/httpdocs/src/Controller/MeetingViewController.php
@@ -7,12 +7,13 @@
*/
namespace App\Controller;
-use App\Entity\EntCustomerMeeting;
-use App\Entity\EntInternalMeeting;
+use App\Entity\CustomerMeeting;
+use App\Entity\InternalMeeting;
use App\Utils\Excel;
use App\Utils\ExcelStyle;
use App\Utils\Reply;
use App\Utils\Utils;
+use Doctrine\ORM\EntityManagerInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
@@ -24,14 +25,15 @@ use Symfony\Component\Routing\Annotation\Route;
#[Security("is_granted('ROLE_USER')")]
class MeetingViewController extends AbstractController
{
+ public function __construct(private EntityManagerInterface $em) {}
+
#[Route('/get-meeting-data', name: 'get_meeting_data')]
public function getMeetingData()
{
- $em = $this->getDoctrine()->getManager();
return Reply::getResponse(
[
- 'customerMeetings' => Utils::clientMap($em, $em->getRepository(EntCustomerMeeting::class)->findAll()),
- 'internalMeetings' => Utils::clientMap($em, $em->getRepository(EntInternalMeeting::class)->findAll()),
+ 'customerMeetings' => Utils::clientMap($this->em, $this->em->getRepository(CustomerMeeting::class)->findAll()),
+ 'internalMeetings' => Utils::clientMap($this->em, $this->em->getRepository(InternalMeeting::class)->findAll()),
]
);
}
diff --git a/httpdocs/src/Controller/PublicController.php b/httpdocs/src/Controller/PublicController.php
index b443930..c368d0c 100644
--- a/httpdocs/src/Controller/PublicController.php
+++ b/httpdocs/src/Controller/PublicController.php
@@ -51,7 +51,7 @@ class PublicController extends AbstractController
}
#[Route('/logout', name: 'security_logout')]
- public function logoutAction()
+ public function logoutAction(): never
{
throw new Exception('this should not be reached');
}
diff --git a/httpdocs/src/Entity/EntCountry.php b/httpdocs/src/Entity/Country.php
similarity index 96%
rename from httpdocs/src/Entity/EntCountry.php
rename to httpdocs/src/Entity/Country.php
index 7c079ed..2cf37b1 100644
--- a/httpdocs/src/Entity/EntCountry.php
+++ b/httpdocs/src/Entity/Country.php
@@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'country')]
#[ORM\Entity]
-class EntCountry implements IEntity
+class Country implements IEntity
{
const COUNTRY_GERMANY_ID = 1;
const COUNTRY_AUSTRIA_ID = 2;
@@ -47,7 +47,7 @@ class EntCountry implements IEntity
public static function getCountriesById(EntityManagerInterface $em)
{
if (is_null(self::$cacheCountriesById)) {
- self::$cacheCountriesById = Utils::getSortedObjectsById($em->getRepository('App:EntCountry')->findAll());
+ self::$cacheCountriesById = Utils::getSortedObjectsById($em->getRepository(self::class)->findAll());
}
return self::$cacheCountriesById;
}
@@ -80,7 +80,7 @@ class EntCountry implements IEntity
}
/**
- * EntCountry constructor.
+ * Country constructor.
* @param $countryName
* @param $isoCode
*/
diff --git a/httpdocs/src/Entity/EntCustomer.php b/httpdocs/src/Entity/Customer.php
similarity index 96%
rename from httpdocs/src/Entity/EntCustomer.php
rename to httpdocs/src/Entity/Customer.php
index 666295a..c11c0c7 100644
--- a/httpdocs/src/Entity/EntCustomer.php
+++ b/httpdocs/src/Entity/Customer.php
@@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'customer')]
#[ORM\Entity]
-class EntCustomer implements IEntity
+class Customer implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -69,7 +69,7 @@ class EntCustomer implements IEntity
protected $creation_date;
/**
- * EntCustomer constructor.
+ * Customer constructor.
* @param ObjectManager $em
* @param $name
* @throws \Exception
@@ -409,9 +409,9 @@ class EntCustomer implements IEntity
];
if ($fullMapping) {
- $res['v_customer_contacts'] = Utils::clientMap($em, $em->getRepository('App:EntCustomerContact')->findBy(['customer_id' => $this->getId()]));
- $res['v_customer_notes'] = Utils::clientMap($em, $em->getRepository('App:EntCustomerNote')->findBy(['customer_id' => $this->getId()]));
- $res['v_customer_meetings'] = Utils::clientMap($em, $em->getRepository('App:EntCustomerMeeting')->findBy(['customer_id' => $this->getId()]));
+ $res['v_customer_contacts'] = Utils::clientMap($em, $em->getRepository(CustomerContact::class)->findBy(['customer_id' => $this->getId()]));
+ $res['v_customer_notes'] = Utils::clientMap($em, $em->getRepository(CustomerNote::class)->findBy(['customer_id' => $this->getId()]));
+ $res['v_customer_meetings'] = Utils::clientMap($em, $em->getRepository(CustomerMeeting::class)->findBy(['customer_id' => $this->getId()]));
}
return $res;
diff --git a/httpdocs/src/Entity/EntCustomerContact.php b/httpdocs/src/Entity/CustomerContact.php
similarity index 97%
rename from httpdocs/src/Entity/EntCustomerContact.php
rename to httpdocs/src/Entity/CustomerContact.php
index 7382e5c..1fe4a56 100644
--- a/httpdocs/src/Entity/EntCustomerContact.php
+++ b/httpdocs/src/Entity/CustomerContact.php
@@ -12,7 +12,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Table(name: 'customer_contact')]
#[ORM\Entity]
-class EntCustomerContact implements IEntity
+class CustomerContact implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -74,13 +74,13 @@ class EntCustomerContact implements IEntity
protected $is_xmas_mail_recipient = false;
/**
- * EntCustomerContact constructor.
+ * CustomerContact constructor.
* @param EntityManagerInterface $em
- * @param EntCustomer $entCustomer
+ * @param Customer $entCustomer
* @param $lastName
* @throws \Exception
*/
- public function __construct(EntityManagerInterface $em, EntCustomer $entCustomer, $lastName)
+ public function __construct(EntityManagerInterface $em, Customer $entCustomer, $lastName)
{
if (is_null($entCustomer->getId())) {
throw new Exception('no id found');
diff --git a/httpdocs/src/Entity/EntCustomerMeeting.php b/httpdocs/src/Entity/CustomerMeeting.php
similarity index 95%
rename from httpdocs/src/Entity/EntCustomerMeeting.php
rename to httpdocs/src/Entity/CustomerMeeting.php
index a6c5b4d..e7b457a 100644
--- a/httpdocs/src/Entity/EntCustomerMeeting.php
+++ b/httpdocs/src/Entity/CustomerMeeting.php
@@ -12,7 +12,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Table(name: 'customer_meeting')]
#[ORM\Index(name: 'search_customer_idx', columns: ['customer_id', 'owner_user_id', 'customer_contact_id'])]
#[ORM\Entity]
-class EntCustomerMeeting implements IEntity
+class CustomerMeeting implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -105,20 +105,20 @@ class EntCustomerMeeting implements IEntity
/**
- * EntCustomerMeeting constructor.
+ * CustomerMeeting constructor.
* @param ObjectManager $em
- * @param EntCustomer $entCustomer
- * @param EntUser $entCreationUser
- * @param EntUser $entOwnerUser
- * @param EntMeetingType $entMeetingType
+ * @param Customer $entCustomer
+ * @param User $entCreationUser
+ * @param User $entOwnerUser
+ * @param MeetingType $entMeetingType
* @param $isOptionMeeting
* @param $title
* @param $startDate
* @param $endDate
* @throws \Exception
*/
- public function __construct(ObjectManager $em, EntCustomer $entCustomer, EntUser $entCreationUser, EntUser $entOwnerUser,
- EntMeetingType $entMeetingType, $isOptionMeeting, $title, $startDate, $endDate)
+ public function __construct(ObjectManager $em, Customer $entCustomer, User $entCreationUser, User $entOwnerUser,
+ MeetingType $entMeetingType, $isOptionMeeting, $title, $startDate, $endDate)
{
if (is_null($entCustomer->getId())) {
throw new Exception('no id found');
@@ -132,7 +132,7 @@ class EntCustomerMeeting implements IEntity
throw new Exception('no id found');
}
- $meetingTypesById = EntMeetingType::getMeetingTypesById($em);
+ $meetingTypesById = MeetingType::getMeetingTypesById($em);
if (is_null($entMeetingType->getId()) || !array_key_exists($entMeetingType->getId(), $meetingTypesById)) {
throw new Exception('no id found');
}
@@ -460,8 +460,8 @@ class EntCustomerMeeting implements IEntity
if ($customer_contact_id == 0) {
$this->customer_contact_id = $customer_contact_id;
} else {
- /** @var EntCustomerContact $entCustomerContact */
- $entCustomerContact = $em->getRepository('App:EntCustomerContact')->find($customer_contact_id);
+ /** @var CustomerContact $entCustomerContact */
+ $entCustomerContact = $em->getRepository(CustomerContact::class)->find($customer_contact_id);
// NOTE: Check if contact still exists
$this->customer_contact_id = !is_null($entCustomerContact) ? $customer_contact_id : null;
}
@@ -691,7 +691,7 @@ class EntCustomerMeeting implements IEntity
'report_done' => $this->report_done,
'report_reminder_sent' => $this->report_reminder_sent,
'creation_date' => !is_null($this->creation_date) ? $this->creation_date->format('Y-m-d H:i:s'): null,
- 'v_participants' => Utils::clientMap($em, $em->getRepository('App:EntCustomerMeetingParticipant')->findBy(['customer_meeting_id' => $this->id])),
+ 'v_participants' => Utils::clientMap($em, $em->getRepository(CustomerMeetingParticipant::class)->findBy(['customer_meeting_id' => $this->id])),
'v_is_editable' => $now < $this->start_date,
];
}
diff --git a/httpdocs/src/Entity/EntCustomerMeetingParticipant.php b/httpdocs/src/Entity/CustomerMeetingParticipant.php
similarity index 86%
rename from httpdocs/src/Entity/EntCustomerMeetingParticipant.php
rename to httpdocs/src/Entity/CustomerMeetingParticipant.php
index 049d36c..c289377 100644
--- a/httpdocs/src/Entity/EntCustomerMeetingParticipant.php
+++ b/httpdocs/src/Entity/CustomerMeetingParticipant.php
@@ -13,7 +13,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Index(name: 'search_participant_idx', columns: ['customer_meeting_id', 'participant_user_id'])]
#[UniqueConstraint(name: 'unique_participant', columns: ['customer_meeting_id', 'participant_user_id'])]
#[ORM\Entity]
-class EntCustomerMeetingParticipant implements IEntity
+class CustomerMeetingParticipant implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -28,12 +28,12 @@ class EntCustomerMeetingParticipant implements IEntity
/**
- * EntCustomerMeetingParticipant constructor.
+ * CustomerMeetingParticipant constructor.
* @param EntityManagerInterface $em
- * @param EntCustomerMeeting $entCustomerMeeting
- * @param EntUser $entParticipantUser
+ * @param CustomerMeeting $entCustomerMeeting
+ * @param User $entParticipantUser
*/
- public function __construct(EntityManagerInterface $em, EntCustomerMeeting $entCustomerMeeting, EntUser $entParticipantUser)
+ public function __construct(EntityManagerInterface $em, CustomerMeeting $entCustomerMeeting, User $entParticipantUser)
{
if (is_null($entCustomerMeeting->getId())) {
throw new Exception('no id found');
diff --git a/httpdocs/src/Entity/EntCustomerNote.php b/httpdocs/src/Entity/CustomerNote.php
similarity index 95%
rename from httpdocs/src/Entity/EntCustomerNote.php
rename to httpdocs/src/Entity/CustomerNote.php
index e37be01..1d67cf9 100644
--- a/httpdocs/src/Entity/EntCustomerNote.php
+++ b/httpdocs/src/Entity/CustomerNote.php
@@ -11,7 +11,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Table(name: 'customer_note')]
#[ORM\Entity]
-class EntCustomerNote implements IEntity
+class CustomerNote implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -71,14 +71,14 @@ class EntCustomerNote implements IEntity
/**
- * EntCustomerNote constructor.
+ * CustomerNote constructor.
* @param ObjectManager $em
- * @param EntCustomer $entCustomer
- * @param EntUser $entUser
+ * @param Customer $entCustomer
+ * @param User $entUser
* @param $title
* @throws \Exception
*/
- public function __construct(ObjectManager $em, EntCustomer $entCustomer, EntUser $entUser, $title)
+ public function __construct(ObjectManager $em, Customer $entCustomer, User $entUser, $title)
{
if (is_null($entCustomer->getId())) {
throw new Exception('no id found');
@@ -250,8 +250,8 @@ class EntCustomerNote implements IEntity
if ($customer_contact_id == 0) {
$this->customer_contact_id = $customer_contact_id;
} else {
- /** @var EntCustomerContact $entCustomerContact */
- $entCustomerContact = $em->getRepository('App:EntCustomerContact')->find($customer_contact_id);
+ /** @var CustomerContact $entCustomerContact */
+ $entCustomerContact = $em->getRepository(CustomerContact::class)->find($customer_contact_id);
// NOTE: Check if contact still exists
$this->customer_contact_id = !is_null($entCustomerContact) ? $customer_contact_id : null;
}
diff --git a/httpdocs/src/Entity/EntUserType.php b/httpdocs/src/Entity/EntUserType.php
deleted file mode 100644
index c044d41..0000000
--- a/httpdocs/src/Entity/EntUserType.php
+++ /dev/null
@@ -1,155 +0,0 @@
- array(self::USER_ROLE_ADMIN, self::USER_ROLE_USER, self::USER_ROLE_SALES, self::USER_ROLE_TECHNIQUE,
- self::USER_ROLE_PRODUCTION, self::USER_ROLE_ACCOUNTING, self::USER_ROLE_SERVICE),
- self::USER_TYPE_ID_SALES => array(self::USER_ROLE_USER, self::USER_ROLE_SALES),
- self::USER_TYPE_ID_TECHNIQUE => array(self::USER_ROLE_USER, self::USER_ROLE_TECHNIQUE, self::USER_ROLE_PRODUCTION, self::USER_ROLE_SERVICE),
- self::USER_TYPE_ID_PRODUCTION => array(self::USER_ROLE_USER, self::USER_ROLE_PRODUCTION, self::USER_ROLE_SERVICE),
- self::USER_TYPE_ID_ACCOUNTING => array(self::USER_ROLE_USER, self::USER_ROLE_ACCOUNTING),
- self::USER_TYPE_ID_SERVICE => array(self::USER_ROLE_USER, self::USER_ROLE_SERVICE, self::USER_ROLE_PRODUCTION),
- );
-
- // Role translations for client
- private static $translatedRoles = array(
- self::USER_TYPE_ID_ADMIN => 'Admin',
- self::USER_TYPE_ID_SALES => 'Vertrieb',
- self::USER_TYPE_ID_TECHNIQUE => 'Technik',
- self::USER_TYPE_ID_PRODUCTION => 'Produktion',
- self::USER_TYPE_ID_ACCOUNTING => 'Buchhaltung',
- self::USER_TYPE_ID_SERVICE => 'Service'
- );
-
- #[ORM\Id]
- #[ORM\GeneratedValue]
- #[ORM\Column(type: 'integer')]
- protected $id;
-
- #[ORM\Column(name: 'type', type: 'string', nullable: false, unique: true)]
- protected $type;
-
-
- public function __construct($type)
- {
- $this->type = $type;
- }
-
- /**
- * @return mixed
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * @return mixed
- */
- public function getType()
- {
- return $this->type;
- }
-
- /**
- * Returns all available user roles
- * @return array
- */
- public static function getAllUserRoles()
- {
- return self::$userRoles;
- }
-
- /**
- * Returns user roles
- * @param $userTypeId
- * @return string[]
- */
- public static function getUserRoles($userTypeId)
- {
- if (!array_key_exists($userTypeId, self::$userRoles)) {
- throw new Exception("unknown user type");
- }
- return self::$userRoles[$userTypeId];
- }
-
- public static function getTranslatedRole($userTypeId)
- {
- if (!array_key_exists($userTypeId, self::$translatedRoles)) {
- throw new Exception('invalid user type id given');
- }
- return self::$translatedRoles[$userTypeId];
- }
-
- /**
- * Returns role config
- * @return array
- */
- public static function getRolesConfig()
- {
- $rolesConfig = array();
- foreach (self::$userRoles as $userTypeId => $ur) {
- $rolesConfig[] = array(
- 'user_type_id' => $userTypeId,
- 'roles' => $ur,
- 'translation' => self::$translatedRoles[$userTypeId]
- );
- }
- return $rolesConfig;
- }
-
- public static function isValidUserTypeId($userTypeId)
- {
- return array_key_exists($userTypeId, self::$userRoles);
- }
-
- /**
- * Check if a given user type is higher than given compare id
- * @param $higherUserTypeId
- * @return bool
- */
- public static function isHigherUserType($higherUserTypeId, $lowerUserTypeId)
- {
- return $higherUserTypeId < $lowerUserTypeId;
- }
-
- public function clientMapper(EntityManagerInterface $em, $fullMapping = false) {
- return [
- 'user_type_id' => $this->getId(),
- 'type' => $this->type,
- 'v_roles' => self::getUserRoles($this->getId())
- ];
- }
-
-
-}
diff --git a/httpdocs/src/Entity/EntInternalMeeting.php b/httpdocs/src/Entity/InternalMeeting.php
similarity index 95%
rename from httpdocs/src/Entity/EntInternalMeeting.php
rename to httpdocs/src/Entity/InternalMeeting.php
index 6bd15b5..b1a4aeb 100644
--- a/httpdocs/src/Entity/EntInternalMeeting.php
+++ b/httpdocs/src/Entity/InternalMeeting.php
@@ -12,7 +12,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Table(name: 'internal_meeting')]
#[ORM\Index(name: 'search_owner_idx', columns: ['owner_user_id'])]
#[ORM\Entity]
-class EntInternalMeeting implements IEntity
+class InternalMeeting implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -54,16 +54,16 @@ class EntInternalMeeting implements IEntity
/**
- * EntInternalMeeting constructor.
+ * InternalMeeting constructor.
* @param ObjectManager $em
- * @param EntUser $entCreationUser
- * @param EntUser $entOwnerUser
+ * @param User $entCreationUser
+ * @param User $entOwnerUser
* @param $title
* @param $startDate
* @param $endDate
* @throws \Exception
*/
- public function __construct(ObjectManager $em, EntUser $entCreationUser, EntUser $entOwnerUser, $title, $startDate, $endDate)
+ public function __construct(ObjectManager $em, User $entCreationUser, User $entOwnerUser, $title, $startDate, $endDate)
{
if (is_null($entCreationUser->getId())) {
throw new Exception('no id found');
@@ -305,7 +305,7 @@ class EntInternalMeeting implements IEntity
'second_reminder_sent' => $this->second_reminder_sent,
'report_reminder_sent' => $this->report_reminder_sent,
'creation_date' => !is_null($this->creation_date) ? $this->creation_date->format('Y-m-d H:i:s'): null,
- 'v_participants' => Utils::clientMap($em, $em->getRepository('App:EntInternalMeetingParticipant')->findBy(['internal_meeting_id' => $this->id])),
+ 'v_participants' => Utils::clientMap($em, $em->getRepository(InternalMeetingParticipant::class)->findBy(['internal_meeting_id' => $this->id])),
'v_is_editable' => $now < $this->start_date,
];
}
diff --git a/httpdocs/src/Entity/EntInternalMeetingParticipant.php b/httpdocs/src/Entity/InternalMeetingParticipant.php
similarity index 86%
rename from httpdocs/src/Entity/EntInternalMeetingParticipant.php
rename to httpdocs/src/Entity/InternalMeetingParticipant.php
index 86b802b..4f2130e 100644
--- a/httpdocs/src/Entity/EntInternalMeetingParticipant.php
+++ b/httpdocs/src/Entity/InternalMeetingParticipant.php
@@ -13,7 +13,7 @@ use Symfony\Component\Config\Definition\Exception\Exception;
#[ORM\Index(name: 'search_participant_idx', columns: ['internal_meeting_id', 'participant_user_id'])]
#[UniqueConstraint(name: 'unique_participant', columns: ['internal_meeting_id', 'participant_user_id'])]
#[ORM\Entity]
-class EntInternalMeetingParticipant implements IEntity
+class InternalMeetingParticipant implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -28,12 +28,12 @@ class EntInternalMeetingParticipant implements IEntity
/**
- * EntInternalMeetingParticipant constructor.
+ * InternalMeetingParticipant constructor.
* @param EntityManagerInterface $em
- * @param EntInternalMeeting $entInternalMeeting
- * @param EntUser $entParticipantUser
+ * @param InternalMeeting $entInternalMeeting
+ * @param User $entParticipantUser
*/
- public function __construct(EntityManagerInterface $em, EntInternalMeeting $entInternalMeeting, EntUser $entParticipantUser)
+ public function __construct(EntityManagerInterface $em, InternalMeeting $entInternalMeeting, User $entParticipantUser)
{
if (is_null($entInternalMeeting->getId())) {
throw new Exception('no id found');
diff --git a/httpdocs/src/Entity/EntMeetingType.php b/httpdocs/src/Entity/MeetingType.php
similarity index 94%
rename from httpdocs/src/Entity/EntMeetingType.php
rename to httpdocs/src/Entity/MeetingType.php
index d18992a..dffe543 100644
--- a/httpdocs/src/Entity/EntMeetingType.php
+++ b/httpdocs/src/Entity/MeetingType.php
@@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'meeting_type')]
#[ORM\Entity]
-class EntMeetingType implements IEntity
+class MeetingType implements IEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -32,7 +32,7 @@ class EntMeetingType implements IEntity
public static function getMeetingTypesById(EntityManagerInterface $em)
{
if (is_null(self::$cacheMeetingTypesById)) {
- self::$cacheMeetingTypesById = Utils::getSortedObjectsById($em->getRepository('App:EntMeetingType')->findAll());
+ self::$cacheMeetingTypesById = Utils::getSortedObjectsById($em->getRepository(self::class)->findAll());
}
return self::$cacheMeetingTypesById;
}
diff --git a/httpdocs/src/Entity/EntUser.php b/httpdocs/src/Entity/User.php
similarity index 75%
rename from httpdocs/src/Entity/EntUser.php
rename to httpdocs/src/Entity/User.php
index d90e818..615fc7e 100644
--- a/httpdocs/src/Entity/EntUser.php
+++ b/httpdocs/src/Entity/User.php
@@ -8,14 +8,19 @@ use App\Utils\Utils;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping as ORM;
+use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
+use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity]
#[ORM\Table(name: "user")]
-class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterface
+class User implements IEntity, UserInterface, PasswordAuthenticatedUserInterface//, UserLoaderInterface
{
+ const USER_ROLE_ADMIN = "ROLE_ADMIN";
+ const USER_ROLE_USER = "ROLE_USER";
+
// Costs of password encryption
const CRYPT_COST = 12;
@@ -48,18 +53,7 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
#[ORM\Column(type: 'datetime', nullable: false)]
protected $creation_date;
- /**
- * EntUser constructor.
- * @param EntityManagerInterface $em
- * @param $email
- * @param $firstName
- * @param $lastName
- * @param $password
- * @param $userTypeIdCreatingUser
- * @param EntUser|null $editingUser
- * @throws \Exception
- */
- public function __construct(EntityManagerInterface $em, $email, $firstName, $lastName, $password, $userTypeIdCreatingUser, EntUser $editingUser = null)
+ public function __construct(EntityManagerInterface $em, $email, $firstName, $lastName, $password, $userTypeIdCreatingUser, User $editingUser = null)
{
// Check email
if (!Utils::validateEmail($em, $email)) {
@@ -154,6 +148,11 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
return $this->email;
}
+// public function loadUserByIdentifier(string $identifier): ?UserInterface
+// {
+// // TODO: Implement loadUserByIdentifier() method.
+// }
+
public function getRoles(): array
{
$roles = $this->roles;
@@ -170,42 +169,30 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
return $this;
}
- /**
- * Returns if user has admin rights
- * @return bool
- */
public function isAdmin()
{
- return in_array(EntUserType::USER_ROLE_ADMIN, $this->getRoles());
+ return in_array(self::USER_ROLE_ADMIN, $this->getRoles(), true);
}
- /**
- * Erases credentials as part of UserInterface needed in Symfony
- */
public function eraseCredentials() {}
- /**
- * Checks password as part of UserInterface needed in Symfony
- * @param $password
- * @return bool
- */
public function checkPassword($password)
{
return $this->active && password_verify($password, $this->password);
}
/**
- * Returns salt as part of UserInterface needed in Symfony
- * @return null|string|void
+ * Returning a salt is only needed if you are not using a modern
+ * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
+ *
+ * @see UserInterface
*/
- public function getSalt() {}
+ public function getSalt(): ?string
+ {
+ return null;
+ }
- /**
- * Sets email with check on validity and existence
- * @param ObjectManager $em
- * @param $email
- */
- public function setEmail(ObjectManager $em, $email)
+ public function setEmail(EntityManagerInterface $em, $email)
{
if ($email != $this->email) {
if (!Utils::validateEmail($em, $email)) {
@@ -215,34 +202,21 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
}
}
- /**
- * @param bool|string $password
- */
public function setPassword($password): void
{
$this->password = $password;
}
- /**
- * @param bool $active
- */
public function setActive(bool $active): void
{
$this->active = $active;
}
- /**
- * @param mixed $lastname
- */
public function setLastname($lastname): void
{
$this->lastname = $lastname;
}
- /**
- * @param string $firstname
- * @return EntUser
- */
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
@@ -250,25 +224,16 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
return $this;
}
- /**
- * @param bool $visible
- */
public function setVisible(bool $visible): void
{
$this->visible = $visible;
}
- /**
- * Returns whether this user is on higher user role level than given user to compare with
- * @param EntUser $compareUser
- * @return bool
- */
- public function isHigherUser(EntUser $compareUser)
+ private function getTranslatedRole(): string
{
- return EntUserType::isHigherUserType($this->user_type_id, $compareUser->getUserTypeId());
+ return $this->isAdmin() ? 'Admin' : 'User';
}
-
/**
* Sets client data
* @param EntityManagerInterface $em
@@ -296,6 +261,8 @@ class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterf
'lastname' => $this->lastname,
'active' => $this->active,
'visible' => $this->visible,
+ 'roles' => $this->getRoles(),
+ 'v_translated_role' => $this->getTranslatedRole()
];
}
diff --git a/httpdocs/src/EventListener/ControllerListener.php b/httpdocs/src/EventListener/ControllerListener.php
index 149269f..5232aa4 100755
--- a/httpdocs/src/EventListener/ControllerListener.php
+++ b/httpdocs/src/EventListener/ControllerListener.php
@@ -3,7 +3,7 @@
namespace App\EventListener;
-use App\Entity\EntUser;
+use App\Entity\User;
use App\Utils\Tools;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
diff --git a/httpdocs/src/EventListener/DatabaseListener.php b/httpdocs/src/EventListener/DatabaseListener.php
index ca471df..fcc5243 100644
--- a/httpdocs/src/EventListener/DatabaseListener.php
+++ b/httpdocs/src/EventListener/DatabaseListener.php
@@ -9,7 +9,7 @@
namespace App\EventListener;
-use App\Entity\EntUser;
+use App\Entity\User;
use App\Entity\IFace\IEntity;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManager;
diff --git a/httpdocs/src/Security/JsonAuthenticator.php b/httpdocs/src/Security/JsonAuthenticator.php
index 1335437..685882a 100644
--- a/httpdocs/src/Security/JsonAuthenticator.php
+++ b/httpdocs/src/Security/JsonAuthenticator.php
@@ -7,7 +7,7 @@
*/
namespace App\Security;
-use App\Entity\EntUser;
+use App\Entity\User;
use App\Utils\Config;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
@@ -23,13 +23,10 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
class JsonAuthenticator extends AbstractAuthenticator
{
- const LOGIN_FAILED = 0;
- const LOGIN_SUCCESS = 1;
- private $em;
+ private EntityManagerInterface $em;
- /** @var $user EntUser */
- private $user;
+ private Passport $passport;
/**
* JsonAuthenticator constructor.
@@ -58,18 +55,21 @@ class JsonAuthenticator extends AbstractAuthenticator
{
$email = $request->request->get('email');
$password = $request->request->get('password');
- return new Passport(
+ $passport = new Passport(
new UserBadge($email),
new PasswordCredentials($password)
);
+ $this->passport = $passport;
+ return $passport;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response
{
// on success, let the request continue
+ /** @var User $user */
+ $user = $this->passport->getUser();
$data = array('message' => 'logged in successfully',
- 'isLoggedIn' => self::LOGIN_SUCCESS,
- 'user' => $this->user->clientMapper($this->em),
+ 'user' => $user->clientMapper($this->em),
'config' => Config::getConfig($this->em),
);
return new JsonResponse($data, Response::HTTP_ACCEPTED);
@@ -77,16 +77,7 @@ class JsonAuthenticator extends AbstractAuthenticator
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
- $data = array(
- 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()),
- 'isLoggedIn' => self::LOGIN_FAILED,
- 'user' => null,
- 'config' => null,
-
- // or to translate this message
- //$this->translator->trans($exception->getMessageKey(), $exception->getMessageData())
- );
- return new JsonResponse($data, Response::HTTP_FORBIDDEN);
+ return new JsonResponse(null, Response::HTTP_UNAUTHORIZED);
}
/**
diff --git a/httpdocs/src/Utils/Config.php b/httpdocs/src/Utils/Config.php
index c242914..4ee3deb 100644
--- a/httpdocs/src/Utils/Config.php
+++ b/httpdocs/src/Utils/Config.php
@@ -9,6 +9,9 @@
namespace App\Utils;
+use App\Entity\Country;
+use App\Entity\MeetingType;
+use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
class Config
@@ -21,9 +24,9 @@ class Config
public static function getConfig(EntityManagerInterface $em)
{
return [
- 'users' => Utils::clientMap($em, $em->getRepository('App:EntUser')->findBy(['visible' => true])),
- 'meeting_types' => Utils::clientMap($em, $em->getRepository('App:EntMeetingType')->findAll()),
- 'countries' => Utils::clientMap($em, $em->getRepository('App:EntCountry')->findAll()),
+ 'users' => Utils::clientMap($em, $em->getRepository(User::class)->findBy(['visible' => true])),
+ 'meeting_types' => Utils::clientMap($em, $em->getRepository(MeetingType::class)->findAll()),
+ 'countries' => Utils::clientMap($em, $em->getRepository(Country::class)->findAll()),
];
}
diff --git a/httpdocs/src/Utils/Utils.php b/httpdocs/src/Utils/Utils.php
index ac35958..83026a2 100644
--- a/httpdocs/src/Utils/Utils.php
+++ b/httpdocs/src/Utils/Utils.php
@@ -10,7 +10,10 @@ namespace App\Utils;
use App\Entity\IFace\IEntity;
+use App\Entity\User;
use Doctrine\DBAL\DriverManager;
+use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use function Couchbase\defaultDecoder;
@@ -116,8 +119,6 @@ class Utils
/**
* Checks email format
- * @param $email
- * @return bool
*/
public static function isValidEmail($email)
{
@@ -126,33 +127,22 @@ class Utils
/**
* Checks if valid gender
- * @param $gender
- * @return bool
*/
public static function isValidGender($gender)
{
return $gender == self::GENDER_MALE || $gender == self::GENDER_FEMALE || $gender == self::GENDER_DIVERSE;
}
- /**
- * Checks if an email exists in users, persons or locations
- * @param ObjectManager $em
- * @param $email
- * @return bool
- */
- public static function emailUserExists(ObjectManager $em, $email)
+ public static function emailUserExists(EntityManagerInterface $em, $email)
{
- $existingUserEmail = $em->getRepository('App:EntUser')->findOneBy(['email' => $email]);
+ $existingUserEmail = $em->getRepository(User::class)->findOneBy(['email' => $email]);
return !is_null($existingUserEmail);
}
/**
* Validates email and checks existence
- * @param ObjectManager $em
- * @param $email
- * @return bool
*/
- public static function validateEmail(ObjectManager $em, $email)
+ public static function validateEmail(EntityManagerInterface $em, $email)
{
return self::isValidEmail($email) && !self::emailUserExists($em, $email);
}
@@ -165,8 +155,8 @@ class Utils
public static function isExcelFile(UploadedFile $uploadedFile)
{
// Check client mime type
- return $uploadedFile->getClientMimeType() == 'application/vnd.ms-excel' ||
- $uploadedFile->getClientMimeType() == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
+ return $uploadedFile->getClientMimeType() === 'application/vnd.ms-excel' ||
+ $uploadedFile->getClientMimeType() === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}
/**
@@ -262,12 +252,8 @@ class Utils
/**
* Returns array of client mappable items
- * @param ObjectManager $em
- * @param $arr
- * @param bool $fullMapping
- * @return array
*/
- public static function clientMap(ObjectManager $em, $arr, $fullMapping = false)
+ public static function clientMap(EntityManagerInterface $em, $arr, $fullMapping = false)
{
$res = [];
foreach ($arr as $key => $value) {
@@ -283,9 +269,6 @@ class Utils
/**
* Returns array with file path info
- * @param $filePath
- * @param $fileName
- * @return array
*/
public static function getFilePathArray($filePath, $fileName)
{
@@ -297,10 +280,6 @@ class Utils
/**
* Creates a zip file of given files
- * @param $zipFilePath
- * @param $zipFileName
- * @param $files
- * @return string
*/
public static function createZipFile($zipFilePath, $zipFileName, $files)
{
@@ -317,10 +296,6 @@ class Utils
/**
* Creates a zip file from folder and optionally excluded files
- * @param $zipFilePath
- * @param $zipFileName
- * @param array $skippedFileNames
- * @param bool $includeZipPathFolder
*/
public static function createZipFileFromFolder($zipFilePath, $zipFileName, $skippedFileNames = [], $includeZipPathFolder = false)
{
@@ -449,9 +424,11 @@ class Utils
public static function copyFolderRecursively($sourcPath, $destinationPath)
{
$dir = opendir($sourcPath);
- @mkdir($destinationPath);
+ if (!mkdir($destinationPath) && !is_dir($destinationPath)) {
+ throw new \RuntimeException(sprintf('Directory "%s" was not created', $destinationPath));
+ }
while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
+ if (( $file !== '.' ) && ( $file !== '..' )) {
if ( is_dir($sourcPath . '/' . $file) ) {
self::copyFolderRecursively($sourcPath . '/' . $file,$destinationPath . '/' . $file);
}
@@ -470,7 +447,7 @@ class Utils
public static function deleteDirectory($dirPath) {
$dir = opendir($dirPath);
while(false !== ( $file = readdir($dir)) ) {
- if (( $file != '.' ) && ( $file != '..' )) {
+ if (( $file !== '.' ) && ( $file !== '..' )) {
$full = $dirPath . '/' . $file;
if ( is_dir($full) ) {
self::deleteDirectory($full);
diff --git a/httpdocs/symfony.lock b/httpdocs/symfony.lock
index db565b9..6caab37 100644
--- a/httpdocs/symfony.lock
+++ b/httpdocs/symfony.lock
@@ -35,6 +35,18 @@
"migrations/.gitignore"
]
},
+ "nelmio/cors-bundle": {
+ "version": "2.3",
+ "recipe": {
+ "repo": "github.com/symfony/recipes",
+ "branch": "main",
+ "version": "1.5",
+ "ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
+ },
+ "files": [
+ "config/packages/nelmio_cors.yaml"
+ ]
+ },
"sensio/framework-extra-bundle": {
"version": "6.2",
"recipe": {