diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php
index 6af42a53c..95a49d0ba 100644
--- a/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php
+++ b/src/Bundle/ChillActivityBundle/Controller/ActivityReasonController.php
@@ -13,15 +13,24 @@ namespace Chill\ActivityBundle\Controller;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Form\ActivityReasonType;
+use Chill\ActivityBundle\Repository\ActivityReasonRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* ActivityReason controller.
*/
class ActivityReasonController extends AbstractController
{
+ private ActivityReasonRepository $activityReasonRepository;
+
+ public function __construct(ActivityReasonRepository $activityReasonRepository)
+ {
+ $this->activityReasonRepository = $activityReasonRepository;
+ }
+
/**
* Creates a new ActivityReason entity.
*/
@@ -56,8 +65,8 @@ class ActivityReasonController extends AbstractController
$entity = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReason::class)->find($id);
- if (!$entity) {
- throw $this->createNotFoundException('Unable to find ActivityReason entity.');
+ if (null === $entity) {
+ throw new NotFoundHttpException('Unable to find ActivityReason entity.');
}
$editForm = $this->createEditForm($entity);
@@ -75,7 +84,7 @@ class ActivityReasonController extends AbstractController
{
$em = $this->getDoctrine()->getManager();
- $entities = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityReason::class)->findAll();
+ $entities = $this->activityReasonRepository->findAll();
return $this->render('ChillActivityBundle:ActivityReason:index.html.twig', [
'entities' => $entities,
diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityReason.php b/src/Bundle/ChillActivityBundle/Entity/ActivityReason.php
index c0cc21209..e6da6b7e0 100644
--- a/src/Bundle/ChillActivityBundle/Entity/ActivityReason.php
+++ b/src/Bundle/ChillActivityBundle/Entity/ActivityReason.php
@@ -63,10 +63,8 @@ class ActivityReason
/**
* Get category.
- *
- * @return ActivityReasonCategory
*/
- public function getCategory()
+ public function getCategory(): ?ActivityReasonCategory
{
return $this->category;
}
@@ -107,6 +105,11 @@ class ActivityReason
return $this->name;
}
+ public function isActiveAndParentActive(): bool
+ {
+ return $this->active && null !== $this->getCategory() && $this->getCategory()->getActive();
+ }
+
/**
* Set active.
*
diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityReasonType.php b/src/Bundle/ChillActivityBundle/Form/ActivityReasonType.php
index 84a3e08ed..f47a101bd 100644
--- a/src/Bundle/ChillActivityBundle/Form/ActivityReasonType.php
+++ b/src/Bundle/ChillActivityBundle/Form/ActivityReasonType.php
@@ -11,7 +11,8 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Form;
-use Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory;
+use Chill\ActivityBundle\Entity\ActivityReason;
+use Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategoryType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -25,13 +26,13 @@ class ActivityReasonType extends AbstractType
$builder
->add('name', TranslatableStringFormType::class)
->add('active', CheckboxType::class, ['required' => false])
- ->add('category', TranslatableActivityReasonCategory::class);
+ ->add('category', TranslatableActivityReasonCategoryType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
- 'data_class' => 'Chill\ActivityBundle\Entity\ActivityReason',
+ 'data_class' => ActivityReason::class,
]);
}
diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityReasonRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityReasonRepository.php
index 275c49b2c..c6b69319e 100644
--- a/src/Bundle/ChillActivityBundle/Repository/ActivityReasonRepository.php
+++ b/src/Bundle/ChillActivityBundle/Repository/ActivityReasonRepository.php
@@ -14,17 +14,38 @@ namespace Chill\ActivityBundle\Repository;
use Chill\ActivityBundle\Entity\ActivityReason;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
+use Symfony\Component\HttpFoundation\RequestStack;
/**
* @method ActivityReason|null find($id, $lockMode = null, $lockVersion = null)
* @method ActivityReason|null findOneBy(array $criteria, array $orderBy = null)
- * @method ActivityReason[] findAll()
* @method ActivityReason[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ActivityReasonRepository extends ServiceEntityRepository
{
- public function __construct(ManagerRegistry $registry)
- {
+ private RequestStack $requestStack;
+
+ public function __construct(
+ ManagerRegistry $registry,
+ RequestStack $requestStack
+ ) {
parent::__construct($registry, ActivityReason::class);
+
+ $this->requestStack = $requestStack;
+ }
+
+ /**
+ * @return ActivityReason[]
+ */
+ public function findAll(): array
+ {
+ $qb = $this->createQueryBuilder('ar');
+ $qb->select(['ar'])
+ ->leftJoin('ar.category', 'category')
+ ->addOrderBy('JSON_EXTRACT(category.name, :lang)')
+ ->addOrderBy('JSON_EXTRACT(ar.name, :lang)')
+ ->setParameter('lang', $this->requestStack->getCurrentRequest()->getLocale() ?? 'fr');
+
+ return $qb->getQuery()->getResult();
}
}
diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityReason/index.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityReason/index.html.twig
index 7d9e5f71d..855c9386d 100644
--- a/src/Bundle/ChillActivityBundle/Resources/views/ActivityReason/index.html.twig
+++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityReason/index.html.twig
@@ -7,22 +7,34 @@
{{ 'Name'|trans }}
+ {{ 'Active'|trans }}
{{ 'Actions'|trans }}