Browse Source

Implementation de user

feature/symfony6.1
Fab 3 years ago
parent
commit
f8673878fc
12 changed files with 238 additions and 109 deletions
  1. +10
    -1
      Container/User/UserContainer.php
  2. +82
    -0
      Definition/Field/User/UserFieldDefinition.php
  3. +21
    -13
      Field/Filter/AssociationFilter.php
  4. +1
    -0
      Model/User/UserModel.php
  5. +7
    -0
      Repository/AbstractStore.php
  6. +1
    -95
      Resources/assets/app/adminlte/field/collection/app.collection.js
  7. +4
    -0
      Resources/assets/app/adminlte/plugins/app.plugins.js
  8. +84
    -0
      Resources/assets/functions/widget-collection.js
  9. +12
    -0
      Resources/assets/functions/widgets.js
  10. +6
    -0
      Resources/translations/admin.fr.yaml
  11. +2
    -0
      Resources/views/adminlte/crud/form.html.twig
  12. +8
    -0
      Solver/User/UserSolver.php

+ 10
- 1
Container/User/UserContainer.php View File

namespace Lc\SovBundle\Container\User; namespace Lc\SovBundle\Container\User;


use Lc\SovBundle\Builder\User\UserBuilder; use Lc\SovBundle\Builder\User\UserBuilder;
use Lc\SovBundle\Definition\Field\User\UserFieldDefinition;
use Lc\SovBundle\Factory\User\UserFactory; use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Repository\User\UserRepositoryQuery; use Lc\SovBundle\Repository\User\UserRepositoryQuery;
use Lc\SovBundle\Repository\User\UserStore; use Lc\SovBundle\Repository\User\UserStore;
protected UserRepositoryQuery $repositoryQuery; protected UserRepositoryQuery $repositoryQuery;
protected UserStore $store; protected UserStore $store;
protected UserSolver $solver; protected UserSolver $solver;
protected UserFieldDefinition $fieldDefinition;


public function __construct( public function __construct(
UserFactory $factory, UserFactory $factory,
UserBuilder $builder, UserBuilder $builder,
UserRepositoryQuery $repositoryQuery, UserRepositoryQuery $repositoryQuery,
UserStore $store, UserStore $store,
UserSolver $solver
UserSolver $solver,
UserFieldDefinition $fieldDefinition
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->builder = $builder; $this->builder = $builder;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->solver = $solver; $this->solver = $solver;
$this->fieldDefinition = $fieldDefinition;
} }


public function getFactory(): UserFactory public function getFactory(): UserFactory
{ {
return $this->solver; return $this->solver;
} }

public function getFieldDefinition(): UserFieldDefinition
{
return $this->fieldDefinition;
}
} }

+ 82
- 0
Definition/Field/User/UserFieldDefinition.php View File

<?php

namespace Lc\SovBundle\Definition\Field\User;


use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Field\AssociationField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Solver\User\UserSolver;
use Lc\SovBundle\Translation\TranslatorAdmin;

class UserFieldDefinition extends AbstractFieldDefinition
{
protected RolesDefinition $rolesDefinition;

public function __construct(TranslatorAdmin $translatorAdmin, RolesDefinition $rolesDefinition)
{
parent::__construct($translatorAdmin);

$this->rolesDefinition = $rolesDefinition;
}

public function configureFieldsIndex(): array
{
return [
'id',
'gender',
'lastname',
'firstname',
'email',
'groupUsers'
];
}

public function configureFieldsForm(): array
{
return [
'id',
'gender',
'lastname',
'firstname',
'email',
'phone',
'birthdate',
'groupUsers'
];
}

public function configurePanels(): array
{
return [];
}

public function configureFields(): array
{
return [
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'gender' => ChoiceField::new('gender')->setChoices(
$this->translatorAdmin->transChoices(UserSolver::getGenderChoices(), 'User', 'gender')
)
->setFormTypeOption('expanded', true)
->setFormTypeOption('multiple', false)
->setSortable(true),
'lastname' => TextField::new('lastname')->setSortable(true),
'firstname' => TextField::new('firstname')->setSortable(true),
'email' => TextField::new('email')->setSortable(true),
'phone' => TextField::new('phone')->setSortable(true),
'birthdate' => DateField::new('birthdate')->setSortable(true),
'groupUsers' => AssociationField::new('groupUsers')->setSortable(true),
'roles' => ChoiceField::new('roles')
->allowMultipleChoices()
->autocomplete()
->setChoices($this->rolesDefinition->getRolesList()),
];
}

}

+ 21
- 13
Field/Filter/AssociationFilter.php View File



public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array()) public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array())
{ {
$param = array();
$targetEntity = $options['entity_dto']->getPropertyMetadata($fieldDto->getProperty())->get('targetEntity'); $targetEntity = $options['entity_dto']->getPropertyMetadata($fieldDto->getProperty())->get('targetEntity');


if($fieldDto->getCustomOption('choices')){
if ($fieldDto->getCustomOption('choices')) {
$choices = $fieldDto->getCustomOption('choices'); $choices = $fieldDto->getCustomOption('choices');
}else if($fieldDto->getFormTypeOption('choices') !=null){
} elseif ($fieldDto->getFormTypeOption('choices') != null) {
$choices = $fieldDto->getFormTypeOption('choices'); $choices = $fieldDto->getFormTypeOption('choices');
}else{
} else {
$choices = array(); $choices = array();
} }

if ($fieldDto->getFormTypeOption('choice_label') != null) {
$param['choice_label'] = $fieldDto->getFormTypeOption('choice_label');
}
//todo utiliser choices plutot que query_builder voir ProductCategoriesFilter //todo utiliser choices plutot que query_builder voir ProductCategoriesFilter
$builder->add( $builder->add(
$fieldDto->getProperty(), $fieldDto->getProperty(),
EntityType::class, EntityType::class,
array(
'class' => $targetEntity,
'placeholder' => '--',
'choices' => $choices,
'required' => false,
'attr' => array(
'class' => 'select2 input-sm',
'form' => 'filters-form',
),
array_merge(
$param,
array(
'class' => $targetEntity,
'placeholder' => '--',
'choices' => $choices,
'required' => false,
'attr' => array(
'class' => 'select2 input-sm',
'form' => 'filters-form',
),




)
) )
); );
} }
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null) public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null)
{ {
if ($filteredValue !== null) { if ($filteredValue !== null) {
$repositoryQuery->andWhere('.'.$fieldProperty.' = :'.$fieldProperty.'');
$repositoryQuery->andWhere('.' . $fieldProperty . ' = :' . $fieldProperty . '');
$repositoryQuery->setParameter($fieldProperty, $filteredValue); $repositoryQuery->setParameter($fieldProperty, $filteredValue);
/* //TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici /* //TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici
if ($field['type_options']['multiple']) { if ($field['type_options']['multiple']) {

+ 1
- 0
Model/User/UserModel.php View File

* @ORM\Column(type="string", length=20, nullable=true) * @ORM\Column(type="string", length=20, nullable=true)
*/ */
protected $phone; protected $phone;

/** /**
* @ORM\Column(type="boolean", nullable=true) * @ORM\Column(type="boolean", nullable=true)
*/ */

+ 7
- 0
Repository/AbstractStore.php View File

return $query->find(); return $query->find();
} }


public function getAll($query = null)
{
$query = $this->createQuery($query);
$query->filterIsOnlineAndOffline();
return $query->find();
}

public function getOnline($query = null) public function getOnline($query = null)
{ {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);

+ 1
- 95
Resources/assets/app/adminlte/field/collection/app.collection.js View File





$(document).ready(function () { $(document).ready(function () {
initCollectionWidget();
SovWidgets.setCollectionWidget();
}); });

function initCollectionWidget() {

$('.field-collection[data-prototype]').each(function (i, collectionWidget) {
setCollectionWidgetSortable($(collectionWidget));
reindexKeyCollectionWidget($(collectionWidget));

setCollectionWidgetAdd($(collectionWidget));
setCollectionWidgetDelete($(collectionWidget));
});
}

function setCollectionWidgetAdd($collectionWidget) {

if ($collectionWidget.data('allow-add')) {
$collectionWidget.find('.field-collection-add').on('click', function (e) {
// grab the prototype template
var newWidget = $collectionWidget.attr('data-prototype');
// replace the "__name__" used in the id and name of the prototype
// with a number that's unique to your emails
// end name attribute looks like name="contact[emails][2]"
newWidget = newWidget.replace(/__name__/g, getNumItems($collectionWidget));

// create a new list element and add it to the list
$collectionWidget.find('.form-widget-compound .field-collection-group').append(newWidget);
$collectionWidget.find('.field-collection-item:last').find('.field-position').val(getNumItems($collectionWidget));

reindexKeyCollectionWidget($collectionWidget);
setCollectionWidgetDelete($collectionWidget);
$collectionWidget.trigger('collection-add-item');

$collectionWidget.data('num-items', $collectionWidget.data('num-items') + 1);
$collectionWidget.find('.collection-empty').hide();
});
}
}

function setCollectionWidgetDelete($collectionWidget) {
if ($collectionWidget.data('allow-delete')) {
$collectionWidget.find('.field-collection-delete').off('click');
$collectionWidget.find('.field-collection-delete').on('click', function () {
$(this).parents('.form-group:first').remove();
reindexKeyCollectionWidget($collectionWidget);
if(getNumItems($collectionWidget)==0)$collectionWidget.find('.collection-empty').show();
});
}
}

function getNumItems($collectionWidget) {
if ($collectionWidget.data('reindex-key')) {
return $collectionWidget.find('.field-collection-item').length;
} else {
return $collectionWidget.data('num-items');
}
}

function reindexKeyCollectionWidget($collectionWidget) {
if ($collectionWidget.data('reindex-key')) {
$collectionWidget.find('.field-collection-item').each(function (i, item) {
$(item).find('input,textarea').each(function (y, field) {
let $field = $(field);
//Chanegment ID
let posIdPrefix = parseInt(SovTools.indexOfFirstDigit($field.prop('id')));
let posIdSuffix = parseInt(SovTools.indexOfLastDigit($field.prop('id')));

let idPrefix = $field.prop('id').substr(0, posIdPrefix);
let idSuffix = $field.prop('id').substr(posIdSuffix + 1);

$field.prop('id', idPrefix + i + idSuffix);

//Chanegment Name
let posNamePrefix = SovTools.indexOfFirstDigit($field.prop('name'));
let posNameSuffix = SovTools.indexOfLastDigit($field.prop('name'));
let namePrefix = $field.prop('name').substr(0, posNamePrefix);
let nameSuffix = $field.prop('name').substr(posNameSuffix + 1);
$field.prop('name', namePrefix + i + nameSuffix);
});
});
}
}

function setCollectionWidgetSortable($collectionWidget) {
if ($collectionWidget.data('sortable')) {
$collectionWidget.find('.field-collection-group').sortable({
"handle" : '.lc-btn-sortable',
cancel: ''
});
$collectionWidget.find('.field-collection-group').on("sortupdate", function (event, ui) {
$collectionWidget.find('.field-collection-group>div').each(function (index, item) {
$(item).find('.field-position').val(index);
});
});
}
}

+ 4
- 0
Resources/assets/app/adminlte/plugins/app.plugins.js View File

import { SovPrices } from '../../../functions/prices.js'; import { SovPrices } from '../../../functions/prices.js';
global.SovPrices = SovPrices; global.SovPrices = SovPrices;


// Widgets
import { SovWidgetCollection } from '../../../functions/widget-collection.js';
global.SovWidgetCollection = SovWidgetCollection;

// Widgets // Widgets
import { SovWidgets } from '../../../functions/widgets.js'; import { SovWidgets } from '../../../functions/widgets.js';
global.SovWidgets = SovWidgets; global.SovWidgets = SovWidgets;

+ 84
- 0
Resources/assets/functions/widget-collection.js View File

export class SovWidgetCollection {
static setCollectionWidgetAdd($collectionWidget) {

if ($collectionWidget.data('allow-add')) {
$collectionWidget.find('.field-collection-add').on('click', function (e) {
// grab the prototype template
var newWidget = $collectionWidget.attr('data-prototype');
// replace the "__name__" used in the id and name of the prototype
// with a number that's unique to your emails
// end name attribute looks like name="contact[emails][2]"
newWidget = newWidget.replace(/__name__/g, SovWidgetCollection.getNumItems($collectionWidget));

// create a new list element and add it to the list
$collectionWidget.find('.form-widget-compound .field-collection-group').append(newWidget);
$collectionWidget.find('.field-collection-item:last').find('.field-position').val(SovWidgetCollection.getNumItems($collectionWidget));

SovWidgetCollection.reindexKeyCollectionWidget($collectionWidget);
SovWidgetCollection.setCollectionWidgetDelete($collectionWidget);
$collectionWidget.trigger('collection-add-item');

$collectionWidget.data('num-items', $collectionWidget.data('num-items') + 1);
$collectionWidget.find('.collection-empty').hide();
});
}
}

static setCollectionWidgetDelete($collectionWidget) {
if ($collectionWidget.data('allow-delete')) {
$collectionWidget.find('.field-collection-delete').off('click');
$collectionWidget.find('.field-collection-delete').on('click', function () {
$(this).parents('.form-group:first').remove();
SovWidgetCollection.reindexKeyCollectionWidget($collectionWidget);
if (getNumItems($collectionWidget) == 0) $collectionWidget.find('.collection-empty').show();
});
}
}

static getNumItems($collectionWidget) {
if ($collectionWidget.data('reindex-key')) {
return $collectionWidget.find('.field-collection-item').length;
} else {
return $collectionWidget.data('num-items');
}
}

static reindexKeyCollectionWidget($collectionWidget) {
if ($collectionWidget.data('reindex-key')) {
$collectionWidget.find('.field-collection-item').each(function (i, item) {
$(item).find('input,textarea').each(function (y, field) {
let $field = $(field);
//Chanegment ID
let posIdPrefix = parseInt(SovTools.indexOfFirstDigit($field.prop('id')));
let posIdSuffix = parseInt(SovTools.indexOfLastDigit($field.prop('id')));

let idPrefix = $field.prop('id').substr(0, posIdPrefix);
let idSuffix = $field.prop('id').substr(posIdSuffix + 1);

$field.prop('id', idPrefix + i + idSuffix);

//Chanegment Name
let posNamePrefix = SovTools.indexOfFirstDigit($field.prop('name'));
let posNameSuffix = SovTools.indexOfLastDigit($field.prop('name'));
let namePrefix = $field.prop('name').substr(0, posNamePrefix);
let nameSuffix = $field.prop('name').substr(posNameSuffix + 1);
$field.prop('name', namePrefix + i + nameSuffix);
});
});
}
}

static setCollectionWidgetSortable($collectionWidget) {
if ($collectionWidget.data('sortable')) {
$collectionWidget.find('.field-collection-group').sortable({
"handle": '.lc-btn-sortable',
cancel: ''
});
$collectionWidget.find('.field-collection-group').on("sortupdate", function (event, ui) {
$collectionWidget.find('.field-collection-group>div').each(function (index, item) {
$(item).find('.field-position').val(index);
});
});
}
}
}

+ 12
- 0
Resources/assets/functions/widgets.js View File

}); });
}); });
} }

static setCollectionWidget() {

$('.field-collection[data-prototype]').each(function (i, collectionWidget) {
SovWidgetCollection.setCollectionWidgetSortable($(collectionWidget));
SovWidgetCollection.reindexKeyCollectionWidget($(collectionWidget));

SovWidgetCollection.setCollectionWidgetAdd($(collectionWidget));
SovWidgetCollection.setCollectionWidgetDelete($(collectionWidget));
});
}

} }

+ 6
- 0
Resources/translations/admin.fr.yaml View File

fields: fields:
firstname: Prénom firstname: Prénom
lastname: Nom lastname: Nom
gender: Sexe
genderChoices:
0: Homme
1: Femme
birthdate: Date de naissance
groupUsers: Groupe d'utilisateurs
Page: Page:
label: Page label: Page
label_plurial: Pages label_plurial: Pages

+ 2
- 0
Resources/views/adminlte/crud/form.html.twig View File





{% block main %} {% block main %}
<div class="row">
<div class="col-8"> <div class="col-8">
{% block form %} {% block form %}
{{ form(form) }} {{ form(form) }}
{{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', { entity_id: entity.primaryKeyValue }, with_context = false) }} {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', { entity_id: entity.primaryKeyValue }, with_context = false) }}
{% endif %} {% endif %}
{% endblock delete_form %} {% endblock delete_form %}
</div>
{% endblock %} {% endblock %}





+ 8
- 0
Solver/User/UserSolver.php View File

use Lc\SovBundle\Model\Newsletter\NewsletterInterface; use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\User\GroupUserInterface; use Lc\SovBundle\Model\User\GroupUserInterface;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Model\User\UserModel;


class UserSolver class UserSolver
{ {
} }
} }


public static function getGenderChoices(){
return[
'0',
'1'
];
}

} }

Loading…
Cancel
Save