<?php
namespace App\Controller;
use App\Crud\Controller\crudPlainController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\UnidadMilitar;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Enum\TipoFuerzaEnum;
class UnidadMilitarController extends crudPlainController
{
protected function getFormFilter()
{
$formulario = parent::getFormFilter();
unset($formulario['cupoMasculino']);
unset($formulario['cupoFemenino']);
unset($formulario['adicionalMasculino']);
unset($formulario['adicionalFemenino']);
$formulario['fuerza']['tipo']="Symfony\Component\Form\Extension\Core\Type\ChoiceType";
$formulario['fuerza']['atributos']['choices'] = array_flip(TipoFuerzaEnum::getReadables());
$formulario['fuerza']['atributos']['placeholder'] = '--- Seleccione ---';
$formulario['fuerza']['atributos']['empty_data'] = null;
if ($this->routeClassName=='reportecupolugar')
{
$formulario['baseMovilizacion'] = array('nombre' =>'baseMovilizacion',
'tipo' => EntityType::class,
'type' => 'association',
'atributos'=> array('label' => $this->translator->trans(
$this->translatorBase.'.fields.base',
array(),
'crud').':',
'class' => 'App\\Entity\\BaseMovilizacion',
'placeholder' => $this->translator->trans('choice_value.empty_value',array(),'crud'),
'required' => false,
'multiple'=>true,
'attr'=>array('style'=>'width: 100%', 'class'=>'chosen-select')));
}
return $formulario;
}
protected function getFormulario($entity)
{
$formulario = parent::getFormulario($entity);
$formulario['fuerza']['tipo']="Symfony\Component\Form\Extension\Core\Type\ChoiceType";
$formulario['fuerza']['atributos']['choices'] = array_flip(TipoFuerzaEnum::getReadables());
$formulario['fuerza']['atributos']['placeholder'] = '--- Seleccione ---';
$formulario['fuerza']['atributos']['empty_data'] = null;
return $formulario;
}
protected function indexGetFields()
{
$indexFields = parent::indexGetFields();
unset($indexFields['geometria']);
return $indexFields;
}
protected function setFiltros()
{
if (!$this->getUser()->isRoleAssigned('ROLE_OPERADOR_INSTRUCCION') && !$this->getUser()->isRoleAssigned('ROLE_COORDINADOR_BASE') && !$this->getUser()->isRoleAssigned('ROLE_ADMINISTRADOR') && !$this->getUser()->isRoleAssigned('ROLE_COORDINADOR_DIRECCION'))
{
$this->filterData['centroMovilizacion']= $this->getUser()->getCentroMovilizacion()->getId();
}
if ($this->getUser()->isRoleAssigned('ROLE_COORDINADOR_BASE'))
{
$this->filterData['baseMovilizacion']= $this->getUser()->getBaseMovilizacion()->getId();
}
if ($this->getUser()->isRoleAssigned('ROLE_OPERADOR_INSTRUCCION'))
{
$centros = $this->getUser()->getCentroInstruccion()->getCentrosMovilizacion();
$f = array();
foreach ($centros as $centro)
{
$f[]=$centro->getId();
}
$this->filterData['centroMovilizacion'] = $f;
}
if ($this->getUser()->isRoleAssigned('ROLE_OPERADOR_UNIDAD'))
{
$this->filterData['id']= $this->getUser()->getUnidadMilitar()->getId();
}
}
}