Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
agplv3
kohinos-tav
Commits
91314e67
Commit
91314e67
authored
Jan 17, 2022
by
Julien Jorry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Presta / Adherent Admin : add cotisation up to date and first cotisation in export
parent
b135dc7b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
255 additions
and
5 deletions
+255
-5
services.yaml
config/services.yaml
+1
-0
AdherentAdmin.php
src/Admin/AdherentAdmin.php
+60
-1
PrestataireAdmin.php
src/Admin/PrestataireAdmin.php
+64
-3
Prestataire.php
src/Entity/Prestataire.php
+1
-1
CustomDoctrineORMQuerySourceIterator.php
src/Exporter/CustomDoctrineORMQuerySourceIterator.php
+85
-0
CotisationUtils.php
src/Utils/CotisationUtils.php
+44
-0
No files found.
config/services.yaml
View file @
91314e67
...
@@ -112,6 +112,7 @@ services:
...
@@ -112,6 +112,7 @@ services:
app.utils.cotisations
:
app.utils.cotisations
:
class
:
App\Utils\CotisationUtils
class
:
App\Utils\CotisationUtils
autowire
:
false
autowire
:
false
public
:
true
arguments
:
[
'
@app.utils.custom_entity_manager'
,
'
@session'
,
'
@security.helper'
,
'
@event_dispatcher'
]
arguments
:
[
'
@app.utils.custom_entity_manager'
,
'
@session'
,
'
@security.helper'
,
'
@event_dispatcher'
]
app.utils.account
:
app.utils.account
:
...
...
src/Admin/AdherentAdmin.php
View file @
91314e67
...
@@ -11,17 +11,21 @@ use App\Entity\User;
...
@@ -11,17 +11,21 @@ use App\Entity\User;
use
App\Entity\Usergroup
;
use
App\Entity\Usergroup
;
use
App\Enum\CurrencyEnum
;
use
App\Enum\CurrencyEnum
;
use
App\Events\MLCEvents
;
use
App\Events\MLCEvents
;
use
App\Exporter\CustomDoctrineORMQuerySourceIterator
;
use
App\Form\Type\GeolocFormType
;
use
App\Form\Type\GeolocFormType
;
use
App\Form\Type\UserFormType
;
use
App\Form\Type\UserFormType
;
use
Doctrine\ORM\Query
;
use
FOS\UserBundle\Event\UserEvent
;
use
FOS\UserBundle\Event\UserEvent
;
use
Knp\Menu\ItemInterface
as
MenuItemInterface
;
use
Knp\Menu\ItemInterface
as
MenuItemInterface
;
use
Sonata\AdminBundle\Admin\AbstractAdmin
;
use
Sonata\AdminBundle\Admin\AbstractAdmin
;
use
Sonata\AdminBundle\Admin\AdminInterface
;
use
Sonata\AdminBundle\Admin\AdminInterface
;
use
Sonata\AdminBundle\Datagrid\DatagridInterface
;
use
Sonata\AdminBundle\Datagrid\DatagridMapper
;
use
Sonata\AdminBundle\Datagrid\DatagridMapper
;
use
Sonata\AdminBundle\Datagrid\ListMapper
;
use
Sonata\AdminBundle\Datagrid\ListMapper
;
use
Sonata\AdminBundle\Datagrid\ProxyQueryInterface
;
use
Sonata\AdminBundle\Datagrid\ProxyQueryInterface
;
use
Sonata\AdminBundle\Form\FormMapper
;
use
Sonata\AdminBundle\Form\FormMapper
;
use
Sonata\AdminBundle\Route\RouteCollection
;
use
Sonata\AdminBundle\Route\RouteCollection
;
use
Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker
;
use
Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter
;
use
Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter
;
use
Sonata\Form\Type\DateTimeRangePickerType
;
use
Sonata\Form\Type\DateTimeRangePickerType
;
use
Sonata\UserBundle\Model\UserManagerInterface
;
use
Sonata\UserBundle\Model\UserManagerInterface
;
...
@@ -415,7 +419,62 @@ class AdherentAdmin extends AbstractAdmin
...
@@ -415,7 +419,62 @@ class AdherentAdmin extends AbstractAdmin
'Groupe'
=>
'groupe.name'
,
'Groupe'
=>
'groupe.name'
,
'Téléphone'
=>
'user.phone'
,
'Téléphone'
=>
'user.phone'
,
'Mobile'
=>
'user.mobile'
,
'Mobile'
=>
'user.mobile'
,
'E-compte'
=>
'ecompte'
,
'Crée le'
=>
'createdAt'
,
'Mise à jour le'
=>
'updatedAt'
,
];
];
}
}
public
function
getDataSourceIterator
()
{
$datagrid
=
$this
->
getDatagrid
();
$datagrid
->
buildPager
();
$fields
=
[];
foreach
(
$this
->
getExportFields
()
as
$key
=>
$field
)
{
// NEXT_MAJOR: Remove the following code in favor of the commented one.
$label
=
$this
->
getTranslationLabel
(
$field
,
'export'
,
'label'
);
$transLabel
=
$this
->
getTranslator
()
->
trans
(
$label
,
[],
$this
->
getTranslationDomain
());
if
(
$transLabel
===
$label
)
{
$fields
[
$key
]
=
$field
;
}
else
{
$fields
[
$transLabel
]
=
$field
;
}
}
return
$this
->
getModelDataSourceIterator
(
$datagrid
,
$fields
);
}
/**
* @return DoctrineORMQuerySourceIterator
*/
public
function
getModelDataSourceIterator
(
DatagridInterface
$datagrid
,
array
$fields
,
$firstResult
=
null
,
$maxResult
=
null
)
{
$datagrid
->
buildPager
();
$query
=
$datagrid
->
getQuery
();
$query
->
select
(
'DISTINCT '
.
current
(
$query
->
getRootAliases
()));
$query
->
setFirstResult
(
$firstResult
);
$query
->
setMaxResults
(
$maxResult
);
if
(
$query
instanceof
ProxyQueryInterface
)
{
$sortBy
=
$query
->
getSortBy
();
if
(
!
empty
(
$sortBy
))
{
$query
->
addOrderBy
(
$sortBy
,
$query
->
getSortOrder
());
$query
=
$query
->
getQuery
();
$query
->
setHint
(
Query
::
HINT_CUSTOM_TREE_WALKERS
,
[
OrderByToSelectWalker
::
class
]);
}
else
{
$query
=
$query
->
getQuery
();
}
}
$em
=
$this
->
getConfigurationPool
()
->
getContainer
()
->
get
(
'doctrine'
)
->
getManager
();
$cotisationUtils
=
$this
->
getConfigurationPool
()
->
getContainer
()
->
get
(
'app.utils.cotisations'
);
$iterator
=
new
CustomDoctrineORMQuerySourceIterator
(
$cotisationUtils
,
$em
,
$query
,
$fields
);
$iterator
->
setDateTimeFormat
(
'd/m/Y H:i:s'
);
//change this to suit your needs
return
$iterator
;
}
}
}
src/Admin/PrestataireAdmin.php
View file @
91314e67
...
@@ -17,22 +17,27 @@ use App\Entity\Usergroup;
...
@@ -17,22 +17,27 @@ use App\Entity\Usergroup;
use
App\Enum\CurrencyEnum
;
use
App\Enum\CurrencyEnum
;
use
App\Events\MLCEvents
;
use
App\Events\MLCEvents
;
use
App\Events\PrestataireEvent
;
use
App\Events\PrestataireEvent
;
use
App\Exporter\CustomDoctrineORMQuerySourceIterator
;
use
App\Form\Type\ContactEntityFormType
;
use
App\Form\Type\ContactEntityFormType
;
use
App\Form\Type\GeolocPrestataireFormType
;
use
App\Form\Type\GeolocPrestataireFormType
;
use
App\Form\Type\UserFormType
;
use
App\Form\Type\UserFormType
;
use
Doctrine\ORM\Query
;
use
FOS\CKEditorBundle\Form\Type\CKEditorType
;
use
FOS\CKEditorBundle\Form\Type\CKEditorType
;
use
FOS\UserBundle\Event\UserEvent
;
use
FOS\UserBundle\Event\UserEvent
;
use
FOS\UserBundle\Model\UserManagerInterface
;
use
FOS\UserBundle\Model\UserManagerInterface
;
use
Knp\Menu\ItemInterface
as
MenuItemInterface
;
use
Knp\Menu\ItemInterface
as
MenuItemInterface
;
use
Sonata\AdminBundle\Admin\AbstractAdmin
;
use
Sonata\AdminBundle\Admin\AbstractAdmin
;
use
Sonata\AdminBundle\Admin\AdminInterface
;
use
Sonata\AdminBundle\Admin\AdminInterface
;
use
Sonata\AdminBundle\Datagrid\DatagridInterface
;
use
Sonata\AdminBundle\Datagrid\DatagridMapper
;
use
Sonata\AdminBundle\Datagrid\DatagridMapper
;
use
Sonata\AdminBundle\Datagrid\ListMapper
;
use
Sonata\AdminBundle\Datagrid\ListMapper
;
use
Sonata\AdminBundle\Datagrid\ProxyQueryInterface
;
use
Sonata\AdminBundle\Form\FormMapper
;
use
Sonata\AdminBundle\Form\FormMapper
;
use
Sonata\AdminBundle\Object\Metadata
;
use
Sonata\AdminBundle\Object\Metadata
;
use
Sonata\AdminBundle\Route\RouteCollection
;
use
Sonata\AdminBundle\Route\RouteCollection
;
use
Sonata\
Form\Type\DateTimeRangePickerType
;
use
Sonata\
DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker
;
use
Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter
;
use
Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter
;
use
Sonata\Form\Type\DateTimeRangePickerType
;
use
Sonata\MediaBundle\Form\Type\MediaType
;
use
Sonata\MediaBundle\Form\Type\MediaType
;
use
Sonata\MediaBundle\Provider\MediaProviderInterface
;
use
Sonata\MediaBundle\Provider\MediaProviderInterface
;
use
Sonata\MediaBundle\Provider\Pool
;
use
Sonata\MediaBundle\Provider\Pool
;
...
@@ -800,12 +805,68 @@ class PrestataireAdmin extends AbstractAdmin
...
@@ -800,12 +805,68 @@ class PrestataireAdmin extends AbstractAdmin
{
{
return
[
return
[
'Id'
=>
'id'
,
'Id'
=>
'id'
,
'Activé ?'
=>
'enabled'
,
'Raison'
=>
'raison'
,
'Raison'
=>
'raison'
,
'Groupe'
=>
'groupe.name'
,
'Groupe local'
=>
'groupe.name'
,
'E-compte'
=>
'ecompte'
,
'Rubriques'
=>
'rubriquesString'
,
'Rubriques'
=>
'rubriquesString'
,
'Gestionnaires'
=>
'usersString'
,
'Gestionnaires'
=>
'usersString'
,
'Tags'
=>
'etatsString'
,
'Tags'
=>
'etatsString'
,
'Crée le'
=>
'createdAt'
,
'Mise à jour le'
=>
'updatedAt'
,
];
];
}
}
public
function
getDataSourceIterator
()
{
$datagrid
=
$this
->
getDatagrid
();
$datagrid
->
buildPager
();
$fields
=
[];
foreach
(
$this
->
getExportFields
()
as
$key
=>
$field
)
{
// NEXT_MAJOR: Remove the following code in favor of the commented one.
$label
=
$this
->
getTranslationLabel
(
$field
,
'export'
,
'label'
);
$transLabel
=
$this
->
getTranslator
()
->
trans
(
$label
,
[],
$this
->
getTranslationDomain
());
if
(
$transLabel
===
$label
)
{
$fields
[
$key
]
=
$field
;
}
else
{
$fields
[
$transLabel
]
=
$field
;
}
}
return
$this
->
getModelDataSourceIterator
(
$datagrid
,
$fields
);
}
/**
* @return DoctrineORMQuerySourceIterator
*/
public
function
getModelDataSourceIterator
(
DatagridInterface
$datagrid
,
array
$fields
,
$firstResult
=
null
,
$maxResult
=
null
)
{
$datagrid
->
buildPager
();
$query
=
$datagrid
->
getQuery
();
$query
->
select
(
'DISTINCT '
.
current
(
$query
->
getRootAliases
()));
$query
->
setFirstResult
(
$firstResult
);
$query
->
setMaxResults
(
$maxResult
);
if
(
$query
instanceof
ProxyQueryInterface
)
{
$sortBy
=
$query
->
getSortBy
();
if
(
!
empty
(
$sortBy
))
{
$query
->
addOrderBy
(
$sortBy
,
$query
->
getSortOrder
());
$query
=
$query
->
getQuery
();
$query
->
setHint
(
Query
::
HINT_CUSTOM_TREE_WALKERS
,
[
OrderByToSelectWalker
::
class
]);
}
else
{
$query
=
$query
->
getQuery
();
}
}
$em
=
$this
->
getConfigurationPool
()
->
getContainer
()
->
get
(
'doctrine'
)
->
getManager
();
$cotisationUtils
=
$this
->
getConfigurationPool
()
->
getContainer
()
->
get
(
'app.utils.cotisations'
);
$iterator
=
new
CustomDoctrineORMQuerySourceIterator
(
$cotisationUtils
,
$em
,
$query
,
$fields
);
$iterator
->
setDateTimeFormat
(
'd/m/Y H:i:s'
);
//change this to suit your needs
return
$iterator
;
}
}
}
src/Entity/Prestataire.php
View file @
91314e67
...
@@ -670,7 +670,7 @@ class Prestataire extends AccountableObject implements AccountableInterface
...
@@ -670,7 +670,7 @@ class Prestataire extends AccountableObject implements AccountableInterface
public
function
getUsersString
()
public
function
getUsersString
()
{
{
return
join
(
' - '
,
array_map
(
function
(
$user
)
{
return
join
(
' - '
,
array_map
(
function
(
$user
)
{
return
$user
->
getName
()
.
':'
.
$user
->
getEmail
(
);
return
$user
->
getName
()
.
(
$user
->
getEmail
()
==
$user
->
getName
()
?
''
:
(
':'
.
$user
->
getEmail
())
);
},
$this
->
users
->
getValues
()));
},
$this
->
users
->
getValues
()));
}
}
...
...
src/Exporter/CustomDoctrineORMQuerySourceIterator.php
0 → 100644
View file @
91314e67
<?php
declare
(
strict_types
=
1
);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace
App\Exporter
;
use
App\Entity\Adherent
;
use
App\Entity\Prestataire
;
use
App\Utils\CotisationUtils
;
use
Doctrine\ORM\EntityManagerInterface
;
use
Doctrine\ORM\Query
;
use
Sonata\Exporter\Source\AbstractPropertySourceIterator
;
use
Sonata\Exporter\Source\SourceIteratorInterface
;
/**
* @final since sonata-project/exporter 2.4.
*/
class
CustomDoctrineORMQuerySourceIterator
extends
AbstractPropertySourceIterator
implements
SourceIteratorInterface
{
/**
* @var Query
*/
protected
$query
;
protected
$em
;
protected
$cotisationUtils
;
/**
* @param array<string> $fields Fields to export
*/
public
function
__construct
(
CotisationUtils
$cotisationUtils
,
EntityManagerInterface
$em
,
Query
$query
,
array
$fields
,
string
$dateTimeFormat
=
'r'
)
{
$this
->
em
=
$em
;
$this
->
cotisationUtils
=
$cotisationUtils
;
$this
->
query
=
clone
$query
;
$this
->
query
->
setParameters
(
$query
->
getParameters
());
foreach
(
$query
->
getHints
()
as
$name
=>
$value
)
{
$this
->
query
->
setHint
(
$name
,
$value
);
}
parent
::
__construct
(
$fields
,
$dateTimeFormat
);
}
public
function
current
()
{
$current
=
$this
->
iterator
->
current
();
$data
=
$this
->
getCurrentData
(
$current
[
0
]);
// Add for kohinos
if
(
!
empty
(
$data
[
'Id'
])
&&
!
empty
(
$data
[
'Raison'
]))
{
//presta
$presta
=
$this
->
em
->
getRepository
(
Prestataire
::
class
)
->
findOneById
(
$data
[
'Id'
]);
$cotisEnd
=
$this
->
cotisationUtils
->
isCotisationValidForPresta
(
$presta
);
$data
[
'Cotisation à jour'
]
=
$cotisEnd
==
false
?
''
:
(
$cotisEnd
->
format
(
'd/m/Y'
));
$firstCotis
=
$this
->
cotisationUtils
->
getFirstCotisationForPresta
(
$presta
);
$data
[
'Première Cotisation'
]
=
$firstCotis
==
false
?
''
:
(
$firstCotis
->
format
(
'd/m/Y'
));
}
else
if
(
!
empty
(
$data
[
'Id'
])
&&
!
empty
(
$data
[
'Email'
]))
{
//adherent
$adherent
=
$this
->
em
->
getRepository
(
Adherent
::
class
)
->
findOneById
(
$data
[
'Id'
]);
$cotisEnd
=
$this
->
cotisationUtils
->
isCotisationValidForAdherent
(
$adherent
);
$data
[
'Cotisation à jour'
]
=
$cotisEnd
==
false
?
''
:
(
$cotisEnd
->
format
(
'd/m/Y'
));
$firstCotis
=
$this
->
cotisationUtils
->
getFirstCotisationForAdherent
(
$adherent
);
$data
[
'Première Cotisation'
]
=
$firstCotis
==
false
?
''
:
(
$firstCotis
->
format
(
'd/m/Y'
));
}
$this
->
query
->
getEntityManager
()
->
clear
();
return
$data
;
}
final
public
function
rewind
()
:
void
{
$this
->
iterator
=
$this
->
query
->
iterate
();
$this
->
iterator
->
rewind
();
}
}
src/Utils/CotisationUtils.php
View file @
91314e67
...
@@ -64,6 +64,28 @@ class CotisationUtils
...
@@ -64,6 +64,28 @@ class CotisationUtils
}
}
/**
/**
* Get first Cotisation For Presta ?
* @param Prestataire $presta
* @return boolean|date
*/
public
function
getFirstCotisationForPresta
(
?
Prestataire
$presta
)
{
$query
=
null
;
if
(
null
!==
$presta
)
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByPrestataire
(
$presta
,
'cotisation'
);
}
if
(
null
!==
$query
)
{
$cotisations
=
$query
->
getResult
();
if
(
count
(
$cotisations
)
>
0
)
{
$firstCotis
=
$cotisations
[
0
];
return
$firstCotis
->
getCotisationInfos
()
->
getDebut
();
}
}
return
false
;
}
/**
* Is the Cotisation Valid For Presta ?
* Is the Cotisation Valid For Presta ?
* @param Prestataire $presta
* @param Prestataire $presta
* @return boolean|date
* @return boolean|date
...
@@ -87,6 +109,28 @@ class CotisationUtils
...
@@ -87,6 +109,28 @@ class CotisationUtils
}
}
/**
/**
* Get first Cotisation For Adherent
* @param Adherent $adherent
* @return boolean|date
*/
public
function
getFirstCotisationForAdherent
(
?
Adherent
$adherent
)
{
$query
=
null
;
if
(
null
!==
$adherent
)
{
$query
=
$this
->
em
->
getRepository
(
Flux
::
class
)
->
getQueryByAdherent
(
$adherent
,
'cotisation'
);
}
if
(
null
!==
$query
)
{
$cotisations
=
$query
->
getResult
();
if
(
count
(
$cotisations
)
>
0
)
{
$firstCotis
=
$cotisations
[
0
];
return
$firstCotis
->
getCotisationInfos
()
->
getDebut
();
}
}
return
false
;
}
/**
* Is the Cotisation Valid For Adherent
* Is the Cotisation Valid For Adherent
* @param Adherent $adherent
* @param Adherent $adherent
* @return boolean|date
* @return boolean|date
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment