Skip to content

Commit

Permalink
#35: Ajout des champ date de création de compte et dernière activité
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-its committed Feb 26, 2021
1 parent d08da27 commit f7847b4
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 82 deletions.
85 changes: 39 additions & 46 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,25 @@

namespace App\Controller;

use App\Entity\Customer;
use App\Entity\HalfDayAdjustment;
use App\Form\HalfDayAdjustmentType;
use App\Repository\HalfDayAdjustmentRepository;
use App\Form\CustomerSettingsAccountType;
use App\Form\CustomerSettingsPasswordType;
use App\Form\CustomerSettingsProfileType;
use App\Repository\CheckInRepository;
use App\Repository\OptionsRepository;
use App\Repository\SubscriptionRepository;
use App\Service\Services;
use Doctrine\Common\Persistence\ObjectManager;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Validator\Constraints\DateTime;
use App\Form\HalfDayType;
use App\Form\MonthType;
use App\Form\PlaceType;
use App\Form\PromoType;
use App\Form\CustomerType;
use App\Form\CustomerSettingStatusType;
use App\Form\TextHomeType;
use App\Repository\CustomerRepository;
use App\Repository\PromoRepository;
use phpDocumentor\Reflection\Types\Null_;

class AdminController extends AbstractController
{
Expand All @@ -42,7 +31,7 @@ class AdminController extends AbstractController
private $optionsRepository;
private $promoRepository;
private $halfDayAdjustmentRepository;
private $om;
private $manager;

public function __construct(
CheckInRepository $checkInRepository,
Expand All @@ -51,22 +40,26 @@ public function __construct(
OptionsRepository $optionsRepository,
PromoRepository $promoRepository,
HalfDayAdjustmentRepository $halfDayAdjustmentRepository,
ObjectManager $om
EntityManagerInterface $manager
) {
$this->checkInRepository=$checkInRepository;
$this->customerRepository=$customerRepository;
$this->subscriptionRepository=$subscriptionRepository;
$this->optionsRepository=$optionsRepository;
$this->promoRepository=$promoRepository;
$this->halfDayAdjustmentRepository=$halfDayAdjustmentRepository;
$this->om=$om;
$this->manager=$manager;
}

/**
* @Route("/admin/home", name="admin_home")
*/
public function adminHome()
{
($this->getUser())->setLastActivityAt(new DateTime());
$this->manager->persist($this->getUser());
$this->manager->flush();

return $this->render('admin/home.html.twig');
}

Expand Down Expand Up @@ -133,9 +126,9 @@ public function activate($id)
} else {
$customer->setActive(0);
}
$this->om->persist($customer);
$this->om->persist($promo);
$this->om->flush();
$this->manager->persist($customer);
$this->manager->persist($promo);
$this->manager->flush();

return $this->redirect($_SERVER['HTTP_REFERER']);
}
Expand Down Expand Up @@ -169,16 +162,16 @@ public function profile($id, Request $request)
$counter->handleRequest($request);

if ($counter->isSubmitted() && $counter->isValid()) {
$this->om->persist($promo);
$this->om->flush();
$this->manager->persist($promo);
$this->manager->flush();
};

$status = $this->createForm(CustomerSettingStatusType::class, $customer);
$status->handleRequest($request);

if ($status->isSubmitted() && $status->isValid()) {
$this->om->persist($customer);
$this->om->flush();
$this->manager->persist($customer);
$this->manager->flush();
}

return $this->render(
Expand Down Expand Up @@ -221,8 +214,8 @@ public function boom()
]
);
$raz = $subscriptions->setActive(0);
$this->om->persist($raz);
$this->om->flush();
$this->manager->persist($raz);
$this->manager->flush();
}

return $this->render('admin/raz.html.twig');
Expand All @@ -241,8 +234,8 @@ public function switch($id)
} else {
$switch = $customer->setRole('ROLE_USER');
}
$this->om->persist($switch);
$this->om->flush();
$this->manager->persist($switch);
$this->manager->flush();

return $this->redirect($_SERVER['HTTP_REFERER']);
}
Expand Down Expand Up @@ -279,8 +272,8 @@ public function text(Request $request)
$formtext->handleRequest($request);

if ($formtext->isSubmitted() && $formtext->isValid()) {
$this->om->persist($text);
$this->om->flush();
$this->manager->persist($text);
$this->manager->flush();

$this->addFlash(
'option',
Expand All @@ -292,8 +285,8 @@ public function text(Request $request)
$formplace->handleRequest($request);

if ($formplace->isSubmitted() && $formplace->isValid()) {
$this->om->persist($place);
$this->om->flush();
$this->manager->persist($place);
$this->manager->flush();

$this->addFlash(
'option',
Expand All @@ -305,8 +298,8 @@ public function text(Request $request)
$formhalfday->handleRequest($request);

if ($formhalfday->isSubmitted() && $formhalfday->isValid()) {
$this->om->persist($halfday);
$this->om->flush();
$this->manager->persist($halfday);
$this->manager->flush();

$this->addFlash(
'option',
Expand All @@ -318,8 +311,8 @@ public function text(Request $request)
$formmonth->handleRequest($request);

if ($formmonth->isSubmitted() && $formmonth->isValid()) {
$this->om->persist($month);
$this->om->flush();
$this->manager->persist($month);
$this->manager->flush();

$this->addFlash(
'option',
Expand Down Expand Up @@ -356,8 +349,8 @@ public function textActive()
} else {
$option->setActive(1);
}
$this->om->persist($option);
$this->om->flush();
$this->manager->persist($option);
$this->manager->flush();

return $this->redirect($_SERVER['HTTP_REFERER']);
}
Expand Down Expand Up @@ -417,10 +410,10 @@ public function price(OptionsRepository $optionsRepository, Request $request)
}
} elseif ($checkin->getHalfDay() == 0) {
if (!isset($days[$customer_id])) {
$days[$customer_id] = 0;
$days[$customer_id] = 0;
}
};
}

$days[$customer_id] -= $checkin->getFree();
if (isset($free[$customer_id])) {
$free[$customer_id] += $checkin->getFree();
Expand Down Expand Up @@ -468,7 +461,7 @@ public function price(OptionsRepository $optionsRepository, Request $request)
'label' => 'Month'
])->getContent();

// For the detailed display of the customer's checkins in the facturation table
// For the detailed display of the customer's checkins in the facturation table
$all_checkins = [];
foreach ($customers as $key => $customer) {
$user_checkins = $this->checkInRepository->findBy(
Expand Down Expand Up @@ -498,7 +491,7 @@ public function price(OptionsRepository $optionsRepository, Request $request)
$Mois_arrivee_num = $Arrivee->format('m');
$Annee_arrivee_num = $Arrivee->format('Y');
$Heure_arrivee = $Arrivee->format('H:i:s');

$Depart = $checkin->getLeaving();
if($Depart != null)
{
Expand All @@ -519,7 +512,7 @@ public function price(OptionsRepository $optionsRepository, Request $request)

$Demijournees = $checkin->getHalfDay();
$Demijournees_offertes = $checkin->getFree();

$Difference_depart_arrivee = $checkin->getDiff();
$tab[$line][] = [
'jour_arrivee_str' => $Jour_arrivee_str,
Expand Down Expand Up @@ -564,8 +557,8 @@ public function price(OptionsRepository $optionsRepository, Request $request)
$formHalfDayAdjustment->handleRequest($request);

if ($formHalfDayAdjustment->isSubmitted() && $formHalfDayAdjustment->isValid()) {
$this->om->persist($ajustement);
$this->om->flush();
$this->manager->persist($ajustement);
$this->manager->flush();
}

$all_adjustments = [];
Expand All @@ -576,7 +569,7 @@ public function price(OptionsRepository $optionsRepository, Request $request)
['id' => 'DESC']
);
};

return $this->render(
'admin/facturation.html.twig',
[
Expand Down
14 changes: 12 additions & 2 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use App\Repository\CustomerRepository;
use App\Repository\OptionsRepository;
use App\Service\Services;
use Doctrine\Common\Persistence\ObjectManager;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use function Sodium\add;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -29,6 +30,7 @@ class SecurityController extends AbstractController
private $utils;
private $adminMail = "[email protected]";
private $options;
private $manager;

/**
* SecurityController constructor.
Expand All @@ -37,10 +39,12 @@ class SecurityController extends AbstractController
*/
public function __construct(
AuthenticationUtils $utils,
OptionsRepository $options
OptionsRepository $options,
EntityManagerInterface $manager
) {
$this->utils = $utils;
$this->options = $options;
$this->manager = $manager;
}

/**
Expand Down Expand Up @@ -110,6 +114,10 @@ public function index(
);

if ($this->getUser()) {
($this->getUser())->setLastActivityAt(new DateTime());
$this->manager->persist($this->getUser());
$this->manager->flush();

if ($this->getUser()->getRole() == 'ROLE_USER') {
return $this->redirectToRoute('user_home');
} elseif ($this->getUser()->getRole() == 'ROLE_ADMIN') {
Expand Down Expand Up @@ -212,9 +220,11 @@ public function create(
$hash = $encoder->encodePassword($customer, $customer->getPassword());
if ($customerRepository->findAll()) {
$customer->setPassword($hash)
->setCreatedAt(new DateTime())
->setRole('ROLE_USER');
} else {
$customer->setPassword($hash)
->setCreatedAt(new DateTime())
->setRole('ROLE_ADMIN');
}

Expand Down
Loading

0 comments on commit f7847b4

Please sign in to comment.