Commit c004c1e5 authored by Christian BUFFIN's avatar Christian BUFFIN
Browse files

ajout de la classe RecettesController qui permet d'obtenir des tableaux...

ajout de la classe RecettesController qui permet d'obtenir des tableaux synthétiques en temps réel des paramétrages utilisés pour la recette
parent fdec019a
<?php
class RecettesController extends AppController {
public $uses = [
'Organisation'
];
/**
* Vérification de l'accès aux actions en fonction du profil de l'utilisateur connecté.
*/
public function beforeFilter() {
parent::beforeFilter();
// Seul le rôle Superutilisateur peut accéder à ce contrôleur, uniquement en mode debug et sur une instance de recette
$recette = preg_match('/^https{0,1}:\/\/(localhost|.*\.recette\.libriciel\.fr)[:\/]/', Router::url( $this->here, true )) === 1;
if ($this->Droits->isSu() !== true || (int)Configure::read('debug') < 1 || $recette === false) {
throw new ForbiddenException(__d('default', 'default.flasherrorPasDroitPage'));
}
}
protected function _getOrganisations() {
$query = [
'fields' => [
'Organisation.id',
'Organisation.raisonsociale'
],
'contain' => [
'Responsable' => [
'fields' => ['Responsable.nom_complet'],
'order' => ['Responsable.nom_complet']
],
'Role' => [
'fields' => ['Role.libelle'],
'order' => ['Role.libelle']
],
'Service' => [
'fields' => ['Service.libelle'],
'order' => ['Service.libelle']
],
'Soustraitant' => [
'fields' => ['Soustraitant.raisonsociale'],
'order' => ['Soustraitant.raisonsociale']
],
'Typage' => [
'fields' => ['Typage.libelle'],
'order' => ['Typage.libelle']
],
'User' => [
'fields' => ['User.username'],
'order' => ['User.username']
],
],
'order' => [
'Organisation.raisonsociale'
]
];
return $this->Organisation->find('all', $query);
}
protected function _getUsers() {
$query = [
'fields' => array_merge(
[
'User.username',
'User.nom_complet',
'User.email',
'("Admin"."id" IS NOT NULL) AS "User__is_superadmin"',
'(CASE WHEN "User"."username" = \'superadmin\' THEN \'admin\' ELSE \'bateauavionmotovoiture\' END) AS "User__pwd"',
],
$this->Organisation->User->Admin->fields()
),
'contain' => [
'Organisation' => [
'fields' => [
'Organisation.raisonsociale',
'("Organisation"."dpo" = "OrganisationUser"."user_id") AS "User__is_dpo"',
],
'order' => [
'Organisation.raisonsociale'
],
],
],
'joins' => [
$this->Organisation->User->join('Admin', ['type' => 'LEFT OUTER'])
],
'conditions' => [],
'order' => [
'User.username'
]
];
$users = $this->Organisation->User->find('all', $query);
foreach ($users as $idx => $user) {
foreach ((array)Hash::extract($user, 'Organisation.{n}.OrganisationUser') as $i => $ou) {
$query = [
'conditions' => [
'OrganisationUser.id' => $ou['id']
],
'contain' => [
'OrganisationUserRole' => [
'Role' => [
'fields' => 'Role.libelle',
'order' => 'Role.libelle',
]
],
'OrganisationUserService' => [
'Service' => [
'fields' => 'Service.libelle',
'order' => 'Service.libelle',
]
],
]
];
$users[$idx]['Organisation'][$i]['OrganisationUser'] = array_merge(
$users[$idx]['Organisation'][$i],
$this->Organisation->OrganisationUser->find('first', $query)
);
}
}
return $users;
}
public function index() {
$organisations = $this->_getOrganisations();
$users = $this->_getUsers();
$this->set(compact('organisations', 'users'));
}
}
<h1>Données actuelles pour la recette</h1>
<h2>Liste des entités</h2>
<table border="1" cellpadding="1" cellspacing="1" class="table">
<thead>
<tr>
<th>Raison sociale</th>
<th>Profils</th>
<th>Responsables</th>
<th>Services</th>
<th>Sous-traitants</th>
<th>Types d'annexes</th>
<th>Utilisateurs</th>
</tr>
</thead>
<tbody>
<?php foreach ($organisations as $organisation):?>
<tr>
<td><?php echo $organisation['Organisation']['raisonsociale']?></td>
<?php
$colums = [
'Role.{n}.libelle',
'Responsable.{n}.nom_complet',
'Service.{n}.libelle',
'Soustraitant.{n}.raisonsociale',
'Typage.{n}.libelle',
'User.{n}.username'
];
?>
<?php foreach($colums as $column):?>
<td>
<?php
$items = Hash::extract($organisation, $column);
if (empty($items) === false) {
echo sprintf('<ul><li>%s</li></ul>', implode('</li><li>', $items));
}
?>
</td>
<?php endforeach;?>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php /*debug($organisations);*/?>
<h2>Liste des utilisateurs</h2>
<table border="1" cellpadding="1" cellspacing="1" class="table">
<thead>
<tr>
<th>Identifiant</th>
<th>Nom</th>
<th>Mot de passe</th>
<th>Courriel</th>
<th>Spécial</th>
<th>Entité</th>
<th>Profil</th>
<th>Services</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user):?>
<tr>
<?php
$links = 0;
if (isset($user['Organisation']) === true) {
$links = count($user['Organisation']);
}
$rowspan = $links < 1 ? 1 : $links;
?>
<td rowspan="<?php echo $rowspan;?>"><?php echo $user['User']['username']?></td>
<td rowspan="<?php echo $rowspan;?>"><?php echo $user['User']['nom_complet']?></td>
<td rowspan="<?php echo $rowspan;?>"><?php echo $user['User']['pwd']?></td>
<td rowspan="<?php echo $rowspan;?>"><?php echo $user['User']['email']?></td>
<?php if ($links === 0):?>
<td>Superadmin</td>
<td colspan="3"></td>
<?php else:?>
<?php foreach ($user['Organisation'] as $uo):?>
<td><?php
if ($uo['User']['is_dpo'] === true) {
echo 'DPO';
}
?></td>
<td><?php echo $uo['raisonsociale']?></td>
<td><?php echo $uo['OrganisationUser']['OrganisationUserRole'][0]['Role']['libelle'];?></td>
<td>
<?php
$services = Hash::extract($uo, 'OrganisationUser.OrganisationUserService.Service.libelle');
if (empty($services) === false) {
echo sprintf('<ul><li>%s</li></ul>', implode('</li><li>', $services));
}
?>
</td>
</tr><tr>
<?php endforeach;?>
<?php endif;?>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php /*debug($users);*/?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment