php function that calls return from another function

0

Hello, I'm new to PHP OO and Doctrine . I would like to return the value of a function inside another function. It's possible? Both are within the same class.

Function that will receive the result:

public function salvar(Request $request, EM $em)
{
    $FinContaspagar = new FinContaspagar(
        $_SESSION["grupo"],
        $_SESSION["estabelecimento"],
        $request->get('terceiro'),
        /****************RESULTADO DA FUNÇÃO AQUI**********/,
        $request->get('dtemissao'),
        $request->get("dtvencimento")
    );

    $em->persist($FinContaspagar);
    $em->flush();

    return redirect('contas')->with('success_message', 'Cadastrado com sucesso');
}

Function that generates value:

public function insereCodigo(em $em){

    $query = $em->createQuery('SELECT COALESCE(MAX(u.codigo+1),1) as Codigo
                                 FROM ModuloFinanceiro\Entities\FinContaspagar u 
                                WHERE u.grupo = :sessionGrupo
                                  AND u.estabelecimento = :sessionEstabelecimento');
    $query->setParameter('sessionGrupo',$_SESSION["grupo"])
        ->setParameter('sessionEstabelecimento',$_SESSION["estabelecimento"]);
    $codigo = $query->getResult();

    return $codigo[0]["Codigo"];
}

If it is not possible or not recommended to do this, how can I proceed?

    
asked by anonymous 20.04.2017 / 14:30

1 answer

2

I think that for a better understanding it would be better to receive this value before calling the function:

$retorno = $this->insereCodigo($em);

or so, but I do not know if it works:

 $FinContaspagar = new FinContaspagar(
    $_SESSION["grupo"],
    $_SESSION["estabelecimento"],
    $request->get('terceiro'),
    $this->insereCodigo($em),
    $request->get('dtemissao'),
    $request->get("dtvencimento")
);
    
20.04.2017 / 14:37