This commit is contained in:
Julien Fastré 2022-10-05 15:23:28 +02:00
parent 58b1778544
commit a967e1ed17
194 changed files with 1580 additions and 1386 deletions

View File

@ -13,7 +13,6 @@ namespace Chill\ActivityBundle\Export\Aggregator\ACPAggregators;
use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use DateTime;
use Doctrine\ORM\QueryBuilder;
use RuntimeException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -50,14 +49,17 @@ class DateAggregator implements AggregatorInterface
switch ($data['frequency']) {
case 'month':
$fmt = 'YYYY-MM';
break;
case 'week':
$fmt = 'YYYY-IW';
break;
case 'year':
$fmt = 'YYYY'; $order = 'DESC';
break; // order DESC does not works !
default:
@ -98,7 +100,6 @@ class DateAggregator implements AggregatorInterface
switch ($data['frequency']) {
case 'month':
case 'week':
//return $this->translator->trans('for week') .' '. $value ;

View File

@ -16,7 +16,6 @@ use Chill\ActivityBundle\Repository\ActivityTypeRepositoryInterface;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Closure;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;

View File

@ -25,8 +25,8 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function array_key_exists;
use function count;
use function in_array;
class ActivityReasonAggregator implements AggregatorInterface, ExportElementValidatedInterface
{

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
class AvgActivityDuration implements ExportInterface, GroupedExportInterface
@ -57,7 +58,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
public function getLabels($key, array $values, $data)
{
if ('export_avg_activity_duration' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
return static fn ($value) => '_header' === $value ? 'Average activities linked to an accompanying period duration' : $value;
@ -105,8 +106,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
return $qb;
}

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterface
@ -58,7 +59,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function getLabels($key, array $values, $data)
{
if ('export_avg_activity_visit_duration' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
return static fn ($value) => '_header' === $value ? 'Average activities linked to an accompanying period visit duration' : $value;
@ -95,8 +96,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
$qb
->join('activity.accompanyingPeriod', 'acp')
->select('AVG(activity.travelTime) as export_avg_activity_visit_duration')
->andWhere($qb->expr()->isNotNull('activity.travelTime'))
;
->andWhere($qb->expr()->isNotNull('activity.travelTime'));
$qb
->andWhere(
@ -107,8 +107,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
return $qb;
}

View File

@ -103,8 +103,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
$qb->select('COUNT(DISTINCT activity.id) as export_count_activity');

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
class SumActivityDuration implements ExportInterface, GroupedExportInterface
@ -58,7 +59,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
public function getLabels($key, array $values, $data)
{
if ('export_sum_activity_duration' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
return static fn ($value) => '_header' === $value ? 'Sum activities linked to an accompanying period duration' : $value;
@ -106,8 +107,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
return $qb;
}

View File

@ -23,6 +23,7 @@ use Chill\PersonBundle\Export\Declarations as PersonDeclarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
class SumActivityVisitDuration implements ExportInterface, GroupedExportInterface
@ -58,7 +59,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
public function getLabels($key, array $values, $data)
{
if ('export_sum_activity_visit_duration' !== $key) {
throw new \LogicException("the key {$key} is not used by this export");
throw new LogicException("the key {$key} is not used by this export");
}
return static fn ($value) => '_header' === $value ? 'Sum activities linked to an accompanying period visit duration' : $value;
@ -106,8 +107,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
return $qb;
}

View File

@ -87,8 +87,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface
$qb = $this->activityRepository
->createQueryBuilder('activity')
->join('activity.person', 'person')
->join('person.centerHistory', 'centerHistory')
;
->join('person.centerHistory', 'centerHistory');
$qb->select('COUNT(activity.id) as export_count_activity');

View File

@ -18,10 +18,10 @@ use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class ActivityTypeFilter implements FilterInterface
{

View File

@ -17,8 +17,6 @@ use Chill\ActivityBundle\Repository\ActivityTypeRepositoryInterface;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
@ -79,8 +77,8 @@ class ActivityTypeFilter implements ExportElementValidatedInterface, FilterInter
'multiple' => true,
'expanded' => false,
'attr' => [
'class' => 'select2'
]
'class' => 'select2',
],
]);
}

View File

@ -19,14 +19,13 @@ use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function array_key_exists;
use function count;
use function in_array;
class ActivityReasonFilter implements ExportElementValidatedInterface, FilterInterface
{

View File

@ -14,11 +14,8 @@ namespace Chill\ActivityBundle\Form\Type;
use Chill\ActivityBundle\Entity\ActivityType;
use Chill\ActivityBundle\Repository\ActivityTypeRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TranslatableActivityType extends AbstractType

View File

@ -12,11 +12,8 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Repository;
use Chill\ActivityBundle\Entity\ActivityType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use UnexpectedValueException;
final class ActivityTypeRepository implements ActivityTypeRepositoryInterface
{
@ -27,14 +24,6 @@ final class ActivityTypeRepository implements ActivityTypeRepositoryInterface
$this->repository = $em->getRepository(ActivityType::class);
}
/**
* @return array|ActivityType[]
*/
public function findAllActive(): array
{
return $this->findBy(['active' => true]);
}
public function find($id): ?ActivityType
{
return $this->repository->find($id);
@ -48,6 +37,14 @@ final class ActivityTypeRepository implements ActivityTypeRepositoryInterface
return $this->repository->findAll();
}
/**
* @return array|ActivityType[]
*/
public function findAllActive(): array
{
return $this->findBy(['active' => true]);
}
/**
* @return array|ActivityType[]
*/
@ -65,6 +62,4 @@ final class ActivityTypeRepository implements ActivityTypeRepositoryInterface
{
return ActivityType::class;
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\ActivityBundle\Repository;
use Chill\ActivityBundle\Entity\ActivityType;
@ -11,5 +20,4 @@ interface ActivityTypeRepositoryInterface extends ObjectRepository
* @return array|ActivityType[]
*/
public function findAllActive(): array;
}

View File

@ -49,16 +49,16 @@ class ActivityStatsVoter extends AbstractChillVoter implements ProvideRoleHierar
return $this->getAttributes();
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return $this->helper->voteOnAttribute($attribute, $subject, $token);
}
protected function supports($attribute, $subject)
{
return $this->helper->supports($attribute, $subject);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return $this->helper->voteOnAttribute($attribute, $subject, $token);
}
private function getAttributes()
{
return [self::STATS, self::LISTS];

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\BySocialActionAggregat
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class BySocialActionAggregatorTest extends AbstractAggregatorTest
{
private BySocialActionAggregator $aggregator;
@ -52,8 +56,7 @@ final class BySocialActionAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.socialActions', 'actsocialaction')
,
->join('activity.socialActions', 'actsocialaction'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\BySocialIssueAggregato
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class BySocialIssueAggregatorTest extends AbstractAggregatorTest
{
private BySocialIssueAggregator $aggregator;
@ -52,8 +56,7 @@ final class BySocialIssueAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.socialIssues', 'actsocialissue')
,
->join('activity.socialIssues', 'actsocialissue'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\ByThirdpartyAggregator
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class ByThirdpartyAggregatorTest extends AbstractAggregatorTest
{
private ByThirdpartyAggregator $aggregator;
@ -52,8 +56,7 @@ final class ByThirdpartyAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.thirdParties', 'acttparty')
,
->join('activity.thirdParties', 'acttparty'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\ByUserAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class ByUserAggregatorTest extends AbstractAggregatorTest
{
private ByUserAggregator $aggregator;
@ -52,8 +56,7 @@ final class ByUserAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.users', 'actusers')
,
->join('activity.users', 'actusers'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\DateAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class DateAggregatorTest extends AbstractAggregatorTest
{
private DateAggregator $aggregator;
@ -43,7 +47,7 @@ final class DateAggregatorTest extends AbstractAggregatorTest
],
[
'frequency' => 'year',
]
],
];
}
@ -59,8 +63,7 @@ final class DateAggregatorTest extends AbstractAggregatorTest
$em->createQueryBuilder()
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
,
->join('activity.accompanyingPeriod', 'acp'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\LocationTypeAggregator
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class LocationTypeAggregatorTest extends AbstractAggregatorTest
{
private LocationTypeAggregator $aggregator;
@ -52,8 +56,7 @@ final class LocationTypeAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.location', 'actloc')
,
->join('activity.location', 'actloc'),
];
}
}

View File

@ -16,6 +16,10 @@ use Chill\ActivityBundle\Export\Aggregator\ACPAggregators\UserScopeAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
* @coversNothing
*/
final class UserScopeAggregatorTest extends AbstractAggregatorTest
{
private UserScopeAggregator $aggregator;
@ -52,8 +56,7 @@ final class UserScopeAggregatorTest extends AbstractAggregatorTest
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.accompanyingPeriod', 'acp')
->join('activity.user', 'actuser')
,
->join('activity.user', 'actuser'),
];
}
}

View File

@ -11,12 +11,15 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Aggregator\PersonAggregators;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityReasonAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @internal
* @coversNothing
*/
final class ActivityReasonAggregatorTest extends AbstractAggregatorTest
{
use ProphecyTrait;

View File

@ -53,7 +53,7 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_activitytypes' => $a
'accepted_activitytypes' => $a,
];
}

View File

@ -51,7 +51,7 @@ final class BySocialActionFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_socialactions' => $a
'accepted_socialactions' => $a,
];
}

View File

@ -51,7 +51,7 @@ final class BySocialIssueFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_socialissues' => $a
'accepted_socialissues' => $a,
];
}
@ -70,8 +70,7 @@ final class BySocialIssueFilterTest extends AbstractFilterTest
$em->createQueryBuilder()
->select('count(activity.id)')
->from(Activity::class, 'activity')
->join('activity.socialIssues', 'actsocialissue')
,
->join('activity.socialIssues', 'actsocialissue'),
];
}
}

View File

@ -51,7 +51,7 @@ final class ByUserFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_users' => $a
'accepted_users' => $a,
];
}

View File

@ -51,7 +51,7 @@ final class LocationTypeFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_locationtype' => $a
'accepted_locationtype' => $a,
];
}

View File

@ -40,7 +40,7 @@ final class SentReceivedFilterTest extends AbstractFilterTest
{
return [
['accepted_sentreceived' => Activity::SENTRECEIVED_SENT],
['accepted_sentreceived' => Activity::SENTRECEIVED_RECEIVED ]
['accepted_sentreceived' => Activity::SENTRECEIVED_RECEIVED],
];
}

View File

@ -51,7 +51,7 @@ final class UserFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_users' => $a
'accepted_users' => $a,
];
}

View File

@ -51,7 +51,7 @@ final class UserScopeFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'accepted_userscope' => $a
'accepted_userscope' => $a,
];
}

View File

@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Tests\Export\Filter;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Export\Filter\ActivityDateFilter;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
/**
@ -40,9 +41,9 @@ final class ActivityDateFilterTest extends AbstractFilterTest
{
return [
[
'date_from' => \DateTime::createFromFormat('Y-m-d', '2020-01-01'),
'date_to' => \DateTime::createFromFormat('Y-m-d', '2021-01-01'),
]
'date_from' => DateTime::createFromFormat('Y-m-d', '2020-01-01'),
'date_to' => DateTime::createFromFormat('Y-m-d', '2021-01-01'),
],
];
}

View File

@ -51,7 +51,7 @@ final class ActivityTypeFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'types' => $a
'types' => $a,
];
}

View File

@ -51,7 +51,7 @@ final class ActivityReasonFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'reasons' => $a
'reasons' => $a,
];
}

View File

@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Export\Filter\PersonFilters\PersonHavingActivityBetweenDateFilter;
use Chill\MainBundle\Test\Export\AbstractFilterTest;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
/**
@ -51,9 +52,9 @@ final class PersonHavingActivityBetweenDateFilterTest extends AbstractFilterTest
foreach ($array as $a) {
$data[] = [
'date_from' => \DateTime::createFromFormat('Y-m-d', '2021-07-01'),
'date_to' => \DateTime::createFromFormat('Y-m-d', '2022-07-01'),
'reasons' => $a
'date_from' => DateTime::createFromFormat('Y-m-d', '2021-07-01'),
'date_to' => DateTime::createFromFormat('Y-m-d', '2022-07-01'),
'reasons' => $a,
];
}

View File

@ -70,14 +70,14 @@ class ConfigRepository
private function getCharges(bool $onlyActive = false): array
{
return $onlyActive ?
array_filter($this->charges, function ($el) { return $el['active']; })
array_filter($this->charges, static function ($el) { return $el['active']; })
: $this->charges;
}
private function getResources(bool $onlyActive = false): array
{
return $onlyActive ?
array_filter($this->resources, function ($el) { return $el['active']; })
array_filter($this->resources, static function ($el) { return $el['active']; })
: $this->resources;
}

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Templating\Entity\UserRender;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class AgentAggregator implements AggregatorInterface
{

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class CancelReasonAggregator implements AggregatorInterface
{

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class JobAggregator implements AggregatorInterface
{

View File

@ -17,7 +17,7 @@ use Chill\MainBundle\Repository\LocationRepository;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
use function in_array;
final class LocationAggregator implements AggregatorInterface
{

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class LocationTypeAggregator implements AggregatorInterface
{

View File

@ -16,7 +16,6 @@ use Chill\MainBundle\Export\AggregatorInterface;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Security\Core\Role\Role;
class MonthYearAggregator implements AggregatorInterface
{

View File

@ -18,6 +18,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Closure;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ScopeAggregator implements AggregatorInterface
{

View File

@ -20,6 +20,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function in_array;
class JobFilter implements FilterInterface
{

View File

@ -20,6 +20,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function in_array;
class ScopeFilter implements FilterInterface
{

View File

@ -445,7 +445,7 @@ class ExportController extends AbstractController
$this->logger->notice('[export] choices for an export unserialized', [
'key' => $key,
'rawData' => json_encode($rawData)
'rawData' => json_encode($rawData),
]);
$alias = $rawData['alias'];

View File

@ -33,6 +33,11 @@ class GeographicalUnit
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class, inversedBy="units")
*/
private ?GeographicalUnitLayer $layer;
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
*/
@ -43,21 +48,14 @@ class GeographicalUnit
*/
private string $unitRefId;
/**
* @ORM\ManyToOne(targetEntity=GeographicalUnitLayer::class, inversedBy="units")
*/
private ?GeographicalUnitLayer $layer;
public function getId(): ?int
{
return $this->id;
}
protected function setId(int $id): self
public function getLayer(): ?GeographicalUnitLayer
{
$this->id = $id;
return $this;
return $this->layer;
}
public function getUnitName(): ?string
@ -65,31 +63,10 @@ class GeographicalUnit
return $this->unitName;
}
/**
* @return GeographicalUnitLayer|null
*/
public function getLayer(): ?GeographicalUnitLayer
{
return $this->layer;
}
/**
* @param string $unitRefId
* @return GeographicalUnit
*/
public function setUnitRefId(string $unitRefId): GeographicalUnit
{
$this->unitRefId = $unitRefId;
return $this;
}
/**
* @param GeographicalUnitLayer|null $layer
* @return GeographicalUnit
*/
public function setLayer(?GeographicalUnitLayer $layer): GeographicalUnit
{
$this->layer = $layer;
return $this;
}
@ -99,4 +76,18 @@ class GeographicalUnit
return $this;
}
public function setUnitRefId(string $unitRefId): GeographicalUnit
{
$this->unitRefId = $unitRefId;
return $this;
}
protected function setId(int $id): self
{
$this->id = $id;
return $this;
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
@ -41,45 +50,30 @@ class GeographicalUnitLayer
$this->units = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return array
*/
public function getName(): array
{
return $this->name;
}
/**
* @param array $name
* @return GeographicalUnitLayer
*/
public function setName(array $name): GeographicalUnitLayer
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getRefId(): string
{
return $this->refId;
}
/**
* @return Collection
*/
public function getUnits(): Collection
{
return $this->units;
}
public function setName(array $name): GeographicalUnitLayer
{
$this->name = $name;
return $this;
}
}

View File

@ -13,7 +13,6 @@ namespace Chill\MainBundle\Export;
use Chill\MainBundle\Form\Type\Export\ExportType;
use Chill\MainBundle\Form\Type\Export\PickCenterType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
@ -265,16 +264,14 @@ class ExportManager
$this->handleAggregators($export, $query, $data[ExportType::AGGREGATOR_KEY], $centers);
$this->logger->notice('[export] will execute this qb in export', [
'dql' => $query->getDQL()
'dql' => $query->getDQL(),
]);
} else {
throw new UnexpectedValueException('The method `intiateQuery` should return '
. 'a `\\Doctrine\\ORM\\NativeQuery` or a `Doctrine\\ORM\\QueryBuilder` '
. 'object.');
}
$result = $export->getResult($query, $data[ExportType::EXPORT_KEY]);
if (!is_iterable($result)) {

View File

@ -14,9 +14,7 @@ namespace Chill\MainBundle\Form\Type\Export;
use Chill\MainBundle\Center\GroupingCenterInterface;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
@ -49,9 +47,6 @@ class PickCenterType extends AbstractType
*/
protected array $groupingCenters = [];
/**
* @var \Symfony\Component\Security\Core\User\UserInterface
*/
protected UserInterface $user;
public function __construct(

View File

@ -14,7 +14,6 @@ namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Center;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
final class CenterRepository implements CenterRepositoryInterface
{

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Center;
@ -8,7 +17,7 @@ use Doctrine\Persistence\ObjectRepository;
interface CenterRepositoryInterface extends ObjectRepository
{
/**
* Return all active centers
* Return all active centers.
*
* Note: this is a teaser: active will comes later on center entity
*

View File

@ -1,12 +1,19 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\GeographicalUnit;
use Chill\MainBundle\Entity\GeographicalUnitLayer;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use UnexpectedValueException;
final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLayerRepositoryInterface
{
@ -30,6 +37,15 @@ final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLaye
return $this->repository->findAll();
}
public function findAllHavingUnits(): array
{
$qb = $this->repository->createQueryBuilder('l');
return $qb->where($qb->expr()->gt('SIZE(l.units)', 0))
->getQuery()
->getResult();
}
/**
* @return array|GeographicalUnitLayer[]
*/
@ -47,13 +63,4 @@ final class GeographicalUnitLayerLayerRepository implements GeographicalUnitLaye
{
return GeographicalUnitLayer::class;
}
public function findAllHavingUnits(): array
{
$qb = $this->repository->createQueryBuilder('l');
return $qb->where($qb->expr()->gt('SIZE(l.units)', 0))
->getQuery()
->getResult();
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\GeographicalUnitLayer;

View File

@ -1,33 +1,39 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\GeographicalUnit;
use Chill\MainBundle\Entity\GeographicalUnitDTO;
use Chill\MainBundle\Entity\GeographicalUnitLayer;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
class GeographicalUnitRepository implements GeographicalUnitRepositoryInterface
{
private EntityRepository $repository;
private EntityManagerInterface $em;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $em)
{
$this->repository = $em->getRepository($this->getClassName());
$this->em = $em;
}
public function find($id): ?GeographicalUnit
{
return $this->repository->find($id);
}
/**
* Will return only partial object, where the @link{GeographicalUnit::geom} property is not loaded
* Will return only partial object, where the @see{GeographicalUnit::geom} property is not loaded.
*
* @return array|GeographicalUnit[]
*/

View File

@ -1,10 +1,18 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Doctrine\Persistence\ObjectRepository;
interface GeographicalUnitRepositoryInterface extends ObjectRepository
{
}

View File

@ -15,7 +15,6 @@ use Chill\MainBundle\Entity\Scope;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
final class ScopeRepository implements ScopeRepositoryInterface
{

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Scope;
@ -18,6 +27,9 @@ interface ScopeRepositoryInterface extends ObjectRepository
public function findAll(): array;
/**
* @param null|mixed $limit
* @param null|mixed $offset
*
* @return Scope[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array;

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

View File

@ -16,6 +16,7 @@ use Doctrine\DBAL\Statement;
use Exception;
use LogicException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use function array_key_exists;
use function count;
@ -159,8 +160,8 @@ final class AddressReferenceBaseImporter
try {
$affected = $statement->executeStatement(array_merge(...$this->waitingForInsert));
if ($affected === 0) {
throw new \RuntimeException('no row affected');
if (0 === $affected) {
throw new RuntimeException('no row affected');
}
} catch (Exception $e) {
// in some case, we can add debug code here

View File

@ -13,11 +13,10 @@ namespace Chill\MainBundle\Service\Import;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Statement;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Exception;
use LogicException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use function array_key_exists;
use function count;
@ -77,7 +76,7 @@ final class GeographicalUnitBaseImporter
string $unitName,
string $unitKey,
string $geomAsWKT,
int $srid = null
?int $srid = null
): void {
$this->initialize();
@ -87,7 +86,7 @@ final class GeographicalUnitBaseImporter
'unitName' => $unitName,
'unitKey' => $unitKey,
'geomAsWKT' => $geomAsWKT,
'srid' => $srid
'srid' => $srid,
];
if (100 <= count($this->waitingForInsert)) {
@ -138,8 +137,10 @@ final class GeographicalUnitBaseImporter
}
$statement = $this->cachingStatements[$forNumber];
try {
$i = 0;
foreach ($this->waitingForInsert as $insert) {
$statement->bindValue(++$i, $insert['layerKey'], Types::STRING);
$statement->bindValue(++$i, $insert['layerName'], Types::JSON);
@ -151,8 +152,8 @@ final class GeographicalUnitBaseImporter
$affected = $statement->executeStatement();
if ($affected === 0) {
throw new \RuntimeException('no row affected');
if (0 === $affected) {
throw new RuntimeException('no row affected');
}
} catch (Exception $e) {
throw $e;
@ -197,7 +198,8 @@ final class GeographicalUnitBaseImporter
FROM unique_layers
ON CONFLICT (refid)
DO UPDATE SET name=EXCLUDED.name
");
"
);
//1) Add new units
$this->logger->info(self::LOG_PREFIX . 'upsert new units');

View File

@ -25,6 +25,7 @@ use function is_string;
/**
* Helper which creates a set of test for aggregators.
*
* @internal
*/
abstract class AbstractAggregatorTest extends KernelTestCase
{

View File

@ -24,6 +24,7 @@ use function is_string;
/**
* Helper to test filters.
*
* @internal
*/
abstract class AbstractFilterTest extends KernelTestCase
{

View File

@ -18,6 +18,7 @@ namespace Chill\MainBundle\Test;
* and use tearDownTrait after usage.
*
* @codeCoverageIgnore
*
* @deprecated use @class{Prophecy\PhpUnit\ProphecyTrait} instead
*/
trait ProphecyTrait

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Services\Import;
use Chill\MainBundle\Entity\PostalCode;
@ -9,11 +18,18 @@ use Chill\MainBundle\Service\Import\AddressReferenceBaseImporter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class AddressReferenceBaseImporterTest extends KernelTestCase
/**
* @internal
* @coversNothing
*/
final class AddressReferenceBaseImporterTest extends KernelTestCase
{
private AddressReferenceBaseImporter $importer;
private AddressReferenceRepository $addressReferenceRepository;
private EntityManagerInterface $entityManager;
private AddressReferenceBaseImporter $importer;
private PostalCodeRepository $postalCodeRepository;
protected function setUp(): void
@ -54,7 +70,8 @@ class AddressReferenceBaseImporterTest extends KernelTestCase
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
$postalCode,
'Rue test abcc guessed');
'Rue test abcc guessed'
);
$this->assertCount(1, $addresses);
$this->assertEquals('Rue test abccc-guessed', $addresses[0]->getStreet());
@ -79,12 +96,11 @@ class AddressReferenceBaseImporterTest extends KernelTestCase
$addresses = $this->addressReferenceRepository->findByPostalCodePattern(
$postalCode,
'abcc guessed fixed');
'abcc guessed fixed'
);
$this->assertCount('1', $addresses);
$this->assertEquals('Rue test abccc guessed fixed', $addresses[0]->getStreet());
$this->assertEquals($previousAddressId, $addresses[0]->getId());
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Services\Import;
use Chill\MainBundle\Service\Import\GeographicalUnitBaseImporter;
@ -8,7 +17,11 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class GeographicalUnitBaseImporterTest extends KernelTestCase
/**
* @internal
* @coversNothing
*/
final class GeographicalUnitBaseImporterTest extends KernelTestCase
{
private Connection $connection;
@ -42,10 +55,10 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
$importer->finalize();
$unit = $this->connection->executeQuery("
$unit = $this->connection->executeQuery('
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
WHERE u.unitrefid = ?", ['layer_one']);
WHERE u.unitrefid = ?', ['layer_one']);
$results = $unit->fetchAssociative();
@ -71,10 +84,10 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
$importer->finalize();
$unit = $this->connection->executeQuery("
$unit = $this->connection->executeQuery('
SELECT unitname, unitrefid, cmgul.refid AS layerrefid, cmgul.name AS layername, ST_AsText(ST_snapToGrid(ST_Transform(u.geom, 3812), 1)) AS geom
FROM chill_main_geographical_unit u JOIN chill_main_geographical_unit_layer cmgul on u.layer_id = cmgul.id
WHERE u.unitrefid = ?", ['layer_one']);
WHERE u.unitrefid = ?', ['layer_one']);
$results = $unit->fetchAssociative();
@ -83,7 +96,5 @@ class GeographicalUnitBaseImporterTest extends KernelTestCase
$this->assertEquals(json_decode($results['layername'], true), ['fr' => 'Test Layer fixed']);
$this->assertEquals($results['layerrefid'], 'test');
$this->assertEquals($results['geom'], 'MULTIPOLYGON(((130 120,45 40,10 40,130 120)),((0 0,15 5,40 10,10 20,0 0)))');
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Services\Import;
use Chill\MainBundle\Repository\CountryRepository;
@ -8,16 +17,20 @@ use Chill\MainBundle\Service\Import\PostalCodeBaseImporter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class PostalCodeBaseImporterTest extends KernelTestCase
/**
* @internal
* @coversNothing
*/
final class PostalCodeBaseImporterTest extends KernelTestCase
{
private CountryRepository $countryRepository;
private EntityManagerInterface $entityManager;
private PostalCodeBaseImporter $importer;
private PostalCodeRepository $postalCodeRepository;
private CountryRepository $countryRepository;
protected function setUp(): void
{
parent::setUp();
@ -79,7 +92,4 @@ class PostalCodeBaseImporterTest extends KernelTestCase
$this->assertStringStartsWith('tested with adapted pattern', $postalCodes[0]->getName());
$this->assertEquals($previousId, $postalCodes[0]->getId());
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Tests\Workflow\EventSubscriber;
use Chill\MainBundle\Entity\Notification;
@ -14,16 +23,22 @@ use Prophecy\Argument;
use Prophecy\Call\Call;
use Prophecy\Exception\Prediction\FailedPredictionException;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionClass;
use stdClass;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
use Symfony\Component\Workflow\WorkflowInterface;
use function count;
class NotificationOnTransitionTest extends TestCase
/**
* @internal
* @coversNothing
*/
final class NotificationOnTransitionTest extends TestCase
{
use ProphecyTrait;
@ -36,11 +51,10 @@ class NotificationOnTransitionTest extends TestCase
$entityWorkflow = new EntityWorkflow();
$entityWorkflow
->setWorkflowName('workflow_name')
->setRelatedEntityClass(\stdClass::class)
->setRelatedEntityId(1)
;
->setRelatedEntityClass(stdClass::class)
->setRelatedEntityId(1);
// force an id to entityWorkflow:
$reflection = new \ReflectionClass($entityWorkflow);
$reflection = new ReflectionClass($entityWorkflow);
$id = $reflection->getProperty('id');
$id->setAccessible(true);
$id->setValue($entityWorkflow, 1);
@ -48,12 +62,11 @@ class NotificationOnTransitionTest extends TestCase
$step = new EntityWorkflowStep();
$entityWorkflow->addStep($step);
$step->addDestUser($dest)
->setCurrentStep('to_state')
;
->setCurrentStep('to_state');
$em = $this->prophesize(EntityManagerInterface::class);
$em->persist(Argument::type(Notification::class))->should(
function($args) use ($dest) {
static function ($args) use ($dest) {
/** @var Call[] $args */
if (1 !== count($args)) {
throw new FailedPredictionException('no notification sent');
@ -68,7 +81,8 @@ class NotificationOnTransitionTest extends TestCase
if (!$notification->getAddressees()->contains($dest)) {
throw new FailedPredictionException('the dest is not notified');
}
});
}
);
$engine = $this->prophesize(EngineInterface::class);
$engine->render(Argument::type('string'), Argument::type('array'))

View File

@ -41,6 +41,24 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
$this->userRender = $userRender;
}
public function addDests(Event $event): void
{
if (!$event->getSubject() instanceof EntityWorkflow) {
return;
}
/** @var EntityWorkflow $entityWorkflow */
$entityWorkflow = $event->getSubject();
foreach ($entityWorkflow->futureDestUsers as $user) {
$entityWorkflow->getCurrentStep()->addDestUser($user);
}
foreach ($entityWorkflow->futureDestEmails as $email) {
$entityWorkflow->getCurrentStep()->addDestEmail($email);
}
}
public static function getSubscribedEvents(): array
{
return [
@ -55,23 +73,6 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
];
}
public function addDests(Event $event): void
{
if (!$event->getSubject() instanceof EntityWorkflow) {
return;
}
/** @var EntityWorkflow $entityWorkflow */
$entityWorkflow = $event->getSubject();
foreach ($entityWorkflow->futureDestUsers as $user) {
$entityWorkflow->getCurrentStep()->addDestUser($user);
}
foreach ($entityWorkflow->futureDestEmails as $email) {
$entityWorkflow->getCurrentStep()->addDestEmail($email);
}
}
public function guardEntityWorkflow(GuardEvent $event)
{
if (!$event->getSubject() instanceof EntityWorkflow) {

View File

@ -57,14 +57,15 @@ class NotificationOnTransition implements EventSubscriberInterface
}
/**
* Send a notification to:
* Send a notification to:.
*
* * the dests of the new step;
* * the users which subscribed to workflow, on each step, or on final
*
* **Warning** take care that this method must be executed **after** the dest users are added to
* the step (@link{EntityWorkflowStep::addDestUser}). Currently, this is done during
* @link{EntityWorkflowTransitionEventSubscriber::addDests}.
* the step (@see{EntityWorkflowStep::addDestUser}). Currently, this is done during
*
* @see{EntityWorkflowTransitionEventSubscriber::addDests}.
*/
public function onCompletedSendNotification(Event $event): void
{
@ -77,6 +78,7 @@ class NotificationOnTransition implements EventSubscriberInterface
/** @var array<string, User> $dests array of unique values, where keys is the object's hash */
$dests = [];
foreach (array_merge(
// the subscriber to each step
$entityWorkflow->getSubscriberToStep()->toArray(),

View File

@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
@ -9,6 +16,11 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20220730204216 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX chill_main_address_reference_unicity');
}
public function getDescription(): string
{
return 'Add an unique constraint on addresses references';
@ -18,9 +30,4 @@ final class Version20220730204216 extends AbstractMigration
{
$this->addSql('CREATE UNIQUE INDEX chill_main_address_reference_unicity ON chill_main_address_reference (refId, source)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX chill_main_address_reference_unicity');
}
}

View File

@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
@ -12,6 +19,11 @@ use Doctrine\Migrations\AbstractMigration;
*/
final class Version20220913174922 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE TEXT');
}
public function getDescription(): string
{
return 'Geographical Unit correction';
@ -21,9 +33,4 @@ final class Version20220913174922 extends AbstractMigration
{
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE GEOMETRY(MULTIPOLYGON, 4326)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER COLUMN geom SET DATA TYPE TEXT');
}
}

View File

@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
@ -9,6 +16,24 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20221003112151 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
/* for memory
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP CONSTRAINT FK_360A2B2FEA6EFDCD');
$this->addSql('DROP SEQUENCE chill_main_geographical_unit_layer_id_seq CASCADE');
$this->addSql('DROP TABLE chill_main_geographical_unit_layer');
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD layername VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP layer_id');
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP unitRefId');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER geom TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP DEFAULT');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP NOT NULL');
*/
}
public function getDescription(): string
{
return 'Add a proper entity for GeographicalUnitLayer';
@ -35,24 +60,5 @@ final class Version20221003112151 extends AbstractMigration
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitname SET NOT NULL');
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD CONSTRAINT FK_360A2B2FEA6EFDCD FOREIGN KEY (layer_id) REFERENCES chill_main_geographical_unit_layer (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_360A2B2FEA6EFDCD ON chill_main_geographical_unit (layer_id)');
}
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
/* for memory
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP CONSTRAINT FK_360A2B2FEA6EFDCD');
$this->addSql('DROP SEQUENCE chill_main_geographical_unit_layer_id_seq CASCADE');
$this->addSql('DROP TABLE chill_main_geographical_unit_layer');
$this->addSql('ALTER TABLE chill_main_geographical_unit ADD layername VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP layer_id');
$this->addSql('ALTER TABLE chill_main_geographical_unit DROP unitRefId');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER geom TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP DEFAULT');
$this->addSql('ALTER TABLE chill_main_geographical_unit ALTER unitName DROP NOT NULL');
*/
}
}

View File

@ -1,5 +1,12 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\Migrations\Main;
@ -9,6 +16,13 @@ use Doctrine\Migrations\AbstractMigration;
final class Version20221003132620 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX geographical_unit_layer_refid');
$this->addSql('DROP INDEX geographical_unit_refid');
$this->addSql('DROP INDEX chill_internal_geographical_unit_layer_geom_idx');
}
public function getDescription(): string
{
return 'Create indexes and unique constraints on geographical unit entities';
@ -20,11 +34,4 @@ final class Version20221003132620 extends AbstractMigration
$this->addSql('CREATE UNIQUE INDEX geographical_unit_refid ON chill_main_geographical_unit (layer_id, unitRefId)');
$this->addSql('CREATE INDEX chill_internal_geographical_unit_layer_geom_idx ON chill_main_geographical_unit USING GIST (layer_id, geom)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX geographical_unit_layer_refid');
$this->addSql('DROP INDEX geographical_unit_refid');
$this->addSql('DROP INDEX chill_internal_geographical_unit_layer_geom_idx');
}
}

View File

@ -46,6 +46,7 @@ use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use UnexpectedValueException;
use function count;
use function in_array;
@ -182,21 +183,23 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's center.
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Center")
*
* @deprecated
*/
private ?Center $center = null;
/**
* @ORM\OneToMany(targetEntity=PersonCenterHistory::class, mappedBy="person", cascade={"persist"})
* @var Collection|PersonCenterHistory[]
*/
private Collection $centerHistory;
/**
* @ORM\OneToOne(targetEntity=PersonCenterCurrent::class, mappedBy="person")
*/
private ?PersonCenterCurrent $centerCurrent = null;
/**
* @ORM\OneToMany(targetEntity=PersonCenterHistory::class, mappedBy="person", cascade={"persist"})
*
* @var Collection|PersonCenterHistory[]
*/
private Collection $centerHistory;
/**
* Array where customfield's data are stored.
*
@ -910,32 +913,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this->budgetResources;
}
private function getCurrentCenterHistory(): ?PersonCenterHistory
{
if (0 === $this->centerHistory->count()) {
return null;
}
$criteria = Criteria::create();
$now = new DateTimeImmutable('now');
$criteria->where(Criteria::expr()->lte('startDate', $now))
->andWhere(Criteria::expr()->orX(
Criteria::expr()->isNull('endDate'),
Criteria::expr()->gt('endDate', $now)
));
$histories = $this->centerHistory->matching($criteria);
switch ($histories->count()) {
case 0:
return null;
case 1:
return $histories->first();
default:
throw new \UnexpectedValueException('It should not contains more than one center at a time');
}
}
public function getCenter(): ?Center
{
if (null !== $this->centerCurrent) {
@ -949,6 +926,24 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $currentCenterHistory->getCenter();
}
public function getCenterCurrent(): ?PersonCenterCurrent
{
if (null !== $this->centerCurrent) {
return $this->centerCurrent;
}
if (null === $currentCenterHistory = $this->getCurrentCenterHistory()) {
return null;
}
return new PersonCenterCurrent($currentCenterHistory);
}
public function getCenterHistory(): Collection
{
return $this->centerHistory;
}
public function getCFData(): ?array
{
if (null === $this->cFData) {
@ -1562,7 +1557,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Associate the center with the person. The association start on 'now'.
*
* @param Center $center
* @return $this
*/
public function setCenter(Center $center): self
@ -1582,40 +1576,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
/**
* @return Collection
*/
public function getCenterHistory(): Collection
{
return $this->centerHistory;
}
/**
* @param Collection $centerHistory
* @return Person
*/
public function setCenterHistory(Collection $centerHistory): Person
{
$this->centerHistory = $centerHistory;
return $this;
}
/**
* @return PersonCenterCurrent|null
*/
public function getCenterCurrent(): ?PersonCenterCurrent
{
if (null !== $this->centerCurrent) {
return $this->centerCurrent;
}
if (null === $currentCenterHistory = $this->getCurrentCenterHistory()) {
return null;
}
return new PersonCenterCurrent($currentCenterHistory);
}
/**
* @return Person
*/
@ -1818,6 +1785,34 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
private function getCurrentCenterHistory(): ?PersonCenterHistory
{
if (0 === $this->centerHistory->count()) {
return null;
}
$criteria = Criteria::create();
$now = new DateTimeImmutable('now');
$criteria->where(Criteria::expr()->lte('startDate', $now))
->andWhere(Criteria::expr()->orX(
Criteria::expr()->isNull('endDate'),
Criteria::expr()->gt('endDate', $now)
));
$histories = $this->centerHistory->matching($criteria);
switch ($histories->count()) {
case 0:
return null;
case 1:
return $histories->first();
default:
throw new UnexpectedValueException('It should not contains more than one center at a time');
}
}
/**
* This private function scan accompanyingPeriodParticipations Collection,
* searching for a given AccompanyingPeriod.

View File

@ -1,15 +1,19 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use DateTimeInterface;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
@ -24,6 +28,16 @@ use Doctrine\ORM\Mapping as ORM;
*/
class PersonCenterCurrent
{
/**
* @ORM\ManyToOne(targetEntity=Center::class)
*/
private Center $center;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
/**
* @ORM\Id
* @ORM\Column(type="integer")
@ -35,20 +49,10 @@ class PersonCenterCurrent
*/
private Person $person;
/**
* @ORM\ManyToOne(targetEntity=Center::class)
*/
private Center $center;
/**
* @ORM\Column(type="date_immutable", nullable=false)
*/
private \DateTimeImmutable $startDate;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?\DateTimeImmutable $endDate = null;
private DateTimeImmutable $startDate;
/**
* Populate the properties person, center, start and end date from history.
@ -56,7 +60,6 @@ class PersonCenterCurrent
* The creator and updatedby are not filled.
*
* @internal Should not be instantied, unless inside Person entity
* @param PersonCenterHistory $history
*/
public function __construct(PersonCenterHistory $history)
{
@ -67,46 +70,31 @@ class PersonCenterCurrent
$this->id = $history->getId();
}
public function getCenter(): Center
{
return $this->center;
}
public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
/**
* The id will be the same as the current @link{PersonCenterHistory::class}
*
* @return int
* The id will be the same as the current @see{PersonCenterHistory::class}.
*/
public function getId(): int
{
return $this->id;
}
/**
* @return Person
*/
public function getPerson(): Person
{
return $this->person;
}
/**
* @return Center
*/
public function getCenter(): Center
{
return $this->center;
}
/**
* @return \DateTimeImmutable
*/
public function getStartDate(): \DateTimeImmutable
public function getStartDate(): DateTimeImmutable
{
return $this->startDate;
}
/**
* @return \DateTimeImmutable|null
*/
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
@ -8,10 +17,11 @@ use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* Associate a Person with a Center. The association may change on date intervals
* Associate a Person with a Center. The association may change on date intervals.
*
* @ORM\Entity
* @ORM\Table(name="chill_person_person_center_history")
@ -19,8 +29,19 @@ use Doctrine\ORM\Mapping as ORM;
class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterface
{
use TrackCreationTrait;
use TrackUpdateTrait;
/**
* @ORM\ManyToOne(targetEntity=Center::class)
*/
private ?Center $center = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?DateTimeImmutable $endDate = null;
/**
* @ORM\Id
* @ORM\GeneratedValue
@ -33,71 +54,43 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
*/
private ?Person $person = null;
/**
* @ORM\ManyToOne(targetEntity=Center::class)
*/
private ?Center $center = null;
/**
* @ORM\Column(type="date_immutable", nullable=false)
*/
private ?\DateTimeImmutable $startDate = null;
private ?DateTimeImmutable $startDate = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*/
private ?\DateTimeImmutable $endDate = null;
/**
* @param Person|null $person
* @param Center|null $center
* @param \DateTimeImmutable|null $startDate
*/
public function __construct(?Person $person = null, ?Center $center = null, ?\DateTimeImmutable $startDate = null)
public function __construct(?Person $person = null, ?Center $center = null, ?DateTimeImmutable $startDate = null)
{
$this->person = $person;
$this->center = $center;
$this->startDate = $startDate;
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return Person|null
*/
public function getPerson(): ?Person
{
return $this->person;
}
/**
* @param Person|null $person
*/
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
/**
* @return Center|null
*/
public function getCenter(): ?Center
{
return $this->center;
}
/**
* @param Center|null $center
*/
public function getEndDate(): ?DateTimeImmutable
{
return $this->endDate;
}
public function getId(): ?int
{
return $this->id;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function getStartDate(): ?DateTimeImmutable
{
return $this->startDate;
}
public function setCenter(?Center $center): self
{
$this->center = $center;
@ -105,38 +98,24 @@ class PersonCenterHistory implements TrackCreationInterface, TrackUpdateInterfac
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
/**
* @param \DateTimeImmutable|null $startDate
*/
public function setStartDate(?\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
/**
* @param \DateTimeImmutable|null $endDate
*/
public function setEndDate(?\DateTimeImmutable $endDate): self
public function setEndDate(?DateTimeImmutable $endDate): self
{
$this->endDate = $endDate;
return $this;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;
return $this;
}
}

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class AdministrativeLocationAggregator implements AggregatorInterface
{

View File

@ -13,11 +13,8 @@ namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepositoryInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@ -63,7 +60,7 @@ class ClosingMotiveAggregator implements AggregatorInterface
return 'Closing motive';
}
if (NULL === $value) {
if (null === $value) {
return '';
}

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Entity\Address;
@ -11,12 +20,13 @@ use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use DateTimeImmutable;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use UnexpectedValueException;
use function in_array;
final class GeographicalUnitStatAggregator implements AggregatorInterface
{
@ -32,91 +42,11 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
switch ($key) {
case 'acp_geog_agg_unitname':
return function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitname';
}
if (null === $value) {
return '';
}
return $value;
};
case 'acp_geog_agg_unitrefid':
return function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitrefid';
}
if (null === $value) {
return '';
}
return $value;
};
default:
throw new \UnexpectedValueException('this value should not happens');
}
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['acp_geog_agg_unitname', 'acp_geog_agg_unitrefid'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date_calc', ChillDateType::class, [
'label' => 'Compute geographical location at date',
'required' => true,
'data' => new \DateTimeImmutable('today'),
'input' => 'datetime_immutable',
])
->add('level', EntityType::class, [
'label' => 'Geographical layer',
'placeholder' => 'Select a geographical layer',
'class' => GeographicalUnitLayer::class,
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
'choice_label' => function(GeographicalUnitLayer $item) {
return $this->translatableStringHelper->localize($item->getName());
},
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by geographical unit';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('acp_geog_agg_location_history', $qb->getAllAliases(), true)) {
@ -181,15 +111,75 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
->addSelect('acp_geog_units.unitName AS acp_geog_agg_unitname')
->addSelect('acp_geog_units.unitRefId AS acp_geog_agg_unitrefid')
->addGroupBy('acp_geog_agg_unitname')
->addGroupBy('acp_geog_agg_unitrefid')
;
->addGroupBy('acp_geog_agg_unitrefid');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date_calc', ChillDateType::class, [
'label' => 'Compute geographical location at date',
'required' => true,
'data' => new DateTimeImmutable('today'),
'input' => 'datetime_immutable',
])
->add('level', EntityType::class, [
'label' => 'Geographical layer',
'placeholder' => 'Select a geographical layer',
'class' => GeographicalUnitLayer::class,
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
'choice_label' => function (GeographicalUnitLayer $item) {
return $this->translatableStringHelper->localize($item->getName());
},
]);
}
public function getLabels($key, array $values, $data)
{
switch ($key) {
case 'acp_geog_agg_unitname':
return static function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitname';
}
if (null === $value) {
return '';
}
return $value;
};
case 'acp_geog_agg_unitrefid':
return static function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitrefid';
}
if (null === $value) {
return '';
}
return $value;
};
default:
throw new UnexpectedValueException('this value should not happens');
}
}
public function getQueryKeys($data): array
{
return ['acp_geog_agg_unitname', 'acp_geog_agg_unitrefid'];
}
public function getTitle(): string
{
return 'Group by geographical unit';
}
}

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class JobAggregator implements AggregatorInterface
{

View File

@ -19,6 +19,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class OriginAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ReferrerAggregator implements AggregatorInterface
{

View File

@ -1,25 +1,34 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Repository\ScopeRepository;
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
class ReferrerScopeAggregator implements AggregatorInterface
{
private const SCOPE_KEY = 'acp_agg_refscope_user_history_ref_scope_name';
private TranslatableStringHelperInterface $translatableStringHelper;
private ScopeRepositoryInterface $scopeRepository;
private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct(
ScopeRepositoryInterface $scopeRepository,
TranslatableStringHelperInterface $translatableStringHelper
@ -28,70 +37,11 @@ class ReferrerScopeAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value) {
if ('_header' === $value) {
return 'export.aggregator.course.by_user_scope.Referrer\'s scope';
}
if (null === $value) {
return '';
}
$scope = $this->scopeRepository->find($value);
if (null === $scope) {
throw new \LogicException('no scope found with this id: ' . $value);
}
return $this->translatableStringHelper->localize($scope->getName());
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data)
{
return [self::SCOPE_KEY];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('date_calc', ChillDateType::class, [
'input' => 'datetime_immutable',
'data' => new \DateTimeImmutable('now'),
'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer',
'required' => true,
]);
}
/**
* @inheritDoc
*/
public function getTitle()
{
return 'export.aggregator.course.by_user_scope.Group course by referrer\'s scope';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$userHistory = 'acp_agg_refscope_user_history';
@ -119,15 +69,52 @@ class ReferrerScopeAggregator implements AggregatorInterface
// add groups
$qb
->addSelect('IDENTITY(' . $ref . '.mainScope) AS ' . $scopeName)
->addGroupBy($scopeName)
;
->addGroupBy($scopeName);
}
/**
* @inheritDoc
*/
public function applyOn()
{
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('date_calc', ChillDateType::class, [
'input' => 'datetime_immutable',
'data' => new DateTimeImmutable('now'),
'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer',
'required' => true,
]);
}
public function getLabels($key, array $values, $data)
{
return function ($value) {
if ('_header' === $value) {
return 'export.aggregator.course.by_user_scope.Referrer\'s scope';
}
if (null === $value) {
return '';
}
$scope = $this->scopeRepository->find($value);
if (null === $scope) {
throw new LogicException('no scope found with this id: ' . $value);
}
return $this->translatableStringHelper->localize($scope->getName());
};
}
public function getQueryKeys($data)
{
return [self::SCOPE_KEY];
}
public function getTitle()
{
return 'export.aggregator.course.by_user_scope.Group course by referrer\'s scope';
}
}

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ScopeAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class SocialIssueAggregator implements AggregatorInterface
{

View File

@ -17,7 +17,6 @@ use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -73,7 +72,7 @@ class ChildrenNumberAggregator implements AggregatorInterface
public function getLabels($key, array $values, $data)
{
return function ($value): string {
return static function ($value): string {
if ('_header' === $value) {
return 'Number of children';
}

View File

@ -19,7 +19,6 @@ use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Entity\GeographicalUnit;
@ -9,8 +18,10 @@ use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
@ -28,93 +39,11 @@ class GeographicalUnitAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
switch ($key) {
case 'geog_unit_name':
return function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitname';
}
if (null === $value) {
return '';
}
return $value;
};
case 'geog_unit_key':
return function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitrefid';
}
if (null === $value) {
return '';
}
return $value;
};
default:
throw new \LogicException('key not supported');
}
}
/**
* @inheritDoc
*/
public function getQueryKeys($data)
{
return ['geog_unit_name', 'geog_unit_key'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date_calc', ChillDateType::class, [
'label' => 'Address valid at this date',
'required' => true,
'data' => new \DateTimeImmutable('today'),
'input' => 'datetime_immutable',
])
->add('level', EntityType::class, [
'label' => 'Geographical layer',
'placeholder' => 'Select a geographical layer',
'class' => GeographicalUnitLayer::class,
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
'choice_label' => function(GeographicalUnitLayer $item) {
return $this->translatableStringHelper->localize($item->getName());
},
]);
}
/**
* @inheritDoc
*/
public function getTitle()
{
return 'Group people by geographical unit based on his address';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data): void
{
$qb
@ -144,20 +73,80 @@ class GeographicalUnitAggregator implements AggregatorInterface
->addSelect('person_geog_agg_geog_unit.unitName AS geog_unit_name')
->addSelect('person_geog_agg_geog_unit.unitRefId AS geog_unit_key')
->addGroupBy('geog_unit_name')
->addGroupBy('geog_unit_key')
;
->addGroupBy('geog_unit_key');
}
/**
* @inheritDoc
*/
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date_calc', ChillDateType::class, [
'label' => 'Address valid at this date',
'required' => true,
'data' => new DateTimeImmutable('today'),
'input' => 'datetime_immutable',
])
->add('level', EntityType::class, [
'label' => 'Geographical layer',
'placeholder' => 'Select a geographical layer',
'class' => GeographicalUnitLayer::class,
'choices' => $this->geographicalUnitLayerRepository->findAllHavingUnits(),
'choice_label' => function (GeographicalUnitLayer $item) {
return $this->translatableStringHelper->localize($item->getName());
},
]);
}
public static function getDefaultAlias(): string
{
return 'person_geog_agg';
}
public function getLabels($key, array $values, $data)
{
switch ($key) {
case 'geog_unit_name':
return static function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitname';
}
if (null === $value) {
return '';
}
return $value;
};
case 'geog_unit_key':
return static function ($value): string {
if ('_header' === $value) {
return 'acp_geog_agg_unitrefid';
}
if (null === $value) {
return '';
}
return $value;
};
default:
throw new LogicException('key not supported');
}
}
public function getQueryKeys($data)
{
return ['geog_unit_name', 'geog_unit_key'];
}
public function getTitle()
{
return 'Group people by geographical unit based on his address';
}
}

View File

@ -24,6 +24,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function in_array;
final class HouseholdPositionAggregator implements AggregatorInterface, ExportElementValidatedInterface
{

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\MaritalStatusRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class MaritalStatusAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ActionTypeAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class GoalAggregator implements AggregatorInterface
{

View File

@ -1,5 +1,14 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
@ -8,14 +17,16 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\GoalRepository;
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class GoalResultAggregator implements AggregatorInterface
{
private ResultRepository $resultRepository;
private GoalRepository $goalRepository;
private ResultRepository $resultRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
@ -28,86 +39,11 @@ class GoalResultAggregator implements AggregatorInterface
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value) use ($key): string {
if (null === $value) {
return '';
}
switch ($key) {
case 'goal_aggregator':
if ('_header' === $value) {
return 'Goal Type';
}
$g = $this->goalRepository->find($value);
return $this->translatableStringHelper->localize(
$g->getTitle()
);
case 'result_aggregator':
if ('_header' === $value) {
return 'Result Type';
}
$r = $this->resultRepository->find($value);
return $this->translatableStringHelper->localize(
$r->getTitle()
);
default:
throw new \LogicException();
}
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return [
'goal_aggregator',
'result_aggregator'
];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group social work actions by goal and result';
}
/**
* @inheritDoc
*/
public function addRole(): ?string
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('goal', $qb->getAllAliases(), true)) {
@ -123,11 +59,62 @@ class GoalResultAggregator implements AggregatorInterface
$qb->addGroupBy('goal_aggregator')->addGroupBy('result_aggregator');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)
{
return function ($value) use ($key): string {
if (null === $value) {
return '';
}
switch ($key) {
case 'goal_aggregator':
if ('_header' === $value) {
return 'Goal Type';
}
$g = $this->goalRepository->find($value);
return $this->translatableStringHelper->localize(
$g->getTitle()
);
case 'result_aggregator':
if ('_header' === $value) {
return 'Result Type';
}
$r = $this->resultRepository->find($value);
return $this->translatableStringHelper->localize(
$r->getTitle()
);
default:
throw new LogicException();
}
};
}
public function getQueryKeys($data): array
{
return [
'goal_aggregator',
'result_aggregator',
];
}
public function getTitle(): string
{
return 'Group social work actions by goal and result';
}
}

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class JobAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ReferrerAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\ResultRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ResultAggregator implements AggregatorInterface
{

View File

@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
final class ScopeAggregator implements AggregatorInterface
{

View File

@ -107,8 +107,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
'
)
)
->setParameter('authorized_centers', $centers)
;
->setParameter('authorized_centers', $centers);
$qb->select('COUNT(DISTINCT acp.id) AS export_result');

Some files were not shown because too many files have changed in this diff Show More