Merge remote-tracking branch 'origin/master' into rector/rules-symfony

# Conflicts:
#	src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivity.php
#	src/Bundle/ChillAsideActivityBundle/src/Export/Export/ListAsideActivity.php
This commit is contained in:
2023-09-12 15:21:15 +02:00
57 changed files with 1011 additions and 178 deletions

View File

@@ -30,6 +30,7 @@ final class AsideActivityController extends CRUDController
$asideActivity = new AsideActivity();
$asideActivity->setAgent($this->getUser());
$asideActivity->setLocation($this->getUser()->getCurrentLocation());
$duration = $request->query->get('duration', '300');
$duration = DateTime::createFromFormat('U', $duration);

View File

@@ -14,6 +14,7 @@ namespace Chill\AsideActivityBundle\Entity;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Location;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@@ -34,7 +35,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $createdAt = null;
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
@@ -45,7 +46,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $date = null;
private $date;
/**
* @ORM\Column(type="time", nullable=true)
@@ -60,25 +61,26 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
private ?int $id = null;
/**
* @ORM\Column(type="string", length=100, nullable=true)
* @ORM\ManyToOne(targetEntity=Location::class)
* @ORM\JoinColumn(nullable=true)
*/
private ?string $location = null;
private ?Location $location = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $note = null;
private $note;
/**
* @ORM\ManyToOne(targetEntity=AsideActivityCategory::class, inversedBy="asideActivities")
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\AsideActivityBundle\Entity\AsideActivityCategory $type = null;
private $type;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTimeInterface $updatedAt = null;
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
@@ -115,7 +117,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
return $this->id;
}
public function getLocation(): ?string
public function getLocation(): ?Location
{
return $this->location;
}
@@ -175,7 +177,7 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function setLocation(?string $location): self
public function setLocation(?Location $location): self
{
$this->location = $location;

View File

@@ -0,0 +1,100 @@
<?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\AsideActivityBundle\Export\Aggregator;
use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\LocationRepository;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class ByLocationAggregator implements AggregatorInterface
{
public function __construct(private LocationRepository $locationRepository)
{
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder): void
{
// no form
}
/**
* @inheritDoc
*/
public function getFormDefaultData(): array
{
return [];
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'export.aggregator.Aside activity localisation';
}
if (null === $value || '' === $value || null === $l = $this->locationRepository->find($value)) {
return '';
}
return $l->getName();
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['by_aside_activity_location_aggregator'];
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'export.aggregator.Group by aside activity location';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data): void
{
$qb->addSelect('IDENTITY(aside.location) AS by_aside_activity_location_aggregator')
->addGroupBy('by_aside_activity_location_aggregator');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ASIDE_ACTIVITY_TYPE;
}
}

View File

@@ -23,6 +23,7 @@ use Chill\MainBundle\Export\Helper\DateTimeHelper;
use Chill\MainBundle\Export\Helper\UserHelper;
use Chill\MainBundle\Export\ListInterface;
use Chill\MainBundle\Repository\CenterRepositoryInterface;
use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use DateTimeInterface;
@@ -32,23 +33,49 @@ use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
final readonly class ListAsideActivity implements ListInterface, GroupedExportInterface
final class ListAsideActivity implements ListInterface, GroupedExportInterface
{
private AsideActivityCategoryRepository $asideActivityCategoryRepository;
private CategoryRender $categoryRender;
private CenterRepositoryInterface $centerRepository;
private DateTimeHelper $dateTimeHelper;
private EntityManagerInterface $em;
private ScopeRepositoryInterface $scopeRepository;
private TranslatableStringHelperInterface $translatableStringHelper;
private UserHelper $userHelper;
public function __construct(
private EntityManagerInterface $em,
private DateTimeHelper $dateTimeHelper,
private UserHelper $userHelper,
private ScopeRepositoryInterface $scopeRepository,
private CenterRepositoryInterface $centerRepository,
private AsideActivityCategoryRepository $asideActivityCategoryRepository,
private CategoryRender $categoryRender,
private TranslatableStringHelperInterface $translatableStringHelper
EntityManagerInterface $em,
DateTimeHelper $dateTimeHelper,
UserHelper $userHelper,
ScopeRepositoryInterface $scopeRepository,
CenterRepositoryInterface $centerRepository,
AsideActivityCategoryRepository $asideActivityCategoryRepository,
CategoryRender $categoryRender,
private LocationRepository $locationRepository,
TranslatableStringHelperInterface $translatableStringHelper
) {
$this->em = $em;
$this->dateTimeHelper = $dateTimeHelper;
$this->userHelper = $userHelper;
$this->scopeRepository = $scopeRepository;
$this->centerRepository = $centerRepository;
$this->asideActivityCategoryRepository = $asideActivityCategoryRepository;
$this->categoryRender = $categoryRender;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder)
{
}
public function getFormDefaultData(): array
{
return [];
@@ -71,67 +98,99 @@ final readonly class ListAsideActivity implements ListInterface, GroupedExportIn
public function getLabels($key, array $values, $data)
{
return match ($key) {
'id', 'note' => static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.aside_activity.' . $key;
}
switch ($key) {
case 'id':
case 'note':
return static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.aside_activity.' . $key;
}
return $value ?? '';
},
'duration' => static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.aside_activity.' . $key;
}
return $value ?? '';
};
if (null === $value) {
return '';
}
case 'duration':
return static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.aside_activity.' . $key;
}
if ($value instanceof DateTimeInterface) {
return $value->format('H:i:s');
}
if (null === $value) {
return '';
}
return $value;
},
'createdAt', 'updatedAt', 'date' => $this->dateTimeHelper->getLabel('export.aside_activity.' . $key),
'agent_id', 'creator_id' => $this->userHelper->getLabel($key, $values, 'export.aside_activity.' . $key),
'aside_activity_type' => function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.aside_activity_type';
}
if ($value instanceof DateTimeInterface) {
return $value->format('H:i:s');
}
if (null === $value || '' === $value || null === $c = $this->asideActivityCategoryRepository->find($value)) {
return '';
}
return $value;
};
return $this->categoryRender->renderString($c, []);
},
'main_scope' => function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.main_scope';
}
case 'createdAt':
case 'updatedAt':
case 'date':
return $this->dateTimeHelper->getLabel('export.aside_activity.' . $key);
if (null === $value || '' === $value || null === $c = $this->scopeRepository->find($value)) {
return '';
}
case 'agent_id':
case 'creator_id':
return $this->userHelper->getLabel($key, $values, 'export.aside_activity.' . $key);
return $this->translatableStringHelper->localize($c->getName());
},
'main_center' => function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.main_center';
}
case 'aside_activity_type':
return function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.aside_activity_type';
}
if (null === $value || '' === $value || null === $c = $this->centerRepository->find($value)) {
/** @var Center $c */
return '';
}
if (null === $value || '' === $value || null === $c = $this->asideActivityCategoryRepository->find($value)) {
return '';
}
return $c->getName();
},
default => throw new LogicException('this key is not supported : ' . $key),
};
return $this->categoryRender->renderString($c, []);
};
case 'location':
return function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.location';
}
if (null === $value || '' === $value || null === $l = $this->locationRepository->find($value)) {
return '';
}
return $l->getName();
};
case 'main_scope':
return function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.main_scope';
}
if (null === $value || '' === $value || null === $c = $this->scopeRepository->find($value)) {
return '';
}
return $this->translatableStringHelper->localize($c->getName());
};
case 'main_center':
return function ($value) {
if ('_header' === $value) {
return 'export.aside_activity.main_center';
}
if (null === $value || '' === $value || null === $c = $this->centerRepository->find($value)) {
/** @var Center $c */
return '';
}
return $c->getName();
};
default:
throw new LogicException('this key is not supported : ' . $key);
}
}
public function getQueryKeys($data)
@@ -148,6 +207,7 @@ final readonly class ListAsideActivity implements ListInterface, GroupedExportIn
'date',
'duration',
'note',
'location',
];
}
@@ -183,6 +243,7 @@ final readonly class ListAsideActivity implements ListInterface, GroupedExportIn
->addSelect('IDENTITY(aside.type) AS aside_activity_type')
->addSelect('aside.date')
->addSelect('aside.duration')
->addSelect('IDENTITY(aside.location) AS location')
->addSelect('aside.note');
return $qb;

View File

@@ -0,0 +1,105 @@
<?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\AsideActivityBundle\Export\Filter;
use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserLocationType;
use Chill\MainBundle\Repository\LocationRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Security;
final readonly class ByLocationFilter implements FilterInterface
{
public function __construct(
private Security $security
) {
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'export.filter.Filter by aside activity location';
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder): void
{
$builder
->add('locations', PickUserLocationType::class);
}
/**
* @inheritDoc
*/
public function getFormDefaultData(): array
{
$user = $this->security->getUser();
if ($user instanceof User) {
return [
'locations' => $user->getCurrentLocation(),
];
}
return [
'locations' => null,
];
}
/**
* @inheritDoc
*/
public function describeAction($data, $format = 'string'): array
{
$locations = $data['locations']->map(fn (Location $l): string => $l->getName());
return ['export.filter.Filtered by aside activity location: only %location%', [
'%location%' => implode(', ', $locations),
]];
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data): void
{
$clause = $qb->expr()->in('aside.location', ':locations');
$qb->andWhere($clause);
$qb->setParameter('locations', $data['locations']);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ASIDE_ACTIVITY_TYPE;
}
}

View File

@@ -13,13 +13,16 @@ namespace Chill\AsideActivityBundle\Form;
use Chill\AsideActivityBundle\Entity\AsideActivity;
use Chill\AsideActivityBundle\Form\Type\PickAsideActivityCategoryType;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Form\Type\PickUserLocationType;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer;
@@ -77,7 +80,9 @@ final class AsideActivityFormType extends AbstractType
->add('note', ChillTextareaType::class, [
'label' => 'Note',
'required' => false,
]);
])
->add('location', PickUserLocationType::class)
;
foreach (['duration'] as $fieldName) {
$builder->get($fieldName)

View File

@@ -39,6 +39,9 @@
</span>
{% endif %}
</div>
{%- if entity.location.name is defined -%}
<div><i class="fa fa-fw fa-map-marker"></i>{{ entity.location.name }}</div>
{%- endif -%}
</div>
<div class="item-col" style="justify-content: flex-end;">
<div class="box">

View File

@@ -22,6 +22,13 @@
<dt class="inline">{{ 'Created for'|trans }}</dt>
<dd>{{ entity.agent }}</dd>
<dt class="inline">{{ 'Asideactivity location'|trans }}</dt>
{%- if entity.location.name is defined -%}
<dd>{{ entity.location.name }}</dd>
{%- else -%}
<dd><span class="chill-no-data-statement">{{ 'No data given'|trans }}</span></dd>
{%- endif -%}
<h2 class="chill-red">{{ 'Activity data'|trans }}</h2>

View File

@@ -46,19 +46,27 @@ services:
tags:
- { name: chill.export_filter, alias: 'aside_activity_user_filter' }
Chill\AsideActivityBundle\Export\Filter\ByLocationFilter:
tags:
- { name: chill.export_filter, alias: 'aside_activity_location_filter' }
## Aggregators
chill.aside_activity.export.type_aggregator:
class: Chill\AsideActivityBundle\Export\Aggregator\ByActivityTypeAggregator
tags:
- { name: chill.export_aggregator, alias: activity_type_aggregator }
- { name: chill.export_aggregator, alias: 'activity_type_aggregator' }
chill.aside_activity.export.user_job_aggregator:
class: Chill\AsideActivityBundle\Export\Aggregator\ByUserJobAggregator
tags:
- { name: chill.export_aggregator, alias: aside_activity_user_job_aggregator }
- { name: chill.export_aggregator, alias: 'aside_activity_user_job_aggregator' }
chill.aside_activity.export.user_scope_aggregator:
class: Chill\AsideActivityBundle\Export\Aggregator\ByUserScopeAggregator
tags:
- { name: chill.export_aggregator, alias: aside_activity_user_scope_aggregator }
- { name: chill.export_aggregator, alias: 'aside_activity_user_scope_aggregator' }
Chill\AsideActivityBundle\Export\Aggregator\ByLocationAggregator:
tags:
- { name: chill.export_aggregator, alias: 'aside_activity_location_aggregator' }

View File

@@ -0,0 +1,39 @@
<?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\AsideActivity;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20230816112809 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update location attribute in asideactivity';
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX chill_asideactivity.IDX_A866DA0E64D218E');
$this->addSql('ALTER TABLE chill_asideactivity.AsideActivity DROP CONSTRAINT FK_A866DA0E64D218E');
$this->addSql('ALTER TABLE chill_asideactivity.AsideActivity DROP location_id');
$this->addSql('ALTER TABLE chill_asideactivity.AsideActivity ADD location VARCHAR(100) DEFAULT NULL');
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_asideactivity.asideactivity ADD location_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_asideactivity.asideactivity DROP location');
$this->addSql('ALTER TABLE chill_asideactivity.asideactivity ADD CONSTRAINT FK_A866DA0E64D218E FOREIGN KEY (location_id) REFERENCES chill_main_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_A866DA0E64D218E ON chill_asideactivity.asideactivity (location_id)');
}
}

View File

@@ -26,6 +26,7 @@ Users: Utilisateurs
Emergency: Urgent
by: "Par "
location: Lieu
Asideactivity location: Localisation de l'activité
# Crud
crud:
@@ -182,6 +183,7 @@ export:
duration: Durée
note: Note
id: Identifiant
location: Localisation
Exports of aside activities: Exports des activités annexes
Count aside activities: Nombre d'activités annexes
@@ -202,11 +204,16 @@ export:
Filter by user jobs: Filtrer les activités annexes par métier des utilisateurs
'Filtered aside activities by user scope: only %scopes%': "Filtré par service des utilisateur: uniquement %scopes%"
Filter by user scope: Filtrer les activités annexes par service d'utilisateur
Filter by aside activity location: Filtrer les activités annexes par localisation
'Filtered by aside activity location: only %location%': "Filtré par localisation: uniquement %location%"
aggregator:
Group by aside activity type: Grouper les activités annexes par type d'activité
Aside activity type: Type d'activité annexe
Aggregate by user job: Grouper les activités annexes par métier des utilisateurs
Aggregate by user scope: Grouper les activités annexes par service des utilisateurs
Aside activity location: Localisation des activités annexe
Group by aside activity location: Grouper les activités annexes par localisation
Aside activity localisation: Localisation
# ROLES
CHILL_ASIDE_ACTIVITY_STATS: Statistiques pour les activités annexes