jeudi 17 mars 2022

How do i use a checkbox from my Form Type file inside my Controller file?

I'm currently still learning PHP and Symfony bases, and I'm working on a project to allow employees of my company to use their leaves. I don't have people around to help with that (either not here, either "no time", either...).

So I will try to be as clear as my english allows me to :

In my Form file (CongeType.php, didn't chose the name, it was already created by the previous guy) I have that :

     ->add('morning', CheckboxType::class, [
         'label' => 'Matin',
         'mapped' => false,
         'required' => false
    ])
    ->add('afternoon', CheckboxType::class, [
        'label' => 'Après-midi',
        'mapped' => false,
        'required' => false
    ])

Which allow me to have two checkboxes "Morning" and "Afternoon" on my view (by the way, that project is using FullCalendar plugin, I don't know if it's relevant to say it so far).

If the user check "Morning" or "Afternoon" only half a day is took from it's leaves balance, instead of a full day. Well, that's the plan, but so far I'm not sure how to do it.

In my controller, I have that :

    $solde = $this->getUser()->getSoldeCp()->getCurrentYear();
    $conge = new Conge();
    $form = $this->createForm(CongeType::class, $conge);
    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $data = $form->getData();
        $daybreak = $cg->GetNbrJourConge($data->getDateDebut(),  $data->getDateFin()->modify('+ 1 day'), $this->getUser());

        /** @var User $user */
        $soldeCp = $this->getUser()->getSoldeCp()->getCurrentyear();
        $this->getUser()->getSoldeCp()->setCurrentyear($soldeCp - count($daybreak));

So I'm trying to create an other "if" that would divide by 2 the value of $daybreak if any of the "Morning" or "Afternoon" box is checked, but I don't know how to call those boxes inside my controller.

I'm not sure I'm very clear here, so don't hesitate to ask me more info.

Also, thanks for reading me !

(Project is on Symfony 5.3.9, and using JS FullCalendar plugin)




Aucun commentaire:

Enregistrer un commentaire