File: /home/undanet/www/PortalEmpleo/src/Controller/UtilsController.php
<?php
namespace PortalEmpleo\Controller;
require __DIR__ . '/../../vendor/autoload.php';
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use PortalEmpleo\Repository\DBUtilRepository;
class UtilsController extends AbstractController
{
public $load;
public function __construct()
{
}
private function pintarCombobox($html)
{
echo $html;
}
private function generarHTML($lvalorescombo)
{
//generar el codigo html del combo y devolverlo
$htmlcombo = '<select name="slct' . $lvalorescombo['NombreCombo'] . '" id="slct' . $lvalorescombo['NombreCombo'] . '">';
foreach ($lvalorescombo['Valores'] as $val) {
$v1 = json_decode(array_shift($val));
$v2 = array_shift($val);
$htmlcombo = $htmlcombo . '<option value="' . $v1 . '" ';
if($v2==$lvalorescombo['ValorSelected']){
$htmlcombo = $htmlcombo . ' selected>';
}
else{
$htmlcombo = $htmlcombo . ' >';
}
$htmlcombo = $htmlcombo . $v2 . '</option>';
}
$htmlcombo = $htmlcombo . '</select>';
return $htmlcombo;
}
public function cargaCombobox($nombreCombo, $lang, $valSelected)
{
$dbUtilRepository = new DBUtilRepository();
$lvalorescombo = call_user_func(array($dbUtilRepository, 'cargaComboBox'), $nombreCombo, $lang);
//modificar el selected si viene como parametro
$lvalorescombo["ValorSelected"] = $valSelected;
if(isset($lvalorescombo)){
$html = $this->generarHTML($lvalorescombo); //Despues de modificar, generamos el codigo html
$this->pintarCombobox($html);
}
}
}
?>