mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
Feature: [admin][ActivityReason] improve administration for activity reason
* list alphabetically; * show "active" in index
This commit is contained in:
parent
e99fb75ebd
commit
25dd65fbd8
@ -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,
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -7,22 +7,34 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Name'|trans }}</th>
|
||||
<th>{{ 'Active'|trans }}</th>
|
||||
<th>{{ 'Actions'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for entity in entities %}
|
||||
<tr class="{% if entity.active %}active{% else %}inactive{% endif %}">
|
||||
<td><a href="{{ path('chill_activity_activityreason_show', { 'id': entity.id }) }}">{{ entity.name|localize_translatable_string }}</a></td>
|
||||
<td>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('chill_activity_activityreason_show', { 'id': entity.id }) }}" class="btn btn-show" title="{{ 'show'|trans }}"></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ path('chill_activity_activityreason_edit', { 'id': entity.id }) }}" class="btn btn-edit" title="{{ 'edit'|trans }}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
{% if entity.category is not null -%}
|
||||
{{ entity.category.name|localize_translatable_string }} >
|
||||
{% endif -%}
|
||||
{{ entity.name|localize_translatable_string }}
|
||||
</td>
|
||||
<td>
|
||||
<i class="fa {% if entity.active %}fa-check-square-o{% else %}fa-square-o{% endif %}"></i>
|
||||
{% if entity.active and not entity.isActiveAndParentActive %}
|
||||
<span class="badge text-bg-danger text-white">{{ 'Associated activity reason category is inactive'|trans }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<a href="{{ path('chill_activity_activityreason_show', { 'id': entity.id }) }}" class="btn btn-show" title="{{ 'show'|trans }}"></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ path('chill_activity_activityreason_edit', { 'id': entity.id }) }}" class="btn btn-edit" title="{{ 'edit'|trans }}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -7,6 +7,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ 'Name'|trans }}</th>
|
||||
<th>{{ 'Active'|trans }}</th>
|
||||
<th>{{ 'Actions'|trans }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -14,7 +15,11 @@
|
||||
{% for entity in entities %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ path('chill_activity_activityreasoncategory_show', { 'id': entity.id }) }}">{{ entity.name|localize_translatable_string }}</a></td>
|
||||
{{ entity.name|localize_translatable_string }}
|
||||
</td>
|
||||
<td>
|
||||
<i class="fa {% if entity.active %}fa-check-square-o{% else %}fa-square-o{% endif %}"></i>
|
||||
</td>
|
||||
<td>
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
|
@ -1,4 +1,11 @@
|
||||
services:
|
||||
Chill\ActivityBundle\Controller\ActivityController:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\ActivityBundle\Controller\:
|
||||
resource: '../../Controller/'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\ActivityBundle\Controller\ActivityController:
|
||||
tags: ['controller.service_arguments']
|
||||
|
@ -1,11 +1,8 @@
|
||||
---
|
||||
services:
|
||||
chill.activity.form.type.translatableactivityreasoncategory:
|
||||
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
tags:
|
||||
- { name: form.type, alias: translatable_activity_reason_category }
|
||||
Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategoryType:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
chill.activity.form.type.translatableactivityreason:
|
||||
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReason
|
||||
|
@ -1,5 +1,8 @@
|
||||
---
|
||||
services:
|
||||
Chill\ActivityBundle\Repository\ActivityReasonRepository:
|
||||
autowire: true
|
||||
|
||||
chill_activity.repository.activity_type: '@Chill\ActivityBundle\Repository\ActivityTypeRepository'
|
||||
chill_activity.repository.reason: '@Chill\ActivityBundle\Repository\ActivityReasonRepository'
|
||||
chill_activity.repository.reason_category: '@Chill\ActivityBundle\Repository\ActivityReasonCategoryRepository'
|
||||
|
@ -117,6 +117,7 @@ Activity Reasons: Sujets d'une activité
|
||||
Activity Reasons Category: Catégories de sujet d'activités
|
||||
Activity Types Categories: Catégories des types d'activité
|
||||
Activity Presences: Presences aux activités
|
||||
Associated activity reason category is inactive: La catégorie de sujet attachée est inactive
|
||||
|
||||
|
||||
# Crud
|
||||
@ -276,7 +277,7 @@ Creators: Créateurs
|
||||
Filter activity by userscope: Filtrer les activités par service du créateur
|
||||
'Filtered activity by userscope: only %scopes%': "Filtré par service du créateur: uniquement %scopes%"
|
||||
Accepted userscope: Services
|
||||
|
||||
|
||||
Filter acp which has no activity: Filtrer les parcours qui n’ont pas d’activité
|
||||
Filtered acp which has no activities: Filtrer les parcours sans activité associée
|
||||
Group acp by activity number: Grouper les parcours par nombre d’activité
|
||||
|
@ -42,6 +42,8 @@ by_user: "par "
|
||||
lifecycleUpdate: Evenements de création et mise à jour
|
||||
address_fields: Données liées à l'adresse
|
||||
|
||||
inactive: inactif
|
||||
|
||||
Edit: Modifier
|
||||
Update: Mettre à jour
|
||||
Back to the list: Retour à la liste
|
||||
|
Loading…
x
Reference in New Issue
Block a user