Skip to content
Snippets Groups Projects
Commit 902772c5 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Tâche #25977

Pouvoir préciser le statut lors de la création d'un nouvel utilisateur
parent a9089e7a
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ author: Laurent Lécluse - DSI - Unicaen ...@@ -9,6 +9,7 @@ author: Laurent Lécluse - DSI - Unicaen
* Possibilité d'utiliser un service Unoconv présent sur un serveur dédié autre que celui de OSE * Possibilité d'utiliser un service Unoconv présent sur un serveur dédié autre que celui de OSE
* L'export des services au format CSV est maintenant personnalisable * L'export des services au format CSV est maintenant personnalisable
* En ligne de commande, il est désormais possible d'indiquer dans quelle année universitaire et sous quel statut un intervenant sera créé, de même qu'un code intervenant
## Correction de bugs ## Correction de bugs
......
...@@ -12,6 +12,36 @@ $params = $c->getInputs([ ...@@ -12,6 +12,36 @@ $params = $c->getInputs([
]); ]);
$params['date-naissance'] = $params['date-naissance']->format('d/m/Y'); $params['date-naissance'] = $params['date-naissance']->format('d/m/Y');
$params = base64_encode(json_encode($params)); $params['params'] = ['creer-intervenant' => $params['creer-intervenant']];
unset($params['creer-intervenant']);
if ($params['params']['creer-intervenant']) {
if ($c->hasOption('code')) {
$params['params']['code'] = $c->getOption('code');
}
$bdd = $oa->getBdd();
$annee = $bdd->select("SELECT libelle FROM annee WHERE id = (SELECT valeur FROM parametre WHERE nom = 'annee')", [], $bdd::FETCH_ONE)['LIBELLE'];
$params['params']['annee'] = $c->getInput('annee', 'Année universitaire (' . $annee . ' par défaut, sinon entrez 2020 pour 2020/2021, etc.)');
if (!$c->hasOption('statut')) {
$statuts = $bdd->select("SELECT source_code CODE, libelle FROM statut_intervenant WHERE histo_destruction IS NULL AND source_code <> 'AUTRES' ORDER BY ordre");
$c->println('Statut de \'intervenant ("AUTRES" par défaut, sinon entrez le code parmi les propositions suivantes) :');
$maxCodeLength = 0;
foreach ($statuts as $statut) {
$sLen = strlen($statut['CODE']);
if ($sLen > $maxCodeLength) $maxCodeLength = $sLen;
}
foreach ($statuts as $statut) {
$c->print(' * ');
$c->print(str_pad($statut['CODE'], $maxCodeLength, ' '), $c::COLOR_CYAN);
$c->println(' ' . $statut['LIBELLE']);
}
}
$params['params']['statut'] = $c->getInput('statut');
}
$params = base64_encode(json_encode($params));
$oa->exec("creer-utilisateur --data=$params"); $oa->exec("creer-utilisateur --data=$params");
\ No newline at end of file
...@@ -51,6 +51,10 @@ Paramètres possibles : ...@@ -51,6 +51,10 @@ Paramètres possibles :
* ```login``` : Login * ```login``` : Login
* ```mot-de-passe``` : Mot de passe (6 caractères minimum) * ```mot-de-passe``` : Mot de passe (6 caractères minimum)
* ```creer-intervenant``` : Voulez-vous créer un intervenant pour cet utilisateur ? * ```creer-intervenant``` : Voulez-vous créer un intervenant pour cet utilisateur ?
* ```code``` : Code éventuel de l'intervenant
* ```annee``` : Année universitaire pour laquelle l'intervenant sera créé (ex : 2020 pour 2020/2021)
* ```statut``` : Code du statut de l'intervenant
Exemple de commande lancée avec des paramètres : Exemple de commande lancée avec des paramètres :
```bash ```bash
......
...@@ -10,7 +10,6 @@ use Application\Service\Traits\StructureServiceAwareTrait; ...@@ -10,7 +10,6 @@ use Application\Service\Traits\StructureServiceAwareTrait;
use UnicaenAuth\Service\Traits\UserServiceAwareTrait; use UnicaenAuth\Service\Traits\UserServiceAwareTrait;
class UtilisateurController extends BaseController class UtilisateurController extends BaseController
{ {
use ContextServiceAwareTrait; use ContextServiceAwareTrait;
...@@ -19,6 +18,7 @@ class UtilisateurController extends BaseController ...@@ -19,6 +18,7 @@ class UtilisateurController extends BaseController
use UserServiceAwareTrait; use UserServiceAwareTrait;
/** /**
* Traite les requêtes AJAX POST de sélection d'un profil utilisateur. * Traite les requêtes AJAX POST de sélection d'un profil utilisateur.
* La sélection est mémorisé en session par le service AuthUserContext. * La sélection est mémorisé en session par le service AuthUserContext.
...@@ -41,8 +41,7 @@ class UtilisateurController extends BaseController ...@@ -41,8 +41,7 @@ class UtilisateurController extends BaseController
$message = sprintf("Vous endossez à présent le profil utilisateur <strong>%s</strong>%s.", $message = sprintf("Vous endossez à présent le profil utilisateur <strong>%s</strong>%s.",
$role->getRoleName(), $role->getRoleName(),
$structure ? " pour la structure <strong>$structure</strong>" : null); $structure ? " pour la structure <strong>$structure</strong>" : null);
} } else {
else {
$message = sprintf("Vous endossez à présent le profil utilisateur <strong>%s</strong>.", $role); $message = sprintf("Vous endossez à présent le profil utilisateur <strong>%s</strong>.", $role);
if ($s = $role->getStructure()) { if ($s = $role->getStructure()) {
$this->getServiceContext()->setStructure($s); $this->getServiceContext()->setStructure($s);
...@@ -84,7 +83,7 @@ class UtilisateurController extends BaseController ...@@ -84,7 +83,7 @@ class UtilisateurController extends BaseController
$data->{'date-naissance'}, $data->{'date-naissance'},
$data->login, $data->login,
$data->{'mot-de-passe'}, $data->{'mot-de-passe'},
$data->{'creer-intervenant'} (array)$data->params
); );
} }
} }
\ No newline at end of file
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
namespace Application\Service; namespace Application\Service;
use Application\Entity\Db\Intervenant; use Application\Entity\Db\Intervenant;
use Application\Entity\Db\StatutIntervenant;
use Application\Entity\Db\Structure; use Application\Entity\Db\Structure;
use Application\Entity\Db\Periode; use Application\Entity\Db\Periode;
use Application\Entity\Db\Annee; use Application\Entity\Db\Annee;
use Application\Entity\Db\TypeIntervenant; use Application\Entity\Db\TypeIntervenant;
use Application\Service\Traits\AnneeServiceAwareTrait;
use Application\Service\Traits\MiseEnPaiementServiceAwareTrait; use Application\Service\Traits\MiseEnPaiementServiceAwareTrait;
use Application\Service\Traits\MiseEnPaiementIntervenantStructureServiceAwareTrait; use Application\Service\Traits\MiseEnPaiementIntervenantStructureServiceAwareTrait;
use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait;
...@@ -34,6 +36,7 @@ class IntervenantService extends AbstractEntityService ...@@ -34,6 +36,7 @@ class IntervenantService extends AbstractEntityService
use MiseEnPaiementIntervenantStructureServiceAwareTrait; use MiseEnPaiementIntervenantStructureServiceAwareTrait;
use WorkflowServiceAwareTrait; use WorkflowServiceAwareTrait;
use SourceServiceAwareTrait; use SourceServiceAwareTrait;
use AnneeServiceAwareTrait;
...@@ -325,31 +328,44 @@ class IntervenantService extends AbstractEntityService ...@@ -325,31 +328,44 @@ class IntervenantService extends AbstractEntityService
* @param string $nom * @param string $nom
* @param string $prenom * @param string $prenom
* @param \DateTime $dateNaissance * @param \DateTime $dateNaissance
* @param string|null $statut * @param array $params
*
* Params :
* code : null | string => généré si non fourni
* annee : null | int | Annee => Année en cours si non fournie
* statut : null | string | StatutIntervenant => AUTRES si non fourni, si string alors c'est le code du statut
* *
* @return Intervenant * @return Intervenant
*/ */
public function creerIntervenant(string $nom, string $prenom, \DateTime $dateNaissance, string $statut = null): Intervenant public function creerIntervenant(string $nom, string $prenom, \DateTime $dateNaissance, array $params = []): Intervenant
{ {
$code = uniqid('OSE'); if (!isset($params['code']) || empty($params['code'])) {
$params['code'] = uniqid('OSE');
}
if ($statut) { if (!isset($params['annee']) || empty($params['annee'])) {
$statutEntity = $this->getServiceStatutIntervenant()->getByCode($statut); $params['annee'] = $this->getServiceContext()->getAnnee();
} else { } elseif (!$params['annee'] instanceof Annee) {
$statutEntity = $this->getServiceStatutIntervenant()->getAutres(); $params['annee'] = $this->getServiceAnnee()->get($params['annee']);
}
if (!isset($params['statut']) || empty($params['statut'])) {
$params['statut'] = $this->getServiceStatutIntervenant()->getAutres();
} elseif (!$params['statut'] instanceof StatutIntervenant) {
$params['statut'] = $this->getServiceStatutIntervenant()->getByCode($params['statut']);
} }
$intervenant = new Intervenant; $intervenant = new Intervenant;
$intervenant->setAnnee($this->getServiceContext()->getAnnee());
$intervenant->setCode($code);
$intervenant->setCode($params['code']);
$intervenant->setSource($this->getServiceSource()->getOse()); $intervenant->setSource($this->getServiceSource()->getOse());
$intervenant->setSourceCode($code); $intervenant->setSourceCode($params['code']);
$intervenant->setNomUsuel($nom); $intervenant->setNomUsuel($nom);
$intervenant->setPrenom($prenom); $intervenant->setPrenom($prenom);
$intervenant->setDateNaissance($dateNaissance); $intervenant->setDateNaissance($dateNaissance);
$intervenant->setStatut($statutEntity); $intervenant->setAnnee($params['annee']);
$intervenant->setStatut($params['statut']);
$this->save($intervenant); $this->save($intervenant);
......
...@@ -117,17 +117,34 @@ class UtilisateurService extends AbstractEntityService ...@@ -117,17 +117,34 @@ class UtilisateurService extends AbstractEntityService
public function creerUtilisateur( string $nom, string $prenom, \DateTime $dateNaissance, string $login, string $motDePasse, bool $creerFicheIntervenant = true): Utilisateur /**
* @param string $nom
* @param string $prenom
* @param \DateTime $dateNaissance
* @param string $login
* @param string $motDePasse
* @param array $params
*
* Params :
* creer-intervenant : bool
* code : null | string => généré si non fourni
* annee : null | int | Annee => Année en cours si non fournie
* statut : null | string | StatutIntervenant => AUTRES si non fourni, si string alors c'est le code du statut
*
* @return Utilisateur
*/
public function creerUtilisateur(string $nom, string $prenom, \DateTime $dateNaissance, string $login, string $motDePasse, array $params = []): Utilisateur
{ {
if ($creerFicheIntervenant){ if (!isset($params['creer-intervenant']) || empty($params['creer-intervenant'])) {
$intervenant = $this->getServiceIntervenant()->creerIntervenant($nom, $prenom, $dateNaissance); $params['creer-intervenant'] = false;
} }
$utilisateur = new Utilisateur(); $utilisateur = new Utilisateur();
$utilisateur->setUsername($login); $utilisateur->setUsername($login);
$utilisateur->setDisplayName($prenom . ' ' . $nom); $utilisateur->setDisplayName($prenom . ' ' . $nom);
$utilisateur->setState(1); $utilisateur->setState(1);
if ($creerFicheIntervenant){ if ($params['creer-intervenant']) {
$intervenant = $this->getServiceIntervenant()->creerIntervenant($nom, $prenom, $dateNaissance, $params);
$utilisateur->setCode($intervenant->getCode()); $utilisateur->setCode($intervenant->getCode());
$intervenant->setUtilisateurCode($intervenant->getCode()); $intervenant->setUtilisateurCode($intervenant->getCode());
$this->getServiceIntervenant()->save($intervenant); $this->getServiceIntervenant()->save($intervenant);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment