diff --git a/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php new file mode 100644 index 000000000..6abc3ac65 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Controller/AdminActivityTypeCategoryController.php @@ -0,0 +1,25 @@ +orderBy('e.id', 'ASC'); + } +} diff --git a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php index b43703b67..6007a6267 100644 --- a/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php +++ b/src/Bundle/ChillActivityBundle/DependencyInjection/ChillActivityExtension.php @@ -3,7 +3,7 @@ /* * Chill is a software for social workers * - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * , * * This program is free software: you can redistribute it and/or modify @@ -44,7 +44,7 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - + $container->setParameter('chill_activity.form.time_duration', $config['form']['time_duration']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); @@ -57,17 +57,18 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf $loader->load('services/form.yaml'); $loader->load('services/templating.yaml'); } - + public function prepend(ContainerBuilder $container) { $this->prependRoutes($container); $this->prependAuthorization($container); + $this->prependCruds($container); } /* (non-PHPdoc) * @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface::prepend() */ - public function prependRoutes(ContainerBuilder $container) + public function prependRoutes(ContainerBuilder $container) { //add routes for custom bundle $container->prependExtensionConfig('chill_main', array( @@ -78,7 +79,7 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf ) )); } - + public function prependAuthorization(ContainerBuilder $container) { $container->prependExtensionConfig('security', array( @@ -90,4 +91,33 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf ) )); } + + protected function prependCruds(ContainerBuilder $container) + { + $container->prependExtensionConfig('chill_main', [ + 'cruds' => [ + [ + 'class' => \Chill\ActivityBundle\Entity\ActivityTypeCategory::class, + 'name' => 'activity_type_category', + 'base_path' => '/admin/activity_type_category', + 'form_class' => \Chill\ActivityBundle\Form\ActivityTypeCategoryType::class, + 'controller' => \Chill\ActivityBundle\Controller\AdminActivityTypeCategoryController::class, + 'actions' => [ + 'index' => [ + 'template' => '@ChillActivity/ActivityTypeCategory/index.html.twig', + 'role' => 'ROLE_ADMIN' + ], + 'new' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityTypeCategory/new.html.twig', + ], + 'edit' => [ + 'role' => 'ROLE_ADMIN', + 'template' => '@ChillActivity/ActivityTypeCategory/edit.html.twig', + ] + ] + ] + ] + ]); + } } diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php new file mode 100644 index 000000000..006a50c28 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityTypeCategory.php @@ -0,0 +1,123 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\ActivityBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * Class ActivityTypeCateogry + * + * @package Chill\ActivityBundle\Entity + * @ORM\Entity() + * @ORM\Table(name="activitytypecategory") + * @ORM\HasLifecycleCallbacks() + */ +class ActivityTypeCategory +{ + /** + * @ORM\Id + * @ORM\Column(name="id", type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ + private ?int $id; + + /** + * @ORM\Column(type="json_array") + */ + private array $name = []; + + /** + * @ORM\Column(type="boolean") + */ + private bool $active = true; + + /** + * Get id + * + * @return integer + */ + public function getId(): int + { + return $this->id; + } + + /** + * Set name + */ + public function setName(array $name): self + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return array | string + */ + public function getName(?string $locale = null) + { + if ($locale) { + if (isset($this->name[$locale])) { + return $this->name[$locale]; + } else { + foreach ($this->name as $name) { + if (!empty($name)) { + return $name; + } + } + } + return ''; + } else { + return $this->name; + } + } + + /** + * Get active + * return true if the category type is active. + */ + public function getActive(): bool + { + return $this->active; + } + + /** + * Is active + * return true if the category type is active + */ + public function isActive(): bool + { + return $this->getActive(); + } + + /** + * Set active + * set to true if the category type is active + */ + public function setActive(bool $active): self + { + $this->active = $active; + + return $this; + } +} diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php b/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php new file mode 100644 index 000000000..8cc90b061 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Form/ActivityTypeCategoryType.php @@ -0,0 +1,33 @@ +add('name', TranslatableStringFormType::class) + ->add('active', ChoiceType::class, array( + 'choices' => array( + 'Yes' => true, + 'No' => false + ), + 'expanded' => true + )); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults(array( + 'data_class' => ActivityTypeCategory::class + )); + } +} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/edit.html.twig new file mode 100644 index 000000000..16cf893e8 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/edit.html.twig @@ -0,0 +1,12 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block title %} +{% include('@ChillMain/CRUD/_edit_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} +{% embed '@ChillMain/CRUD/_edit_content.html.twig' %} + {% block content_form_actions_view %}{% endblock %} + {% block content_form_actions_save_and_show %}{% endblock %} +{% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/index.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/index.html.twig new file mode 100644 index 000000000..2834e50dd --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/index.html.twig @@ -0,0 +1,44 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block admin_content %} +

{{ 'ActivityTypeCategory list'|trans }}

+ + + + + + + + + + + {% for entity in entities %} + + + + + + {% endfor %} + +
{{ 'Name'|trans }}{{ 'Active'|trans }}{{ 'Actions'|trans }}
{{ entity.name|localize_translatable_string }} + {%- if entity.active -%} + + {%- else -%} + + {%- endif -%} + +
    +
  • + +
  • +
+
+ + +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/new.html.twig new file mode 100644 index 000000000..c95711529 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/ActivityTypeCategory/new.html.twig @@ -0,0 +1,11 @@ +{% extends "@ChillActivity/Admin/layout_activity.html.twig" %} + +{% block title %} +{% include('@ChillMain/CRUD/_new_title.html.twig') %} +{% endblock %} + +{% block layout_wvm_content %} +{% embed '@ChillMain/CRUD/_new_content.html.twig' %} + {% block content_form_actions_save_and_show %}{% endblock %} +{% endembed %} +{% endblock %} diff --git a/src/Bundle/ChillActivityBundle/config/routes.yaml b/src/Bundle/ChillActivityBundle/config/routes.yaml index 86b5d6764..4940d8df3 100644 --- a/src/Bundle/ChillActivityBundle/config/routes.yaml +++ b/src/Bundle/ChillActivityBundle/config/routes.yaml @@ -14,6 +14,7 @@ chill_activity_activitytype: resource: "@ChillActivityBundle/config/routes/activitytype.yaml" prefix: / + chill_admin_activity_index: path: /{_locale}/admin/activity controller: Chill\ActivityBundle\Controller\AdminController::indexActivityAction @@ -32,3 +33,12 @@ chill_admin_activity_redirect_to_admin_index: admin_activity: order: 0 label: Main admin menu + +chill_activity_type_category_admin: + path: /{_locale}/admin/activity/type_category + controller: cscrud_activity_type_category_controller:index + options: + menus: + admin_activity: + order: 2999 + label: 'Activity Types Categories' diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20210401090853.php b/src/Bundle/ChillActivityBundle/migrations/Version20210401090853.php new file mode 100644 index 000000000..43f8c8460 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/migrations/Version20210401090853.php @@ -0,0 +1,36 @@ +addSql('CREATE SEQUENCE activitytypecategory_id_seq INCREMENT BY 1 MINVALUE 1 START 1000'); + $this->addSql('CREATE TABLE activitytypecategory (id INT NOT NULL, name JSON NOT NULL, active BOOLEAN NOT NULL, PRIMARY KEY(id))'); + $this->addSql('COMMENT ON COLUMN activitytypecategory.name IS \'(DC2Type:json_array)\''); + $this->addSql('INSERT INTO activitytypecategory VALUES(1, \'{"fr": "Défaut", "en": "Default"}\', true)'); + + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP SEQUENCE activitytypecategory_id_seq CASCADE'); + $this->addSql('DROP TABLE activitytypecategory'); + } +} diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index 92ac3f7b4..b038269b9 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -77,6 +77,7 @@ Activity configuration menu: Configuration des activités Activity Types: Types d'activité 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 reason admin ActivityReason list: Liste des sujets @@ -99,6 +100,14 @@ ActivityReasonCategory is active and will be proposed: La catégorie est active ActivityReasonCategory is inactive and won't be proposed: La catégorie est inactive et ne sera pas proposée # activity type admin +ActivityTypeCategory list: Liste des catégories des types d'activité +Create a new activity type category: Créer une nouvelle catégorie de type d'activité +crud: + activity_type_category: + title_new: Nouvelle catégorie de type d'activité + title_edit: Edition d'une catégorie de type d'activité + +# activitycategory type admin ActivityType list: Types d'activités Create a new activity type: Créer un nouveau type d'activité ActivityType creation: Nouveau type d'activité