Skip to content
Snippets Groups Projects
Commit f5b7270e authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Importation de compétence avec une interface + selection du référentiel

parent 93c54200
No related branches found
No related tags found
No related merge requests found
Showing
with 471 additions and 76 deletions
...@@ -4,9 +4,12 @@ namespace Element; ...@@ -4,9 +4,12 @@ namespace Element;
use Element\Controller\CompetenceImporterController; use Element\Controller\CompetenceImporterController;
use Element\Controller\CompetenceImporterControllerFactory; use Element\Controller\CompetenceImporterControllerFactory;
use UnicaenPrivilege\Guard\PrivilegeController; use Element\Form\CompetenceImportation\CompetenceImportationForm;
use Element\Form\CompetenceImportation\CompetenceImportationFormFactory;
use Element\Form\CompetenceImportation\CompetenceImportationHydrator;
use Element\Form\CompetenceImportation\CompetenceImportationHydratorFactory;
use Laminas\Router\Http\Literal; use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment; use UnicaenPrivilege\Guard\PrivilegeController;
return [ return [
'bjyauthorize' => [ 'bjyauthorize' => [
...@@ -52,10 +55,14 @@ return [ ...@@ -52,10 +55,14 @@ return [
], ],
], ],
'form_elements' => [ 'form_elements' => [
'factories' => [], 'factories' => [
CompetenceImportationForm::class => CompetenceImportationFormFactory::class,
],
], ],
'hydrators' => [ 'hydrators' => [
'factories' => [], 'factories' => [
CompetenceImportationHydrator::class => CompetenceImportationHydratorFactory::class,
],
] ]
]; ];
\ No newline at end of file
...@@ -2,80 +2,110 @@ ...@@ -2,80 +2,110 @@
namespace Element\Controller; namespace Element\Controller;
use Element\Entity\Db\Competence; use Element\Form\CompetenceImportation\CompetenceImportationFormAwareTrait;
use Element\Entity\Db\CompetenceTheme;
use Element\Service\Competence\CompetenceServiceAwareTrait; use Element\Service\Competence\CompetenceServiceAwareTrait;
use Element\Service\CompetenceReferentiel\CompetenceReferentielServiceAwareTrait;
use Element\Service\CompetenceTheme\CompetenceThemeServiceAwareTrait; use Element\Service\CompetenceTheme\CompetenceThemeServiceAwareTrait;
use Element\Service\CompetenceType\CompetenceTypeServiceAwareTrait; use Element\Service\CompetenceType\CompetenceTypeServiceAwareTrait;
use Laminas\Http\Response;
use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class CompetenceImporterController extends AbstractActionController { class CompetenceImporterController extends AbstractActionController
{
use CompetenceServiceAwareTrait; use CompetenceServiceAwareTrait;
use CompetenceReferentielServiceAwareTrait;
use CompetenceThemeServiceAwareTrait; use CompetenceThemeServiceAwareTrait;
use CompetenceTypeServiceAwareTrait; use CompetenceTypeServiceAwareTrait;
use CompetenceImportationFormAwareTrait;
/** IMPORT ET REMPLACEMENT ****************************************************************************************/ /** IMPORT ET REMPLACEMENT ****************************************************************************************/
public function importerAction() : Response public function importerAction(): ViewModel
{ {
$file_path = "/var/www/html/data/competence_referens3.csv"; $form = $this->getCompetenceImportationForm();
$content = file_get_contents($file_path); $form->setAttribute('action', $this->url()->fromRoute('competence-import', ['mode' => 'preview', 'path' => null], [], true));
$types = [
'Compétences comportementales' => $this->getCompetenceTypeService()->getCompetenceType(1), $request = $this->getRequest();
'Compétences opérationnelles' => $this->getCompetenceTypeService()->getCompetenceType(2), if ($request->isPost()) {
'Connaissances' => $this->getCompetenceTypeService()->getCompetenceType(3), $error = [];
]; $data = $request->getPost();
$file = $request->getFiles();
$lines = explode("\n", $content);
$nbLine = count($lines); $fichier_path = $file['fichier']['tmp_name'];
$mode = $data['mode'];
for($position = 1 ; $position < $nbLine; $position++) { $referentiel = $this->getCompetenceReferentielService()->getCompetenceReferentiel($data['referentiel']);
$line = $lines[$position];
if ($line !== '') { //reading
$depth = 0; $array = [];
for ($i = 0; $i < strlen($line) ; $i++) { if ($fichier_path === null or $fichier_path === '') {
if ($line[$i] === ';' and $depth === 0) $line[$i] = '|'; $error[] = "Aucun fichier !";
if ($line[$i] === "\"") { } else {
if ($depth === 0) $depth = 1; else $depth = 0; $handle = fopen($fichier_path, "r");
while ($content = fgetcsv($handle, 0, ";")) {
$array[] = $content;
} }
} }
$elements = explode("|", $line); $warning = [];
$domaine = $elements[0]; if ($mode === 'import' and empty($error)) {
$registre = $elements[1];
$libelle = $elements[2]; $typesLibelle = [];
$definition = $elements[3]; $themesLibelle = [];
$id = ((int)$elements[4]); foreach (array_slice($array, 1) as $line) {
$typesLibelle[$line[1]] = $line[1];
if ($libelle !== null and $libelle !== '') { $themesLibelle[$line[0]] = $line[0];
//Existe-t-elle ? }
$theme = $this->getCompetenceThemeService()->getCompetenceThemeByLibelle($domaine); $types = [];
foreach ($typesLibelle as $typeLibelle) {
$type = $this->getCompetenceTypeService()->getCompetenceTypeByLibelle($typeLibelle);
if ($type === null) {
$type = $this->getCompetenceTypeService()->createWith($typeLibelle);
}
$types[$typeLibelle] = $type;
}
$themes = [];
foreach ($themesLibelle as $themeLibelle) {
$theme = $this->getCompetenceThemeService()->getCompetenceThemeByLibelle($themeLibelle);
if ($theme === null) { if ($theme === null) {
$theme = new CompetenceTheme(); $theme = $this->getCompetenceThemeService()->createWith($themeLibelle);
$theme->setLibelle($domaine);
$this->getCompetenceThemeService()->create($theme);
} }
$competence = $this->getCompetenceService()->getCompetenceByIdSource("REFERENS3", $id); $themes[$themeLibelle] = $theme;
$new_competence = ($competence === null);
if ($new_competence) {
$competence = new Competence();
} }
$competence->setLibelle($libelle);
if ($definition !== 'Définition en attente' and $definition !== 'Définition non nécessaire') $competence->setDescription($definition); else $competence->setDescription(null); foreach (array_slice($array, 1) as $line) {
$competence->setType($types[$registre]); $competence = $this->getCompetenceService()->getCompetenceByRefentiel($referentiel, $line[4]);
$competence->setTheme($theme); if ($competence === null) {
$competence->setSource(Competence::SOURCE_REFERENS3); $this->getCompetenceService()->createWith($line[2], $line[3], $types[$line[1]], $themes[$line[0]], $referentiel, $line[4]);
$competence->setIdSource($id);
if ($new_competence) {
$this->getCompetenceService()->create($competence);
} else { } else {
$this->getCompetenceService()->update($competence); $this->getCompetenceService()->updateWith($competence, $line[2], $line[3], $types[$line[1]], $themes[$line[0]]);
}
} }
} }
if ($mode !== 'import') {
$title = "Importation d'un référentiel de compétences (Prévisualisation)";
}
if ($mode === 'import') {
$title = "Importation d'un référentiel de compétences (Importation)";
} }
return new ViewModel([
'title' => $title,
'fichier_path' => $fichier_path,
'form' => $form,
'mode' => $mode,
'error' => $error,
'warning' => $warning,
'array' => array_slice($array, 1),
]);
} }
return $this->redirect()->toRoute('element/competence',[],[], true); $vm = new ViewModel([
'title' => "Importation d'un référentiel de compétences",
'form' => $form,
]);
return $vm;
} }
} }
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
namespace Element\Controller; namespace Element\Controller;
use Element\Form\CompetenceImportation\CompetenceImportationForm;
use Element\Service\Competence\CompetenceService; use Element\Service\Competence\CompetenceService;
use Element\Service\CompetenceReferentiel\CompetenceReferentielService;
use Element\Service\CompetenceTheme\CompetenceThemeService; use Element\Service\CompetenceTheme\CompetenceThemeService;
use Element\Service\CompetenceType\CompetenceTypeService; use Element\Service\CompetenceType\CompetenceTypeService;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
...@@ -21,17 +23,24 @@ class CompetenceImporterControllerFactory { ...@@ -21,17 +23,24 @@ class CompetenceImporterControllerFactory {
{ {
/** /**
* @var CompetenceService $competenceService * @var CompetenceService $competenceService
* @var CompetenceReferentielService $competenceReferentielService
* @var CompetenceThemeService $competenceThemeService * @var CompetenceThemeService $competenceThemeService
* @var CompetenceTypeService $competenceTypeService * @var CompetenceTypeService $competenceTypeService
*/ */
$competenceService = $container->get(CompetenceService::class); $competenceService = $container->get(CompetenceService::class);
$competenceReferentielService = $container->get(CompetenceReferentielService::class);
$competenceThemeService = $container->get(CompetenceThemeService::class); $competenceThemeService = $container->get(CompetenceThemeService::class);
$competenceTypeService = $container->get(CompetenceTypeService::class); $competenceTypeService = $container->get(CompetenceTypeService::class);
/** @var CompetenceImportationForm $competenceImportationForm */
$competenceImportationForm = $container->get('FormElementManager')->get(CompetenceImportationForm::class);
$controller = new CompetenceImporterController(); $controller = new CompetenceImporterController();
$controller->setCompetenceService($competenceService); $controller->setCompetenceService($competenceService);
$controller->setCompetenceReferentielService($competenceReferentielService);
$controller->setCompetenceThemeService($competenceThemeService); $controller->setCompetenceThemeService($competenceThemeService);
$controller->setCompetenceTypeService($competenceTypeService); $controller->setCompetenceTypeService($competenceTypeService);
$controller->setCompetenceImportationForm($competenceImportationForm);
return $controller; return $controller;
} }
} }
\ No newline at end of file
<?php
namespace Element\Form\CompetenceImportation;
use Element\Service\CompetenceReferentiel\CompetenceReferentielServiceAwareTrait;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\File;
use Laminas\Form\Element\Select;
use Laminas\Form\Form;
use Laminas\InputFilter\Factory;
class CompetenceImportationForm extends Form {
use CompetenceReferentielServiceAwareTrait;
public function init(): void
{
//file CSV
$this->add([
'type' => File::class,
'name' => 'fichier',
'options' => [
'label' => 'Fichier CSV contenant les compétences <span class="icon icon-asterisque" title="Champ obligatoire"></span> :',
'label_options' => [ 'disable_html_escape' => true, ],
],
]);
//referentiel
$this->add([
'type' => Select::class,
'name' => 'referentiel',
'options' => [
'label' => "Référentiel de compétence :",
'empty_option' => "Sélectionner un référentiel pour la compétence ...",
'value_options' => $this->getCompetenceReferentielService()->getCompetencesReferentielsAsOptions(),
],
'attributes' => [
'id' => 'referentiel',
'class' => 'bootstrap-selectpicker show-tick',
'data-live-search' => 'true',
],
]);
//mode
$this->add([
'type' => Select::class,
'name' => 'mode',
'options' => [
'label' => 'Mode <span class="icon icon-asterisque" title="Champ obligatoire"></span> :',
'label_options' => [ 'disable_html_escape' => true, ],
'value_options' => [
'preview' => "Prévisualisation",
'import' => "Importation",
]
],
'attributes' => [
'id' => 'mode',
],
]);
//Submit
$this->add([
'type' => Button::class,
'name' => 'creer',
'options' => [
'label' => 'Traiter le ficher',
'label_options' => [ 'disable_html_escape' => true, ],
],
'attributes' => [
'type' => 'submit',
'class' => 'btn btn-primary',
],
]);
$this->setInputFilter((new Factory())->createInputFilter([
'fichier' => [ 'required' => true, ],
'referentiel' => ['required' => true, ],
'mode' => ['required' => true, ],
]));
}
}
\ No newline at end of file
<?php
namespace Element\Form\CompetenceImportation;
trait CompetenceImportationFormAwareTrait {
private CompetenceImportationForm $competenceImportationForm;
public function getCompetenceImportationForm(): CompetenceImportationForm
{
return $this->competenceImportationForm;
}
public function setCompetenceImportationForm(CompetenceImportationForm $competenceImportationForm): void
{
$this->competenceImportationForm = $competenceImportationForm;
}
}
\ No newline at end of file
<?php
namespace Element\Form\CompetenceImportation;
use Element\Service\CompetenceReferentiel\CompetenceReferentielService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
class CompetenceImportationFormFactory {
/**
* @param ContainerInterface $container
* @return CompetenceImportationForm
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container) : CompetenceImportationForm
{
/** @var CompetenceReferentielService $competenceReferentielService */
$competenceReferentielService = $container->get(CompetenceReferentielService::class);
/** @var CompetenceImportationHydrator $hydrator */
$hydrator = $container->get('HydratorManager')->get(CompetenceImportationHydrator::class);
$form = new CompetenceImportationForm();
$form->setCompetenceReferentielService($competenceReferentielService);
$form->setHydrator($hydrator);
return $form;
}
}
\ No newline at end of file
<?php
namespace Element\Form\CompetenceImportation;
use Laminas\Hydrator\HydratorInterface;
class CompetenceImportationHydrator implements HydratorInterface
{
public function extract(object $object): array
{
return [];
}
public function hydrate(array $data, object $object) : object
{
return $object;
}
}
<?php
namespace Element\Form\CompetenceImportation;
use Psr\Container\ContainerInterface;
class CompetenceImportationHydratorFactory
{
public function __invoke(ContainerInterface $container) : CompetenceImportationHydrator
{
return new CompetenceImportationHydrator();
}
}
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
namespace Element\Service\Competence; namespace Element\Service\Competence;
use Doctrine\ORM\Exception\NotSupported;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Element\Entity\Db\Competence; use Element\Entity\Db\Competence;
use Element\Entity\Db\CompetenceReferentiel;
use Element\Entity\Db\CompetenceTheme;
use Element\Entity\Db\CompetenceType;
use Element\Service\CompetenceTheme\CompetenceThemeServiceAwareTrait; use Element\Service\CompetenceTheme\CompetenceThemeServiceAwareTrait;
use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenApp\Service\EntityManagerAwareTrait;
...@@ -75,10 +79,13 @@ class CompetenceService { ...@@ -75,10 +79,13 @@ class CompetenceService {
public function createQueryBuilder() : QueryBuilder public function createQueryBuilder() : QueryBuilder
{ {
try {
$qb = $this->getEntityManager()->getRepository(Competence::class)->createQueryBuilder('competence') $qb = $this->getEntityManager()->getRepository(Competence::class)->createQueryBuilder('competence')
->addSelect('type')->leftJoin('competence.type', 'type') ->addSelect('type')->leftJoin('competence.type', 'type')
->addSelect('theme')->leftJoin('competence.theme', 'theme') ->addSelect('theme')->leftJoin('competence.theme', 'theme');
; } catch (NotSupported $e) {
throw new RuntimeException("Un problème est survenu lors dela création du QueryBuilder de [".Competence::class."]",0,$e);
}
return $qb; return $qb;
} }
...@@ -176,8 +183,63 @@ class CompetenceService { ...@@ -176,8 +183,63 @@ class CompetenceService {
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
throw new RuntimeException("Plusieurs compétences partagent le même id source [".$source."-".$id."]"); throw new RuntimeException("Plusieurs compétences partagent le même id source [".$source."-".$id."]",0,$e);
}
return $result;
}
public function getCompetenceByRefentiel(CompetenceReferentiel $referentiel, string $id)
{
$qb = $this->createQueryBuilder()
->andWhere('competence.referentiel = :referentiel')
->setParameter('referentiel', $referentiel)
->andWhere('competence.idSource = :id')
->setParameter('id', $id)
;
try {
$result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) {
throw new RuntimeException("Plusieurs compétences partagent le même id referentiel [".$referentiel->getId()."-".$id."]",0,$e);
} }
return $result; return $result;
} }
/** FACADE ****************************************************************************************************/
public function createWith(string $libelle, ?string $description, ?CompetenceType $type, ?CompetenceTheme $theme, CompetenceReferentiel $referentiel, string $id) : Competence
{
$competence = new Competence();
$competence->setLibelle($libelle);
$competence->setDescription($description);
$competence->setType($type);
$competence->setTheme($theme);
$competence->setReferentiel($referentiel);
$competence->setIdSource($id);
$this->create($competence);
return $competence;
}
public function updateWith(Competence $competence, string $libelle, ?string $description, ?CompetenceType $type, ?CompetenceTheme $theme) : Competence
{
$wasModified = false;
if ($competence->getLibelle() !== $libelle) {
$competence->setLibelle($libelle);
$wasModified = true;
}
if ($competence->getDescription() !== $description) {
$competence->setDescription($description);
$wasModified = true;
}
if ($competence->getType() !== $type) {
$competence->setType($type);
$wasModified = true;
}
if ($competence->getTheme() !== $theme) {
$competence->setTheme($theme);
$wasModified = true;
}
if ($wasModified) $this->update($competence);
return $competence;
}
} }
\ No newline at end of file
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
namespace Element\Service\CompetenceTheme; namespace Element\Service\CompetenceTheme;
use Doctrine\ORM\Exception\NotSupported;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\QueryBuilder;
use Element\Entity\Db\CompetenceTheme; use Element\Entity\Db\CompetenceTheme;
use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenApp\Service\EntityManagerAwareTrait;
...@@ -90,6 +92,17 @@ class CompetenceThemeService { ...@@ -90,6 +92,17 @@ class CompetenceThemeService {
/** REQUETE *******************************************************************************************************/ /** REQUETE *******************************************************************************************************/
public function createQueryBuilder() : QueryBuilder
{
try {
$qb = $this->getEntityManager()->getRepository(CompetenceTheme::class)->createQueryBuilder('theme')
->addSelect('competence')->leftJoin('theme.competences', 'competence');
} catch (NotSupported $e) {
throw new RuntimeException("Un problème est survenu lors de la creation que QueryBuilder de [".QueryBuilder::class."]",0, $e);
}
return $qb;
}
/** /**
* @param string $champ * @param string $champ
* @param string $order * @param string $order
...@@ -97,8 +110,7 @@ class CompetenceThemeService { ...@@ -97,8 +110,7 @@ class CompetenceThemeService {
*/ */
public function getCompetencesThemes(string $champ = 'libelle', string $order = 'ASC') : array public function getCompetencesThemes(string $champ = 'libelle', string $order = 'ASC') : array
{ {
$qb = $this->getEntityManager()->getRepository(CompetenceTheme::class)->createQueryBuilder('theme') $qb = $this->createQueryBuilder()
->addSelect('competence')->leftJoin('theme.competences', 'competence')
->orderBy('theme.'.$champ, $order) ->orderBy('theme.'.$champ, $order)
; ;
$result = $qb->getQuery()->getResult(); $result = $qb->getQuery()->getResult();
...@@ -126,9 +138,8 @@ class CompetenceThemeService { ...@@ -126,9 +138,8 @@ class CompetenceThemeService {
*/ */
public function getCompetenceTheme(?int $id) : ?CompetenceTheme public function getCompetenceTheme(?int $id) : ?CompetenceTheme
{ {
$qb = $this->getEntityManager()->getRepository(CompetenceTheme::class)->createQueryBuilder('theme') $qb = $this->createQueryBuilder()
->andWhere('theme.id = :id') ->andWhere('theme.id = :id') ->setParameter('id', $id)
->setParameter('id', $id)
; ;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
...@@ -156,18 +167,26 @@ class CompetenceThemeService { ...@@ -156,18 +167,26 @@ class CompetenceThemeService {
*/ */
public function getCompetenceThemeByLibelle(string $libelle) : ?CompetenceTheme public function getCompetenceThemeByLibelle(string $libelle) : ?CompetenceTheme
{ {
$qb = $this->getEntityManager()->getRepository(CompetenceTheme::class)->createQueryBuilder('theme') $qb = $this->createQueryBuilder()
->andWhere('theme.libelle = :libelle') ->andWhere('theme.libelle = :libelle') ->setParameter('libelle', $libelle)
->setParameter('libelle', $libelle)
; ;
try { try {
$result = $qb->getQuery()->getOneOrNullResult(); $result = $qb->getQuery()->getOneOrNullResult();
} catch (NonUniqueResultException $e) { } catch (NonUniqueResultException $e) {
throw new RuntimeException('Plusieurs CompetenceTheme partagent le même libellé ['.$libelle.']'); throw new RuntimeException('Plusieurs CompetenceTheme partagent le même libellé ['.$libelle.']',0,$e);
} }
return $result; return $result;
} }
/** FACADE ***********************************************************************/
public function createWith(?string $libelle) : CompetenceTheme
{
$theme = new CompetenceTheme();
$theme->setLibelle($libelle);
$this->create($theme);
return $theme;
}
} }
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace Element\Service\CompetenceType; namespace Element\Service\CompetenceType;
use Doctrine\ORM\Exception\NotSupported;
use Doctrine\ORM\QueryBuilder;
use Element\Entity\Db\CompetenceType; use Element\Entity\Db\CompetenceType;
use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Exception\ORMException;
...@@ -91,6 +93,18 @@ class CompetenceTypeService ...@@ -91,6 +93,18 @@ class CompetenceTypeService
/** REQUETE *******************************************************************************************************/ /** REQUETE *******************************************************************************************************/
public function createQueryBuilder() : QueryBuilder
{
try {
$qb = $this->getEntityManager()->getRepository(CompetenceType::class)->createQueryBuilder('type')
->addSelect('competence')->leftJoin('type.competences', 'competence')
;
} catch (NotSupported $e) {
throw new RuntimeException("Un problème est survenu lors de la création du QueryBuilder de [".CompetenceType::class."]",0,$e);
}
return $qb;
}
/** /**
* @param string $champ * @param string $champ
* @param string $order * @param string $order
...@@ -98,8 +112,7 @@ class CompetenceTypeService ...@@ -98,8 +112,7 @@ class CompetenceTypeService
*/ */
public function getCompetencesTypes(string $champ = 'libelle', string $order = 'ASC') : array public function getCompetencesTypes(string $champ = 'libelle', string $order = 'ASC') : array
{ {
$qb = $this->getEntityManager()->getRepository(CompetenceType::class)->createQueryBuilder('type') $qb = $this->createQueryBuilder()
->addSelect('competence')->leftJoin('type.competences', 'competence')
->orderBy('type.'.$champ, $order) ->orderBy('type.'.$champ, $order)
; ;
$result = $qb->getQuery()->getResult(); $result = $qb->getQuery()->getResult();
...@@ -127,7 +140,7 @@ class CompetenceTypeService ...@@ -127,7 +140,7 @@ class CompetenceTypeService
*/ */
public function getCompetenceType(?int $id) : ?CompetenceType public function getCompetenceType(?int $id) : ?CompetenceType
{ {
$qb = $this->getEntityManager()->getRepository(CompetenceType::class)->createQueryBuilder('type') $qb = $this->createQueryBuilder()
->andWhere('type.id = :id') ->andWhere('type.id = :id')
->setParameter('id', $id) ->setParameter('id', $id)
; ;
...@@ -150,4 +163,28 @@ class CompetenceTypeService ...@@ -150,4 +163,28 @@ class CompetenceTypeService
$type = $this->getCompetenceType($id); $type = $this->getCompetenceType($id);
return $type; return $type;
} }
public function getCompetenceTypeByLibelle(string $libelle)
{
$qb = $this->createQueryBuilder()
->andWhere('type.libelle = :libelle')
->setParameter('libelle', $libelle)
;
try {
$result = $qb->getQuery()->getOneOrNullResult();
} catch(NonUniqueResultException $e) {
throw new RuntimeException("Plusieurs CompetenceType partagent le même id [".$libelle."]", $e);
}
return $result;
}
/** FACADE ***********************************************************************/
public function createWith(?string $libelle) : CompetenceType
{
$type = new CompetenceType();
$type->setLibelle($libelle);
$this->create($type);
return $type;
}
} }
<?php
/**
* @see \Element\Controller\CompetenceImporterController::importerAction()
* @var string $title
* @var CompetenceImportationForm $form
* @var string[] $error
* @var string[] $warning
* @var Agent[] $agents
* @var array $array
*/
use Application\Entity\Db\Agent;
use Element\Form\CompetenceImportation\CompetenceImportationForm;
?>
<?php echo $this->form($form); ?>
<?php if (!empty($error)) : ?>
<div class="alert alert-danger">
<span class="icon icon-attention"></span>
<?php echo implode('<br>', $error); ?>
</div>
<?php else : ?>
<?php if (!empty($warning)) : ?>
<div class="alert alert-warning">
<ul>
<?php foreach ($warning as $item) : ?>
<li> <?php echo $item; ?> </li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php if (isset($array)) : ?>
<table class="table table-condensed">
<thead>
<tr>
<th> Compétence </th>
<th> Type</th>
<th> Thèmes</th>
<th style='width:50%;'> Description </th>
</tr>
</thead>
<tbody>
<?php foreach ($array as $line) : ?>
<tr>
<td> <?php echo $line[2]; ?> </td>
<td> <?php echo $line[1]; ?> </td>
<td> <?php echo $line[0]; ?> </td>
<td> <?php echo $line[3]; ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php endif; ?>
...@@ -47,6 +47,12 @@ $this->headTitle("Liste des compétences"); ...@@ -47,6 +47,12 @@ $this->headTitle("Liste des compétences");
<span class="icon icon-ajouter"></span> <span class="icon icon-ajouter"></span>
Ajouter une compétence Ajouter une compétence
</a> </a>
<?php /** @see \Element\Controller\CompetenceImporterController::importerAction() */ ?>
<a href="<?php echo $this->url('competence-import', [], [], true); ?>"
class="btn btn-primary ajax-modal" >
<span class="icon icon-ajouter"></span>
Importer un référentiel
</a>
<?php endif; ?> <?php endif; ?>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment