diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index 37f32af28..94e4cc85f 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -27,7 +27,6 @@ use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Privacy\PrivacyEvent; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -104,12 +103,24 @@ class ActivityController extends AbstractController throw $this->createNotFoundException('Person not found'); } - $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) - ->findBy(['active' => true]); + $data = []; + + $activityTypeCategories = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityTypeCategory::class) + ->findBy(['active' => true], ['ordering' => 'ASC']); + + foreach ($activityTypeCategories as $activityTypeCategory) { + $activityTypes = $em->getRepository(\Chill\ActivityBundle\Entity\ActivityType::class) + ->findBy(['active' => true, 'category' => $activityTypeCategory], ['ordering' => 'ASC']); + + $data[] = [ + 'activityTypeCategory' => $activityTypeCategory, + 'activityTypes' => $activityTypes, + ]; + } return $this->render('ChillActivityBundle:Activity:selectType.html.twig', [ 'person' => $person, - 'activityTypes' => $activityTypes, + 'data' => $data, ]); } diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php index 149e83d28..1aef0c183 100644 --- a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php +++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php @@ -18,6 +18,6 @@ class AdminActivityTypeCategoryController extends CRUDController protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) { /** @var \Doctrine\ORM\QueryBuilder $query */ - return $query->orderBy('e.id', 'ASC'); + return $query->orderBy('e.ordering', 'ASC'); } } diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php index c872bc0f4..8bf5da13d 100644 --- a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php +++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeController.php @@ -18,6 +18,6 @@ class AdminActivityTypeController extends CRUDController protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator) { /** @var \Doctrine\ORM\QueryBuilder $query */ - return $query->orderBy('e.id', 'ASC'); + return $query->orderBy('e.ordering', 'ASC'); } } diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 65fc243d5..50cd7082e 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -54,7 +54,7 @@ class ActivityType private bool $active = true; /** - * ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityTypeCategory") + * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityTypeCategory") */ private ?ActivityTypeCategory $category = null; @@ -228,6 +228,11 @@ class ActivityType */ private string $socialDataLabel = ''; + /** + * @ORM\Column(type="float", options={"default"="0.0"}) + */ + private float $ordering = 0.0; + /** * Get id */ @@ -665,4 +670,16 @@ class ActivityType return $this->$property; } + + public function getOrdering(): float + { + return $this->ordering; + } + + public function setOrdering(float $ordering): self + { + $this->ordering = $ordering; + + return $this; + } } diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php index 4ee84edba..2da799980 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php @@ -49,6 +49,11 @@ class ActivityTypeCategory */ private bool $active = true; + /** + * @ORM\Column(type="float", options={"default"="0.0"}) + */ + private float $ordering = 0.0; + /** * Get id */ @@ -103,4 +108,16 @@ class ActivityTypeCategory return $this; } + + public function getOrdering(): float + { + return $this->ordering; + } + + public function setOrdering(float $ordering): self + { + $this->ordering = $ordering; + + return $this; + } } diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php index 8cc90b061..0c592f519 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php @@ -4,6 +4,7 @@ namespace Chill\ActivityBundle\Form; use Chill\ActivityBundle\Entity\ActivityTypeCategory; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -21,7 +22,12 @@ class ActivityTypeCategoryType extends AbstractType 'No' => false ), 'expanded' => true - )); + )) + ->add('ordering', NumberType::class, [ + 'required' => true, + 'scale' => 5 + ]) + ; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php index 9a819ddf1..d1a46b109 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeType.php @@ -7,6 +7,7 @@ use Chill\ActivityBundle\Form\Type\ActivityFieldPresence; use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -39,6 +40,10 @@ class ActivityTypeType extends AbstractType return $this->translatableStringHelper->localize($activityTypeCategory->getName()); }, ]) + ->add('ordering', NumberType::class, [ + 'required' => true, + 'scale' => 5 + ]) ; $fields = [ diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig index 9e3407337..dfd26bad1 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/selectType.html.twig @@ -8,13 +8,17 @@