Commit 81c54327 authored by lecluse's avatar lecluse
Browse files

#10705

parent 13ea4eb3
......@@ -23,14 +23,13 @@ $sep->forcerTauxMixite($ep, 0.5, 0.5,0);
//var_dump($ep);
$epid = 45788;
/* @var \Application\Entity\Db\ElementPedagogique $ep */
$ep = $sl->get('applicationElementPedagogique')->get($epid);
$fn = '/home/laurent/test/test.txt';
$data = 'salut';
$tis = $ep->getTypesInterventionPossibles();
mkdir( dirname($fn));
chmod( dirname($fn), 0777);
$r = file_put_contents($fn, $data);
chmod($fn, 0777);
var_dump(realpath($fn));
\ No newline at end of file
foreach( $tis as $ti ){
var_dump($ti->getCode());
}
\ No newline at end of file
......@@ -91,6 +91,18 @@ return [
'defaults' => ['action' => 'getPeriode'],
],
],
'volume-horaire' => [
'type' => 'Segment',
'options' => [
'route' => '/volume-horaire/:elementPedagogique',
'constraints' => [
'elementPedagogique' => '[0-9]*',
],
'defaults' => [
'action' => 'volume-horaire',
],
],
],
],
],
'etape' => [
......@@ -231,6 +243,14 @@ return [
Privileges::ODF_ELEMENT_VISUALISATION,
Privileges::ENSEIGNEMENT_EDITION,
],
],
[
'controller' => 'Application\Controller\OffreFormation\ElementPedagogique',
'action' => ['volume-horaire'],
'privileges' => [
Privileges::ODF_ELEMENT_VH_VISUALISATION,
Privileges::ODF_ELEMENT_VH_EDITION,
],
],
[
......@@ -264,6 +284,7 @@ return [
'Etape' => [],
'CentreCoutEp' => [],
'ElementModulateur' => [],
'VolumeHoraireEns' => [],
],
],
'rule_providers' => [
......@@ -294,6 +315,11 @@ return [
'resources' => ['Etape', 'Structure', 'ElementPedagogique'],
'assertion' => 'AssertionOffreDeFormation',
],
[
'privileges' => Privileges::ODF_ELEMENT_VH_EDITION,
'resources' => ['Etape', 'Structure', 'ElementPedagogique','VolumeHoraireEns','TypeIntervention'],
'assertion' => 'AssertionOffreDeFormation',
],
],
],
],
......@@ -303,9 +329,11 @@ return [
'Application\Controller\OffreFormation' => Controller\OffreFormationController::class,
'Application\Controller\OffreFormation\Etape' => Controller\OffreFormation\EtapeController::class,
'Application\Controller\OffreFormation\Modulateur' => Controller\OffreFormation\ModulateurController::class,
'Application\Controller\OffreFormation\ElementPedagogique' => Controller\OffreFormation\ElementPedagogiqueController::class,
'Application\Controller\OffreFormation\EtapeCentreCout' => Controller\OffreFormation\EtapeCentreCoutController::class,
],
'factories' => [
'Application\Controller\OffreFormation\ElementPedagogique' => Controller\OffreFormation\Factory\ElementPedagogiqueControllerFactory::class,
],
],
'service_manager' => [
'invokables' => [
......@@ -335,6 +363,9 @@ return [
Form\OffreFormation\TauxMixite\TauxMixiteForm::class => Form\OffreFormation\TauxMixite\TauxMixiteForm::class,
Form\OffreFormation\TauxMixite\TauxMixiteFieldset::class => Form\OffreFormation\TauxMixite\TauxMixiteFieldset::class,
],
'factories' => [
Form\OffreFormation\VolumeHoraireEns::class => Form\OffreFormation\Factory\VolumeHoraireEnsFormFactory::class,
],
],
'view_helpers' => [
'invokables' => [
......
......@@ -111,6 +111,11 @@ return [
],
],
'bjyauthorize' => [
'resource_providers' => [
'BjyAuthorize\Provider\Resource\Config' => [
'TypeIntervention' => [],
],
],
'guards' => [
PrivilegeController::class => [
[
......
......@@ -8,7 +8,7 @@ use UnicaenAuth\Guard\PrivilegeController;
return [
'router' => [
'routes' => [
'volume-horaire' => [
'volume-horaire' => [
'type' => 'Literal',
'options' => [
'route' => '/volume-horaire',
......@@ -68,26 +68,27 @@ return [
],
'controllers' => [
'invokables' => [
'Application\Controller\VolumeHoraire' => Controller\VolumeHoraireController::class,
'Application\Controller\VolumeHoraire' => Controller\VolumeHoraireController::class,
],
],
'service_manager' => [
'invokables' => [
'ApplicationVolumeHoraire' => Service\VolumeHoraire::class,
'ApplicationVolumeHoraireReferentiel' => Service\VolumeHoraireReferentiel::class,
'ApplicationTypeVolumeHoraire' => Service\TypeVolumeHoraire::class,
'ApplicationEtatVolumeHoraire' => Service\EtatVolumeHoraire::class,
'ApplicationVolumeHoraire' => Service\VolumeHoraire::class,
'ApplicationVolumeHoraireEns' => Service\VolumeHoraireEnsService::class,
'ApplicationVolumeHoraireReferentiel' => Service\VolumeHoraireReferentiel::class,
'ApplicationTypeVolumeHoraire' => Service\TypeVolumeHoraire::class,
'ApplicationEtatVolumeHoraire' => Service\EtatVolumeHoraire::class,
],
],
'view_helpers' => [
'invokables' => [
'volumeHoraireListe' => View\Helper\VolumeHoraire\Liste::class,
'volumeHoraireListe' => View\Helper\VolumeHoraire\Liste::class,
],
],
'form_elements' => [
'invokables' => [
'VolumeHoraireSaisie' => Form\VolumeHoraire\Saisie::class,
'VolumeHoraireSaisieMultipleFieldset' => Form\VolumeHoraire\SaisieMultipleFieldset::class, // Nécessite plusieurs instances
'VolumeHoraireSaisie' => Form\VolumeHoraire\Saisie::class,
'VolumeHoraireSaisieMultipleFieldset' => Form\VolumeHoraire\SaisieMultipleFieldset::class, // Nécessite plusieurs instances
],
],
];
......@@ -2,6 +2,8 @@
namespace Application\Assertion;
use Application\Entity\Db\TypeIntervention;
use Application\Entity\Db\VolumeHoraireEns;
use Application\Provider\Privilege\Privileges;
use Application\Entity\Db\CentreCoutEp;
use Application\Entity\Db\ElementModulateur;
......@@ -41,6 +43,8 @@ class OffreDeFormationAssertion extends AbstractAssertion
return $this->assertElementPedagogiqueSaisieModulateurs($role, $entity);
case Privileges::ODF_TAUX_MIXITE_EDITION:
return $this->assertElementPedagogiqueSaisieTauxMixite($role, $entity);
case Privileges::ODF_ELEMENT_VH_EDITION:
return $this->assertElementPedagogiqueSaisieVH($role, $entity);
}
break;
case $entity instanceof Etape:
......@@ -53,6 +57,8 @@ class OffreDeFormationAssertion extends AbstractAssertion
return $this->assertEtapeSaisieModulateurs($role, $entity);
case Privileges::ODF_TAUX_MIXITE_EDITION:
return $this->assertEtapeSaisieTauxMixite($role, $entity);
case Privileges::ODF_ELEMENT_VH_EDITION:
return $this->assertEtapeSaisieVH($role, $entity);
}
break;
case $entity instanceof Structure:
......@@ -62,6 +68,7 @@ class OffreDeFormationAssertion extends AbstractAssertion
case Privileges::ODF_CENTRES_COUT_EDITION:
case Privileges::ODF_MODULATEURS_EDITION:
case Privileges::ODF_TAUX_MIXITE_EDITION:
case Privileges::ODF_ELEMENT_VH_EDITION:
return $this->assertStructureSaisie($role, $entity);
}
break;
......@@ -77,6 +84,18 @@ class OffreDeFormationAssertion extends AbstractAssertion
return $this->assertElementModulateurSaisieModulateurs($role, $entity);
}
break;
case $entity instanceof VolumeHoraireEns:
switch ($privilege) {
case Privileges::ODF_ELEMENT_VH_EDITION:
return $this->assertVolumeHoraireEnsSaisieVH($role, $entity);
}
break;
case $entity instanceof TypeIntervention:
switch ($privilege) {
case Privileges::ODF_ELEMENT_VH_EDITION:
return $this->assertTypeInterventionSaisieVH($role, $entity);
}
break;
}
return true;
......@@ -150,6 +169,40 @@ class OffreDeFormationAssertion extends AbstractAssertion
/* ---- Volumes horaires d'enseigneement ---- */
protected function assertEtapeSaisieVH(Role $role, Etape $etape)
{
return $this->assertStructureSaisie($role, $etape->getStructure())
&& $etape->getElementPedagogique()->count() > 0;
}
protected function assertElementPedagogiqueSaisieVH(Role $role, ElementPedagogique $elementPedagogique)
{
return $this->assertStructureSaisie($role, $elementPedagogique->getStructure());
}
protected function assertTypeInterventionSaisieVH(Role $role, TypeIntervention $typeIntervention)
{
return true;
}
protected function assertVolumeHoraireEnsSaisieVH(Role $role, VolumeHoraireEns $volumeHoraireEns)
{
return $this->asserts([
$volumeHoraireEns->getSource() ? $this->assertSourceSaisie($volumeHoraireEns->getSource()) : true,
$volumeHoraireEns->getElementPedagogique() ? $this->assertElementPedagogiqueSaisieVH($role, $volumeHoraireEns->getElementPedagogique()) : true,
$volumeHoraireEns->getTypeIntervention() ? $this->assertTypeInterventionSaisieVH($role, $volumeHoraireEns->getTypeIntervention()) : true,
]);
}
/* ---- Modulateurs ---- */
protected function assertEtapeSaisieModulateurs(Role $role, Etape $etape)
{
......
......@@ -3,10 +3,17 @@
namespace Application\Controller\OffreFormation;
use Application\Controller\AbstractController;
use Application\Entity\Db\ElementPedagogique;
use Application\Entity\Db\VolumeHoraireEns;
use Application\Filter\FloatFromString;
use Application\Form\OffreFormation\Traits\ElementPedagogiqueSaisieAwareTrait;
use Application\Exception\DbException;
use Application\Form\OffreFormation\Traits\VolumeHoraireEnsFormAwareTrait;
use Application\Provider\Privilege\Privileges;
use Application\Service\Traits\ElementPedagogiqueAwareTrait;
use Application\Service\Traits\ContextAwareTrait;
use Application\Service\Traits\VolumeHoraireEnsServiceAwareTrait;
/**
* Description of ElementPedagogiqueController
......@@ -18,6 +25,8 @@ class ElementPedagogiqueController extends AbstractController
use ElementPedagogiqueAwareTrait;
use ContextAwareTrait;
use ElementPedagogiqueSaisieAwareTrait;
use VolumeHoraireEnsFormAwareTrait;
use VolumeHoraireEnsServiceAwareTrait;
......@@ -28,7 +37,7 @@ class ElementPedagogiqueController extends AbstractController
\Application\Entity\Db\VolumeHoraire::class,
]);
$element = $this->getEvent()->getParam('elementPedagogique');
$title = "Enseignement";
$title = $element->getLibelle() . ' (' . $element->getCode() . ')';
return compact('element', 'title');
}
......@@ -75,8 +84,8 @@ class ElementPedagogiqueController extends AbstractController
throw new \RuntimeException('L\'identifiant n\'est pas bon ou n\'a pas été fourni');
}
$title = "Suppression d'enseignement";
$form = $this->makeFormSupprimer(function()use($element){
$title = "Suppression d'enseignement";
$form = $this->makeFormSupprimer(function () use ($element) {
$this->getServiceElementPedagogique()->delete($element);
});
......@@ -143,7 +152,7 @@ class ElementPedagogiqueController extends AbstractController
if (!$etape) {
$extra .= sprintf('<span class="element-rech etape" title="%s">%s</span>', "Formation", $item['LIBELLE_ETAPE']);
}
$extra .= "Année" !== $item['LIBELLE_PE'] ? sprintf('<span class="element-rech periode" title="%s">%s</span>', "Période", $item['LIBELLE_PE']) : null;
$extra .= "Année" !== $item['LIBELLE_PE'] ? sprintf('<span class="element-rech periode" title="%s">%s</span>', "Période", $item['LIBELLE_PE']) : null;
$template = sprintf('<span class="element-rech extra">{extra}</span><span class="element-rech element" title="%s">{label}</span>', "Enseignement");
$result[$item['ID']] = [
'id' => $item['ID'],
......@@ -174,4 +183,64 @@ class ElementPedagogiqueController extends AbstractController
return new \Zend\View\Model\JsonModel($result);
}
public function volumeHoraireAction()
{
$this->em()->getFilters()->enable('historique')->init([
\Application\Entity\Db\VolumeHoraireEns::class,
]);
$title = 'Volumes horaires';
/** @var ElementPedagogique $element */
$element = $this->getEvent()->getParam('elementPedagogique');
$ev = $element->getVolumeHoraireEns();
$existsVhes = [];
foreach ($ev as $vhe) {
$existsVhes[$vhe->getTypeIntervention()->getId()] = $vhe;
}
$saisie = $this->params()->fromPost('vhes');
$tis = $element->getTypesInterventionPossibles();
foreach ($tis as $typeIntervention) {
if (!isset($existsVhes[$typeIntervention->getId()])) {
$vhe = $this->getServiceVolumeHoraireEns()->newEntity($element, $typeIntervention);
} else {
$vhe = $existsVhes[$typeIntervention->getId()];
}
if ($this->isAllowed($vhe, Privileges::ODF_ELEMENT_VH_EDITION)) {
if (isset($saisie[$vhe->getTypeIntervention()->getId()]['heures'])) {
$heures = FloatFromString::run($saisie[$vhe->getTypeIntervention()->getId()]['heures']);
} else {
$heures = null;
}
if (isset($saisie[$vhe->getTypeIntervention()->getId()]['groupes'])) {
$groupes = FloatFromString::run($saisie[$vhe->getTypeIntervention()->getId()]['groupes']);
} else {
$groupes = null;
}
try {
$this->getServiceVolumeHoraireEns()->changeHeuresGroupes($vhe, $heures, $groupes);
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
}
}
if (!$vhe->estNonHistorise()){
$vhe = $this->getServiceVolumeHoraireEns()->newEntity($element, $typeIntervention);
}
$vhes[$typeIntervention->getId()] = $vhe;
}
$form = $this->getFormOffreFormationVolumeHoraireEns();
$form->setAttribute('action', $this->url()->fromRoute('of/element/volume-horaire', ['elementPedagogique' => $element->getId()]));
$form->build($vhes);
return compact('title', 'vhes', 'form');
}
}
......@@ -95,7 +95,7 @@ class EtapeController extends AbstractController
ElementPedagogique::class,
]);
$etape = $this->getEvent()->getParam('etape');
$title = 'Formation';
$title = $etape.' ('.$etape->getCode().')';
$serviceEtape = $this->getServiceEtape();
return compact('etape', 'title', 'serviceEtape');
......
<?php
namespace Application\Controller\OffreFormation\Factory;
use Application\Form\OffreFormation\VolumeHoraireEnsForm;
use Zend\Mvc\Controller\ControllerManager as ContainerInterface;
use Application\Controller\OffreFormation\ElementPedagogiqueController;
/**
* Description of ElementPedagogiqueControllerFactory
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class ElementPedagogiqueControllerFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return ElementPedagogiqueController
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
$container = $container->getServiceLocator();
$controller = new ElementPedagogiqueController;
$controller->setServiceLocator($container);
$controller->setFormOffreFormationVolumeHoraireEns($container->get('FormElementManager')->get(VolumeHoraireEnsForm::class));
return $controller;
}
}
\ No newline at end of file
......@@ -110,6 +110,11 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
*/
protected $elementModulateur;
/**
* @var \Doctrine\Common\Collections\Collection
*/
protected $volumeHoraireEns;
/**
* haschanged
*
......@@ -576,6 +581,46 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
/**
* Add volumeHoraireEns
*
* @param VolumeHoraireEns $volumeHoraireEns
*
* @return ElementPedagogique
*/
public function addVolumeHoraireEns(VolumeHoraireEns $volumeHoraireEns)
{
$this->volumeHoraireEns[] = $volumeHoraireEns;
return $this;
}
/**
* Remove volumeHoraireEns
*
* @param VolumeHoraireEns $volumeHoraireEns
*/
public function removeVolumeHoraireEns(VolumeHoraireEns $volumeHoraireEns)
{
$this->volumeHoraireEns->removeElement($volumeHoraireEns);
}
/**
* Get volumeHoraireEns
*
* @return \Doctrine\Common\Collections\Collection|VolumeHoraireEns[]
*/
public function getVolumeHoraireEns()
{
return $this->volumeHoraireEns;
}
/**
* Add service
*
......@@ -728,6 +773,26 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
/**
* @return TypeIntervention[]
*/
public function getTypesInterventionPossibles()
{
if (!$this->getId()) return [];
$sql = 'SELECT type_intervention_id FROM V_ELEMENT_TYPE_INTERV_POSSIBLE WHERE element_pedagogique_id = :element';
$res = $this->getEntityManager()->getConnection()->fetchAll($sql, ['element' => $this->getId()]);
$ids = [];
foreach( $res as $r ){
$ids[] = (int)$r['TYPE_INTERVENTION_ID'];
}
return $this->getEntityManager()->getRepository(TypeIntervention::class)->findBy(['id' => $ids], ['ordre' => 'ASC']);
}
/**
* Returns the string identifier of the Resource
*
......
......@@ -88,6 +88,11 @@
<cascade-all/>
</cascade>
</one-to-many>
<one-to-many field="volumeHoraireEns" target-entity="Application\Entity\Db\VolumeHoraireEns" mapped-by="elementPedagogique">
<cascade>
<cascade-all/>
</cascade>
</one-to-many>
<many-to-many field="typeIntervention" target-entity="Application\Entity\Db\TypeIntervention">
<join-table name="V_ELEMENT_TYPE_INTERVENTION">
<join-columns>
......
......@@ -17,6 +17,7 @@
<generator strategy="SEQUENCE"/>
</id>
<field name="heures" type="float" column="HEURES" precision="126" scale="0" nullable="false"/>
<field name="groupes" type="float" column="GROUPES" precision="126" scale="0" nullable="true"/>
<field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
<field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
<field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/>
......
......@@ -4,11 +4,12 @@ namespace Application\Entity\Db;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use Zend\Permissions\Acl\Resource\ResourceInterface;
/**
* TypeIntervention
*/
class TypeIntervention implements HistoriqueAwareInterface
class TypeIntervention implements HistoriqueAwareInterface, ResourceInterface
{
use HistoriqueAwareTrait;
......@@ -396,4 +397,16 @@ class TypeIntervention implements HistoriqueAwareInterface
return $this;
}
/**
* Returns the string identifier of the Resource
*
* @return string
*/
public function getResourceId()
{
return 'TypeIntervention';
}
}
......@@ -5,16 +5,16 @@ namespace Application\Entity\Db;
use Application\Entity\Db\Traits\ElementPedagogiqueAwareTrait;
use Application\Entity\Db\Traits\SourceAwareTrait;
use Application\Entity\Db\Traits\TypeInterventionAwareTrait;
use Doctrine\ORM\Mapping as ORM;
use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
use UnicaenImport\Entity\Db\Traits\ImportAwareTrait;
use Zend\Permissions\Acl\Resource\ResourceInterface;
/**
* VolumeHoraireEns
*/
class VolumeHoraireEns implements HistoriqueAwareInterface, ImportAwareInterface
class VolumeHoraireEns implements HistoriqueAwareInterface, ImportAwareInterface, ResourceInterface
{
use HistoriqueAwareTrait;
use ImportAwareTrait;
......@@ -31,6 +31,11 @@ class VolumeHoraireEns implements HistoriqueAwareInterface, ImportAwareInterface
*/
protected $heures;
/**
* @var float
*/
protected $groupes;