export
This commit is contained in:
parent
99894ec91c
commit
bc07bec8d1
@ -16,6 +16,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
|
||||
use Cadoles\CoreBundle\Entity\User;
|
||||
use Cadoles\CoreBundle\Entity\UserGroup;
|
||||
@ -765,6 +768,77 @@ class UserController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function exportuserAction(Request $request) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$dir = $this->get('kernel')->getRootDir() . '/../uploads/export/';
|
||||
$file = "export.csv";
|
||||
|
||||
$fs = new Filesystem();
|
||||
$fs->mkdir($dir);
|
||||
|
||||
$csvh = fopen($dir.$file, 'w');
|
||||
$d = ';'; // this is the default but i like to be explicit
|
||||
$e = '"'; // this is the default but i like to be explicit
|
||||
|
||||
// Entête de colonne
|
||||
$data=["id","Login","Nom","Prénom","Email","Téléphone",$this->getParameter("labelniveau01"),$this->getParameter("labelniveau02"),"Métier","Fonction","Nom Usage","Autres Prénom","Sexe","Adresse","Date Naissance","Pays Naissance","Ville Naissance"];
|
||||
fputcsv($csvh, $data, $d, $e);
|
||||
|
||||
// Liste des utilisateurs en fonction du role de l'utilisateur en cours
|
||||
if($this->isGranted('ROLE_ADMIN')) {
|
||||
$users=$em->getRepository($this->labelentity)->findAll();
|
||||
}
|
||||
elseif($this->isGranted('ROLE_MODO')) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$users = $qb->select('user')
|
||||
->from($this->labelentity,'user')
|
||||
->from('CadolesCoreBundle:Niveau01','niveau01')
|
||||
->from('CadolesCoreBundle:UserModo', 'usermodo')
|
||||
->where('user.niveau01=niveau01.id')
|
||||
->andwhere("usermodo.niveau01 = user.niveau01")
|
||||
->andWhere("usermodo.user = :userid")
|
||||
->setParameter("userid", $this->getUser()->getId())
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
foreach($users as $user) {
|
||||
$groups="";
|
||||
foreach($user->getGroups() as $group) {
|
||||
$groups.=$group->getGroup()->getLabel()." ";
|
||||
}
|
||||
$data = [
|
||||
"id"=>$user->getId(),
|
||||
"username"=>$user->getUsername(),
|
||||
"name"=>$user->getLastname(),
|
||||
"firstname"=>$user->getFirstname(),
|
||||
"email"=>$user->getEmail(),
|
||||
"phone"=>$user->getTelephonenumber(),
|
||||
"niveau01"=>$user->getNiveau01()->getLabel(),
|
||||
"niveau02"=>($user->getNiveau02()?$user->getNiveau02()->getLabel():""),
|
||||
"job"=>$user->getJob(),
|
||||
"position"=>$user->getPosition(),
|
||||
"usualname"=>$user->getUsualname(),
|
||||
"givensname"=>$user->getGivensname(),
|
||||
"gender"=>$user->getGender(),
|
||||
"postaladress"=>$user->getPostaladress(),
|
||||
"birthdate"=>($user->getBirthdate()?$user->getBirthdate()->format("d/m/Y"):""),
|
||||
"birthcountry"=>($user->getBirthcountry()?$user->getBirthcountry()->getLabel():""),
|
||||
"birthplace"=>($user->getBirthplace()?$user->getBirthplace()->getLabel():""),
|
||||
|
||||
];
|
||||
|
||||
fputcsv($csvh, $data, $d, $e);
|
||||
}
|
||||
fclose($csvh);
|
||||
|
||||
$response = new BinaryFileResponse($dir.$file);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function importuserAction(Request $request) {
|
||||
if($this->GetParameter("masteridentity")!="SQL")
|
||||
throw $this->createNotFoundException('Permission denied');
|
||||
|
@ -266,6 +266,10 @@ cadoles_core_config_importuser_filectrl:
|
||||
path: /config/importuserfilectrl
|
||||
defaults: { _controller: CadolesCoreBundle:User:importuserfilectrl }
|
||||
|
||||
cadoles_core_config_user_export:
|
||||
path: /config/exportuser
|
||||
defaults: { _controller: CadolesCoreBundle:User:exportuser }
|
||||
|
||||
#-- Access user
|
||||
cadoles_core_user:
|
||||
path: /user
|
||||
|
@ -9,6 +9,7 @@ td { font-size: 10px; }
|
||||
<h1 class="page-header">Gestion des Utilisateurs</h1>
|
||||
{% if masteridentity=="SQL" %}
|
||||
<a class="btn btn-success" href={{ path('cadoles_core_config_user_submit') }}>Ajouter</a>
|
||||
<a class="btn btn-success" href={{ path('cadoles_core_config_user_export') }}>Exporter CSV</a>
|
||||
<br><br>
|
||||
{% elseif masteridentity=="LDAP" %}
|
||||
<a class="btn btn-success" href={{ path('cadoles_core_config_user_sync') }}>Synchroniser avec Annuaire</a>
|
||||
|
Loading…
Reference in New Issue
Block a user