Compare commits

..

4 Commits

Author SHA1 Message Date
becf1f74aa remove var_dump 2021-07-22 17:16:48 +02:00
25ed89bdaf fix class name in test 2021-07-22 17:11:58 +02:00
cacc82bec8 fix showing flash messages 2021-07-22 16:56:12 +02:00
76e7f5b1ee allow age calculation on NULL birthdate and allow age to be null
+ improve translation of age
2021-07-20 23:50:31 +02:00
29 changed files with 169 additions and 484 deletions

View File

@@ -22,7 +22,6 @@ class LoadActivityNotifications extends AbstractFixture implements DependentFixt
'entityRef' => 'activity_gerard depardieu',
'sender' => 'center a_social',
'addressees' => [
'center a_social',
'center a_administrative',
'center a_direction',
'multi_center'

View File

@@ -1,24 +0,0 @@
<?php
namespace Chill\ActivityBundle\Notification;
use Chill\MainBundle\Entity\Notification;
use Chill\ActivityBundle\Entity\Activity;
final class ActivityNotificationRenderer
{
public function supports(Notification $notification, array $options = []): bool
{
return $notification->getRelatedEntityClass() == Activity::class;
}
public function getTemplate()
{
return '@ChillActivity/Activity/showInNotification.html.twig';
}
public function getTemplateData(Notification $notification)
{
return ['notification' => $notification];
}
}

View File

@@ -1,4 +0,0 @@
{{ dump(notification) }}
<a href="{{ path('chill_activity_activity_show', {'id': notification.relatedEntityId }) }}">Go to Activity</a>

View File

@@ -33,8 +33,3 @@ services:
autoconfigure: true
resource: '../Menu/'
tags: ['chill.menu_builder']
Chill\ActivityBundle\Notification\:
autowire: true
autoconfigure: true
resource: '../Notification'

View File

@@ -1,59 +0,0 @@
<?php
namespace Chill\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Notification\NotificationRenderer;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Routing\Annotation\Route;
use Chill\MainBundle\Pagination\PaginatorFactory;
/**
* @Route("/{_locale}/notification")
*/
class NotificationController extends AbstractController
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @Route("/show", name="chill_main_notification_show")
*/
public function showAction(
NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer,
PaginatorFactory $paginatorFactory)
{
$currentUser = $this->security->getUser();
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
$paginator = $paginatorFactory->create($notificationsNbr);
$notifications = $notificationRepository->findAllForAttendee(
$currentUser,
$limit=$paginator->getItemsPerPage(),
$offset= $paginator->getCurrentPage()->getFirstItemNumber());
$templateData = array();
foreach ($notifications as $notification) {
$data = [
'template' => $notificationRenderer->getTemplate($notification),
'template_data' => $notificationRenderer->getTemplateData($notification),
'notification' => $notification
];
$templateData[] = $data;
}
return $this->render('@ChillMain/Notification/show.html.twig', [
'datas' => $templateData,
'notifications' => $notifications,
'paginator' => $paginator,
]);
}
}

View File

@@ -1,44 +0,0 @@
<?php
namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Entity\Notification;
use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer;
use Chill\ActivityBundle\Notification\ActivityNotificationRenderer;
final class NotificationRenderer
{
private array $renderers;
public function __construct(
AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer,
ActivityNotificationRenderer $activityNotificationRenderer)
{
// TODO configure automatically
// TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK
$this->renderers[] = $accompanyingPeriodNotificationRenderer;
$this->renderers[] = $activityNotificationRenderer;
}
private function getRenderer(Notification $notification)
{
foreach ($this->renderers as $renderer) {
if($renderer->supports($notification)) {
return $renderer;
}
}
throw new \Exception('No renderer for '. $notification);
}
public function getTemplate(Notification $notification)
{
return $this->getRenderer($notification)->getTemplate();
}
public function getTemplateData(Notification $notification)
{
return $this->getRenderer($notification)->getTemplateData($notification);
}
}

View File

@@ -23,8 +23,6 @@ use Chill\MainBundle\Entity\Notification;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\Query;
final class NotificationRepository implements ObjectRepository
{
@@ -61,54 +59,8 @@ final class NotificationRepository implements ObjectRepository
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query
{
$qb = $this->repository->createQueryBuilder('n');
$select = 'n';
if($countQuery) {
$select = 'count(n)';
}
$qb
->select($select)
->join('n.addressees', 'a')
->where('a = :addressee')
->setParameter('addressee', $addressee);
return $qb->getQuery();
}
/**
* @return int
*/
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee, $countQuery=True);
return $query->getSingleScalarResult();
}
/**
* @return Notification[]
*/
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
{
$query = $this->queryAllForAttendee($addressee);
if($limit) {
$query = $query->setMaxResults($limit);
}
if($offset) {
$query = $query->setFirstResult($offset);
}
return $query->getResult();
}
public function getClassName() {
return Notification::class;
}
}

View File

@@ -1,42 +0,0 @@
{% extends "@ChillMain/layout.html.twig" %}
{% block content %}
<div id="container content">
<div class="grid-8 centered">
<h1>{{ "Notifications list" | trans }}</h1>
<!-- TODO : UNREAD & READ -->
{%for data in datas %}
{% set notification = data.notification %}
<dl class="chill_view_data">
<dt class="inline">{{ 'Message'|trans }}</dt>
<dd>{{ notification.message }}</dd>
</dl>
<dl class="chill_view_data">
<dt class="inline">{{ 'Date'|trans }}</dt>
<dd>{{ notification.date | date('long') }}</dd>
</dl>
<dl class="chill_view_data">
<dt class="inline">{{ 'Sender'|trans }}</dt>
<dd>{{ notification.sender }}</dd>
</dl>
<dl class="chill_view_data">
<dt class="inline">{{ 'Addressees'|trans }}</dt>
<dd>{{ notification.addressees |join(', ') }}</dd>
</dl>
<dl class="chill_view_data">
<dt class="inline">{{ 'Entity'|trans }}</dt>
<dd>
{% include data.template with data.template_data %}
</dd>
</dl>
{% endfor %}
</div>
</div>
{% endblock content %}

View File

@@ -172,6 +172,7 @@ abstract class AbstractExportTest extends WebTestCase
*/
public function testInitiateQuery($modifiers, $acl, $data)
{
var_dump($data);
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data);
$this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery,

View File

@@ -34,10 +34,6 @@ chill_password_recover:
resource: "@ChillMainBundle/config/routes/password_recover.yaml"
prefix: "public/{_locale}/password"
chill_main_notification:
resource: "@ChillMainBundle/config/routes/notification.yaml"
prefix: "{_locale}/notification"
chill_crud:
resource: "@ChillMainBundle"
type: CRUD

View File

@@ -33,8 +33,3 @@ services:
$logger: '@Psr\Log\LoggerInterface'
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
tags: ['controller.service_arguments']
Chill\MainBundle\Controller\NotificationController:
arguments:
$security: '@Symfony\Component\Security\Core\Security'
tags: ['controller.service_arguments']

View File

@@ -8,7 +8,3 @@ services:
$router: '@Symfony\Component\Routing\RouterInterface'
$translator: '@Symfony\Component\Translation\TranslatorInterface'
$routeParameters: '%chill_main.notifications%'
Chill\MainBundle\Notification\NotificationRenderer:
autoconfigure: true
autowire: true

View File

@@ -2,8 +2,6 @@ services:
chill_main.paginator_factory:
class: Chill\MainBundle\Pagination\PaginatorFactory
public: true
autowire: true
autoconfigure: true
arguments:
- "@request_stack"
- "@router"

View File

@@ -252,6 +252,18 @@ final class PersonController extends AbstractController
*/
$person = $form->getData();
$periods = $person->getAccompanyingPeriodsOrdered();
$period = $periods[0];
$period->setOpeningDate($form['creation_date']->getData());
// $person = new Person($form['creation_date']->getData());
//
// $person->setFirstName($form['firstName']->getData())
// ->setLastName($form['lastName']->getData())
// ->setGender($form['gender']->getData())
// ->setBirthdate($form['birthdate']->getData())
// ->setCenter($form['center']->getData())
// ;
return $person;
}
@@ -352,6 +364,7 @@ final class PersonController extends AbstractController
'lastName' => $form['lastName']->getData(),
'birthdate' => $form['birthdate']->getData(),
'gender' => $form['gender']->getData(),
'creation_date' => $form['creation_date']->getData(),
'form' => $form->createView()));
}

View File

@@ -1,39 +0,0 @@
<?php
namespace Chill\PersonBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
use Chill\PersonBundle\DataFixtures\ORM\LoadAccompanyingPeriod;
/**
* Load notififications into database
*/
class LoadAccompanyingPeriodNotifications extends AbstractFixture implements DependentFixtureInterface
{
use LoadAbstractNotificationsTrait;
public $notifs = [
[
'message' => 'Hello !',
'entityClass' => AccompanyingPeriod::class,
'entityRef' => LoadAccompanyingPeriod::ACCOMPANYING_PERIOD,
'sender' => 'center a_social',
'addressees' => [
'center a_social',
'center a_administrative',
'center a_direction',
'multi_center'
],
]
];
public function getDependencies()
{
return [
LoadAccompanyingPeriod::class,
];
}
}

View File

@@ -183,14 +183,6 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
private function addAPerson(array $person, ObjectManager $manager)
{
$p = new Person();
$p->addAccompanyingPeriod(
new AccompanyingPeriod(
(new \DateTime())
->sub(
new \DateInterval('P'.\random_int(0, 180).'D')
)
)
);
foreach ($person as $key => $value) {
switch ($key) {

View File

@@ -74,7 +74,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
$loader->load('services/form.yaml');
$loader->load('services/alt_names.yaml');
$loader->load('services/household.yaml');
$loader->load('services/notification.yaml');
// We can get rid of this file when the service 'chill.person.repository.person' is no more used.
// We should use the PersonRepository service instead of a custom service name.
$loader->load('services/repository.yaml');

View File

@@ -379,7 +379,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
private Collection $householdAddresses;
public function __construct()
/**
* Person constructor.
*
* @param \DateTime|null $opening
*/
public function __construct(\DateTime $opening = null)
{
$this->accompanyingPeriodParticipations = new ArrayCollection();
$this->spokenLanguages = new ArrayCollection();
@@ -388,6 +393,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
$this->otherPhoneNumbers = new ArrayCollection();
$this->householdParticipations = new ArrayCollection();
$this->householdAddresses = new ArrayCollection();
if ($opening === null) {
$opening = new \DateTime();
}
$this->open(new AccompanyingPeriod($opening));
$this->genderComment = new CommentEmbeddable();
$this->maritalStatusComment = new CommentEmbeddable();
}

View File

@@ -26,7 +26,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\MainBundle\Form\Type\ChillDateType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Chill\MainBundle\Form\Type\CenterType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
@@ -80,6 +80,9 @@ final class CreationPersonType extends AbstractType
'property_path' => 'birthdate'
))
->add('gender', HiddenType::class)
->add('creation_date', HiddenType::class, array(
'mapped' => false
))
->add('form_status', HiddenType::class, array(
'mapped' => false,
'data' => $options['form_status']
@@ -96,18 +99,25 @@ final class CreationPersonType extends AbstractType
$builder->get('birthdate')
->addModelTransformer($dateToStringTransformer);
$builder->get('creation_date')
->addModelTransformer($dateToStringTransformer);
$builder->get('center')
->addModelTransformer($this->centerTransformer);
} else {
$builder
->add('firstName')
->add('lastName')
->add('birthdate', ChillDateType::class, [
'required' => false,
])
->add('birthdate', DateType::class, array('required' => false,
'widget' => 'single_text', 'format' => 'dd-MM-yyyy'))
->add('gender', GenderType::class, array(
'required' => true, 'placeholder' => null
))
->add('creation_date', DateType::class, array(
'required' => true,
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
'mapped' => false,
'data' => new \DateTime()))
->add('form_status', HiddenType::class, array(
'data' => $options['form_status'],
'mapped' => false

View File

@@ -1,24 +0,0 @@
<?php
namespace Chill\PersonBundle\Notification;
use Chill\MainBundle\Entity\Notification;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
final class AccompanyingPeriodNotificationRenderer
{
public function supports(Notification $notification)
{
return $notification->getRelatedEntityClass() == AccompanyingPeriod::class;
}
public function getTemplate()
{
return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig';
}
public function getTemplateData(Notification $notification)
{
return ['notification' => $notification];
}
}

View File

@@ -1,3 +0,0 @@
<a href="{{ path('chill_person_accompanying_course_index', {'accompanying_period_id': notification.relatedEntityId }) }}">
Go to Acc. period.
</a>

View File

@@ -1,6 +1,7 @@
{#
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
* * This program is free software: you can redistribute it and/or modify
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
@@ -38,6 +39,8 @@
{{ form_row(form.gender, { 'label' : 'Gender'|trans }) }}
{{ form_row(form.creation_date, { 'label' : 'Creation date'|trans }) }}
{{ form_rest(form) }}
<button class="btn btn-create" type="submit" alt="add a person">

View File

@@ -71,15 +71,14 @@
<dd>{{ person|chill_entity_render_string }}</dd>
<dt>{{ 'Date of birth'|trans }}</dt>
{% if birthdate is empty %}
<dd>{{ 'Unknown date of birth'|trans }}</dd>
{% else %}
<dd>{{ birthdate|format_date('long') }}</dd>
{% endif %}
<dd>{{ birthdate|format_date('long')|default( 'Unknown date of birth'|trans ) }}</dd>
<dt>{{ 'Gender'|trans }}</dt>
<dd>{{ gender|trans }}</dd>
<dt>{{ 'Creation date'|trans }}</dt>
<dd>{{ creation_date|format_date('long') }}</dd>
{% if form.altNames is defined %}
{# mark as rendered #}
{{ form_widget(form.altNames) }}
@@ -87,13 +86,10 @@
</dl>
{{ form_rest(form) }}
<ul class="record_actions">
<li>
<button class="sc-button bt-create change-icon" type="submit"><i class="fa fa-check"></i> {{ 'Confirm the creation'|trans }}</button>
</li>
</ul>
<button class="btn btn-submit" type="submit"><i class="fa fa-check"></i> {{ 'Confirm the creation'|trans }}</button>
{{ form_end(form) }}
</div>
</div>
</div>
</div>

View File

@@ -529,9 +529,8 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
->find($id);
$periods = $person->getAccompanyingPeriods();
if(sizeof($periods) > 0) {
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
}
$nbGenerated++;
}
}

View File

@@ -93,6 +93,8 @@ class PersonControllerCreateTest extends WebTestCase
'The page contains a "gender" input');
$this->assertTrue($form->has(self::BIRTHDATE_INPUT),
'The page has a "date of birth" input');
$this->assertTrue($form->has(self::CREATEDATE_INPUT),
'The page contains a "creation date" input');
$genderType = $form->get(self::GENDER_INPUT);
$this->assertEquals('radio', $genderType->getType(),
@@ -105,6 +107,10 @@ class PersonControllerCreateTest extends WebTestCase
'gender has "femme" option');
$this->assertFalse($genderType->hasValue(), 'The gender input is not checked');
$today = new \DateTime();
$this->assertEquals($today->format('d-m-Y'), $form->get(self::CREATEDATE_INPUT)
->getValue(), 'The creation date input has the current date by default');
return $form;
}

View File

@@ -45,12 +45,11 @@ class PersonTest extends \PHPUnit\Framework\TestCase
public function testGetCurrentAccompanyingPeriod()
{
$d = new \DateTime('yesterday');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$p = new Person($d);
$period = $p->getCurrentAccompanyingPeriod();
$this->assertInstanceOf(AccompanyingPeriod::class, $period);
$this->assertInstanceOf('Chill\PersonBundle\Entity\AccompanyingPeriod', $period);
$this->assertTrue($period->isOpen());
$this->assertEquals($d, $period->getOpeningDate());
@@ -68,8 +67,7 @@ class PersonTest extends \PHPUnit\Framework\TestCase
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
{
$d = new \DateTime("2013/2/1");
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
@@ -95,8 +93,7 @@ class PersonTest extends \PHPUnit\Framework\TestCase
*/
public function testAccompanyingPeriodOrderSameDateOpening() {
$d = new \DateTime("2013/2/1");
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$p = new Person($d);
$g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
@@ -123,8 +120,7 @@ class PersonTest extends \PHPUnit\Framework\TestCase
*/
public function testDateCoveringWithCoveringAccompanyingPeriod() {
$d = new \DateTime("2013/2/1");
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
@@ -149,8 +145,7 @@ class PersonTest extends \PHPUnit\Framework\TestCase
*/
public function testNotOpenAFileReOpenedLater() {
$d = new \DateTime("2013/2/1");
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$p = new Person($d);
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);

View File

@@ -20,11 +20,9 @@
namespace Chill\PersonBundle\Tests\Timeline;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\SecurityBundle\Tests\Functional\WebTestCase;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\EntityManagerInterface;
use Chill\MainBundle\Test\PrepareClientTrait;
/**
* This class tests entries are shown for closing and opening
@@ -33,20 +31,22 @@ use Chill\MainBundle\Test\PrepareClientTrait;
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
class TimelineAccompanyingPeriodTest extends WebTestCase
class TimelineAccompanyingPeriodTest extends \Chill\PersonBundle\Tests\Controller\AccompanyingPeriodControllerTest
{
use PrepareClientTrait;
/**
* @dataProvider provideDataPersonWithAccompanyingPeriod
*/
public function testEntriesAreShown($personId)
public function testEntriesAreShown()
{
$client = $this->getClientAuthenticated();
$this->generatePeriods(array(
[
'openingDate' => '2014-01-01',
'closingDate' => '2014-12-31',
'closingMotive' => $this->getRandomClosingMotive()
]
));
$crawler = $client->request('GET', "/en/person/{$personId}/timeline");
$crawler = $this->client->request('GET', '/en/person/'
.$this->person->getId().'/timeline');
$this->assertTrue($client->getResponse()->isSuccessful(),
$this->assertTrue($this->client->getResponse()->isSuccessful(),
"the timeline page loads sucessfully");
$this->assertGreaterThan(0, $crawler->filter('.timeline div')->count(),
"the timeline page contains multiple div inside a .timeline element");
@@ -58,33 +58,4 @@ class TimelineAccompanyingPeriodTest extends WebTestCase
"the text 'Une période d'accompagnement a été fermée' is present");
}
public function provideDataPersonWithAccompanyingPeriod()
{
self::bootKernel();
$qb = self::$container->get(EntityManagerInterface::class)
->createQueryBuilder()
;
$personIds = $qb
->from(Person::class, 'p')
->join('p.accompanyingPeriodParticipations', 'part')
->join('part.accompanyingPeriod', 'period')
->join('p.center', 'center')
->select('p.id')
->where($qb->expr()->isNotNull('period.closingDate'))
->andWhere($qb->expr()->eq('center.name', ':center'))
->setParameter('center', 'Center A')
->setMaxResults(1000)
->getQuery()
->getResult()
;
\shuffle($personIds);
yield [ \array_pop($personIds)['id'] ];
yield [ \array_pop($personIds)['id'] ];
yield [ \array_pop($personIds)['id'] ];
}
}

View File

@@ -1,3 +0,0 @@
services:
Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer:
autowire: true