Commit 2d6a8f63 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Masquage de l'intervenant s'il n'est pas nécessaire dans le form de saisie de services

parent 71781d07
......@@ -7,10 +7,3 @@
* @var $sl \Zend\ServiceManager\ServiceLocatorInterface
*/
use Application\Service\PaysService;
/** @var PaysService $cs */
$cs = $sl->get(PaysService::class);
......@@ -485,9 +485,11 @@ return [
],
],
'form_elements' => [
'factories' => [
Form\Service\SaisieFieldset::class => Form\Service\Factory\SaisieFieldsetFactory::class,
],
'invokables' => [
Form\Service\Saisie::class => Form\Service\Saisie::class,
Form\Service\SaisieFieldset::class => Form\Service\SaisieFieldset::class,
Form\ServiceReferentiel\Saisie::class => Form\ServiceReferentiel\Saisie::class,
Form\ServiceReferentiel\SaisieFieldset::class => Form\ServiceReferentiel\SaisieFieldset::class,
Form\Service\RechercheForm::class => Form\Service\RechercheForm::class,
......
......@@ -458,7 +458,18 @@ class ServiceController extends AbstractController
$this->initFilters();
$id = (int)$this->params()->fromRoute('id');
$typeVolumeHoraire = $this->params()->fromQuery('type-volume-horaire', $this->params()->fromPost('type-volume-horaire'));
$intervenant = $this->context()->intervenantFromQuery('intervenant', $this->getServiceIntervenant()->get($this->params()->fromPost('intervenant-id')));
$intervenant = null;
if (!$intervenant){
$intervenant = $this->context()->intervenantFromQuery('intervenant');
}
if (!$intervenant){
$service = $this->params()->fromPost('service');
if (isset($service['intervenant-id'])){
$intervenant = $this->getServiceIntervenant()->get($service['intervenant-id']);
}
}
if (empty($typeVolumeHoraire)) {
$typeVolumeHoraire = $this->getServiceTypeVolumehoraire()->getPrevu();
} else {
......
<?php
namespace Application\Form\Service\Factory;
use Zend\Form\FormElementManager as ContainerInterface;
use Application\Form\Service\SaisieFieldset;
/**
* Description of SaisieFieldsetFactory
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class SaisieFieldsetFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return SaisieFieldset
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* On quitte le FormElementManager */
$container = $container->getServiceLocator();
$fieldset = new SaisieFieldset;
$fieldset->setServiceAuthorize($container->get('BjyAuthorize\Service\Authorize'));
return $fieldset;
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ use Application\Entity\Db\Traits\TypeVolumeHoraireAwareTrait;
use Application\Form\AbstractForm;
use Application\Form\Service\Traits\SaisieFieldsetAwareTrait;
use Application\Form\VolumeHoraire\Traits\SaisieMultipleFieldsetAwareTrait;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\PeriodeServiceAwareTrait;
use Application\Entity\Db\Etablissement;
use Zend\Form\Element\Hidden;
......@@ -23,6 +24,7 @@ class Saisie extends AbstractForm
{
use TypeVolumeHoraireAwareTrait;
use PeriodeServiceAwareTrait;
use ContextServiceAwareTrait;
use SaisieFieldsetAwareTrait;
use SaisieMultipleFieldsetAwareTrait;
......@@ -62,6 +64,9 @@ class Saisie extends AbstractForm
if ($object instanceof Service && $object->getTypeVolumeHoraire()) {
$this->get('type-volume-horaire')->setValue($object->getTypeVolumeHoraire()->getId());
}
if ($object instanceof Service && $object->getIntervenant()) {
$this->get('intervenant')->setValue($object->getIntervenant()->getId());
}
return parent::bind($object, $flags);
}
......@@ -77,16 +82,18 @@ class Saisie extends AbstractForm
$hydrator->setServicePeriode($this->getServicePeriode());
$this->setHydrator($hydrator);
// Product Fieldset
$this->add($this->getFieldsetServiceSaisie());
foreach ($this->getPeriodes() as $periode) {
$pf = $this->getFieldsetVolumeHoraireSaisieMultiple();
$pf->setName($periode->getCode());
$this->add($pf);
// Product Fieldset
if ($this->getServiceContext()->isModaliteServicesSemestriel($this->getTypeVolumeHoraire())){
foreach ($this->getPeriodes() as $periode) {
$pf = $this->getFieldsetVolumeHoraireSaisieMultiple();
$pf->setName($periode->getCode());
$this->add($pf);
}
$this->add(new Hidden('type-volume-horaire'));
}
$this->add(new Hidden('type-volume-horaire'));
$this->add(new Hidden('intervenant'));
$this->add([
'name' => 'submit',
......
......@@ -4,8 +4,10 @@ namespace Application\Form\Service;
use Application\Entity\Db\ElementPedagogique;
use Application\Entity\Db\Service;
use Application\Entity\Db\Traits\IntervenantAwareTrait;
use Application\Form\AbstractFieldset;
use Application\Form\OffreFormation\Traits\ElementPedagogiqueRechercheFieldsetAwareTrait;
use Application\Provider\Privilege\Privileges;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\EtapeServiceAwareTrait;
use Application\Service\Traits\LocalContextServiceAwareTrait;
......@@ -17,6 +19,7 @@ use UnicaenAuth\Service\Traits\AuthorizeServiceAwareTrait;
use Application\Service\Traits\IntervenantServiceAwareTrait;
use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait;
use Application\Service\Traits\EtablissementServiceAwareTrait;
use Zend\Form\Element\Hidden;
use Zend\Stdlib\Hydrator\HydratorInterface;
......@@ -27,6 +30,7 @@ use Zend\Stdlib\Hydrator\HydratorInterface;
*/
class SaisieFieldset extends AbstractFieldset
{
use IntervenantAwareTrait;
use ContextServiceAwareTrait;
use LocalContextServiceAwareTrait;
use EtapeServiceAwareTrait;
......@@ -42,11 +46,6 @@ class SaisieFieldset extends AbstractFieldset
*/
protected $etablissement;
/**
* @var boolean
*/
protected $canSaisieExterieur;
public function init()
......@@ -64,19 +63,15 @@ class SaisieFieldset extends AbstractFieldset
'type' => 'Hidden',
]);
$role = $this->getServiceContext()->getSelectedIdentityRole();
if (!$role->getIntervenant()) {
$intervenant = new SearchAndSelect('intervenant');
$intervenant->setRequired(true)
->setSelectionRequired(true)
->setAutocompleteSource(
$this->getUrl('recherche', ['action' => 'intervenantFind'])
)
->setLabel("Intervenant :")
->setAttributes(['title' => "Saisissez le nom suivi éventuellement du prénom (2 lettres au moins)"]);
$this->add($intervenant);
}
$intervenant = new SearchAndSelect('intervenant');
$intervenant->setRequired(true)
->setSelectionRequired(true)
->setAutocompleteSource(
$this->getUrl('recherche', ['action' => 'intervenantFind'])
)
->setLabel("Intervenant :")
->setAttributes(['title' => "Saisissez le nom suivi éventuellement du prénom (2 lettres au moins)"]);
$this->add($intervenant);
$this->add([
'type' => 'Radio',
......@@ -212,31 +207,26 @@ class SaisieFieldset extends AbstractFieldset
/**
* @return boolean
*/
public function getCanSaisieExterieur()
{
return $this->canSaisieExterieur;
}
/**
* @param boolean $canSaisieExterieur
*
* @return SaisieFieldset
*/
public function setCanSaisieExterieur($canSaisieExterieur)
public function removeUnusedElements()
{
$this->canSaisieExterieur = $canSaisieExterieur;
if ($this->getIntervenant()) {
$canSaisieExterieur = $this->getServiceAuthorize()->isAllowed($this->getIntervenant(), Privileges::ENSEIGNEMENT_EXTERIEUR);
$this->remove('intervenant');
$this->add([
'name' => 'intervenant-id',
'type' => 'Hidden',
'attributes' => [
'value' => $this->getIntervenant()->getId(),
],
]);
} else {
$canSaisieExterieur = $this->getServiceAuthorize()->isAllowed(Privileges::getResourceId(Privileges::ENSEIGNEMENT_EXTERIEUR));
}
if (!$canSaisieExterieur) {
$this->remove('interne-externe');
$this->remove('etablissement');
}
return $this;
}
}
......@@ -270,7 +260,9 @@ class SaisieFieldsetHydrator implements HydratorInterface
public function hydrate(array $data, $object)
{
$intervenant = isset($data['intervenant']['id']) ? (int)$data['intervenant']['id'] : null;
$object->setIntervenant($intervenant ? $this->getServiceIntervenant()->getBySourceCode($intervenant) : null);
if ($intervenant){
$object->setIntervenant( $this->getServiceIntervenant()->getBySourceCode($intervenant));
}
if (isset($data['element-pedagogique']) && $data['element-pedagogique'] instanceof ElementPedagogique) {
$object->setElementPedagogique($data['element-pedagogique']);
......
......@@ -3,6 +3,7 @@
namespace Application\View\Helper\Service;
use Application\Entity\Db\Intervenant;
use Application\Entity\Db\Traits\IntervenantAwareTrait;
use Application\Processus\Traits\IntervenantProcessusAwareTrait;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\EtatVolumeHoraireServiceAwareTrait;
......@@ -28,6 +29,7 @@ class Liste extends AbstractViewHelper
use EtatVolumeHoraireServiceAwareTrait;
use IntervenantServiceAwareTrait;
use IntervenantProcessusAwareTrait;
use IntervenantAwareTrait;
/**
*
......@@ -148,7 +150,14 @@ class Liste extends AbstractViewHelper
public function getAddUrl()
{
return $this->getView()->url('service/saisie', [], ['query' => ['type-volume-horaire' => $this->getTypeVolumeHoraire()->getId()]]);
$params = [
'type-volume-horaire' => $this->getTypeVolumeHoraire()->getId(),
];
if ($this->getIntervenant()){
$params['intervenant'] = $this->getIntervenant()->getRouteParam();
}
return $this->getView()->url('service/saisie', [], ['query' => $params]);
}
......
......@@ -99,9 +99,12 @@ class SaisieForm extends AbstractViewHelper
$fservice = $this->form->get('service');
$res = $this->getView()->form()->openTag($this->form);
if (!$this->getServiceContext()->getSelectedIdentityRole()->getIntervenant()) {
if ($fservice->has('intervenant')) {
$res .= $this->getView()->formControlGroup($fservice->get('intervenant'));
}
if ($fservice->has('intervenant-id')) {
$res .= $this->getView()->formHidden($fservice->get('intervenant-id'));
}
if ($fservice->has('interne-externe')) {
$interne = $fservice->get('interne-externe')->getValue() == 'service-interne';
$res .= $this->getView()->formControlGroup($fservice->get('interne-externe'), 'formButtonGroup');
......
......@@ -49,6 +49,7 @@ if ($cloture) echo $this->partial('application/intervenant/partial/cloture', com
/* Services et horodatage */
if ($services !== false) {
$serviceListe = $this->serviceListe($services);
$serviceListe->setIntervenant($intervenant);
$serviceListe->setTypeVolumeHoraire($typeVolumeHoraire)->setAddButtonVisibility($canAddService);
if ($canAddService && $typeVolumeHoraire->isPrevu()) {
$serviceListe->showPrevuToPrevu($intervenant);
......
Supports Markdown
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