mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FEATURE [absence][in_progress] add absence property to user, create form, controller, template, migration and menu entry
This commit is contained in:
parent
99455ca685
commit
fb51e44e45
42
src/Bundle/ChillMainBundle/Controller/AbsenceController.php
Normal file
42
src/Bundle/ChillMainBundle/Controller/AbsenceController.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Form\AbsenceType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class AbsenceController extends AbstractController
|
||||
{
|
||||
public function setAbsence(Request $request)
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$form = $this->createForm(AbsenceType::class, $user);
|
||||
$form->add('submit', SubmitType::class, ['label' => 'Create']);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_main_homepage'));
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/Menu/absence.html.twig', [
|
||||
'user' => $user,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -11,14 +11,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
@ -40,6 +41,11 @@ class User implements AdvancedUserInterface
|
||||
*/
|
||||
protected ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime", nullable=true)
|
||||
*/
|
||||
private ?DateTimeImmutable $absenceStart = null;
|
||||
|
||||
/**
|
||||
* Array where SAML attributes's data are stored.
|
||||
*
|
||||
@ -175,6 +181,11 @@ class User implements AdvancedUserInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function getAbsenceStart(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->absenceStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes.
|
||||
*
|
||||
@ -295,6 +306,11 @@ class User implements AdvancedUserInterface
|
||||
return $this->usernameCanonical;
|
||||
}
|
||||
|
||||
public function isAbsent(): bool
|
||||
{
|
||||
return null !== $this->getAbsenceStart() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -359,6 +375,11 @@ class User implements AdvancedUserInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function setAbsenceStart(?DateTimeImmutable $absenceStart): void
|
||||
{
|
||||
$this->absenceStart = $absenceStart;
|
||||
}
|
||||
|
||||
public function setAttributeByDomain(string $domain, string $key, $value): self
|
||||
{
|
||||
$this->attributes[$domain][$key] = $value;
|
||||
|
36
src/Bundle/ChillMainBundle/Form/AbsenceType.php
Normal file
36
src/Bundle/ChillMainBundle/Form/AbsenceType.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Form\Type\ChillDateTimeType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AbsenceType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('absenceStart', ChillDateTimeType::class, [
|
||||
'required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => User::class,
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{% if user.absenceStart is not null %}
|
||||
|
||||
<p>Votre absence est indiqué à partier de {{ user.absenceStart|format_datetime() }}</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_row(form.absenceStart) }}
|
||||
{{ form_row(form.submit, { 'attr' : { 'class' : 'btn btn-chill-green' } } ) }}
|
||||
{{ form_end(form) }}
|
@ -78,6 +78,15 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
|
||||
$nbNotifications = $this->notificationByUserCounter->countUnreadByUser($user);
|
||||
|
||||
//TODO add an icon? How exactly? For example a clock icon...
|
||||
$menu
|
||||
->addChild($this->translator->trans('absence.Set absence date'), [
|
||||
'route' => 'chill_absence_user',
|
||||
])
|
||||
->setExtras([
|
||||
'order' => -8888888,
|
||||
]);
|
||||
|
||||
$menu
|
||||
->addChild(
|
||||
$this->translator->trans('notification.My notifications with counter', ['nb' => $nbNotifications]),
|
||||
|
@ -94,3 +94,7 @@ login_check:
|
||||
|
||||
logout:
|
||||
path: /logout
|
||||
|
||||
chill_absence_user:
|
||||
path: /{_locale}/absence
|
||||
controller: Chill\MainBundle\Controller\AbsenceController::setAbsence
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230111160610 extends AbstractMigration
|
||||
{
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE users DROP absenceStart');
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add absence property to user';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE users ADD absenceStart TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user