mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add ordoring field & Display Activity type by Category
This commit is contained in:
parent
f836114d84
commit
1f1b9c594f
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 = [
|
||||
|
@ -8,13 +8,17 @@
|
||||
<h2 class="chill-red">{{ "Activity creation"|trans }}</h2>
|
||||
|
||||
{# TODO: refaire l'html css des tuilles #}
|
||||
<div style="display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
|
||||
{% for activityType in activityTypes %}
|
||||
<a href="{{ path('chill_activity_activity_new', {'person_id': person.id, 'activityType_id': activityType.id }) }}">
|
||||
<div style="width:200px;height:200px;border:1px dotted red;display:flex;justify-content:center;align-items:center;align-content:center;">
|
||||
{{ activityType.name|localize_translatable_string }}
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% for row in data %}
|
||||
<h3>{{ row.activityTypeCategory.name|localize_translatable_string }}</h3>
|
||||
<div style="display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
|
||||
{% for activityType in row.activityTypes %}
|
||||
<a href="{{ path('chill_activity_activity_new', {'person_id': person.id, 'activityType_id': activityType.id }) }}">
|
||||
<div style="width:200px;height:200px;border:1px dotted red;display:flex;justify-content:center;align-items:center;align-content:center;">
|
||||
{{ activityType.name|localize_translatable_string }}
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Activity;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210506090417 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE activitytype ADD ordering DOUBLE PRECISION DEFAULT \'0.0\' NOT NULL');
|
||||
$this->addSql('ALTER TABLE activitytypecategory ADD ordering DOUBLE PRECISION DEFAULT \'0.0\' NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE activitytypecategory DROP ordering');
|
||||
$this->addSql('ALTER TABLE activitytype DROP ordering');
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Activity;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20210506094520 extends AbstractMigration
|
||||
{
|
||||
public function getDescription() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE activitytype ADD category_id INT DEFAULT 1');
|
||||
$this->addSql('ALTER TABLE activitytype ADD CONSTRAINT FK_B38CD05112469DE2 FOREIGN KEY (category_id) REFERENCES activitytypecategory (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE activitytype DROP CONSTRAINT FK_B38CD05112469DE2');;
|
||||
$this->addSql('ALTER TABLE activitytype DROP category_id');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user