Retrieve a flag in a function

Asked

Viewed 45 times

0

I have a function in a php script where, in it, I must recover the values 1 or 3 of a table in mysql (1 - documents relevant to service providers, 2 -documents of the contracts (companies) for which these providers worked)

The code below provides a "magnifying glass" that currently brings me these two types of documents mixed in a list:

<a href="javascript:;" class="btn btn-xs btdoc btn-default" data-key="<?= $value['id_prestador'] ?>" data-toggle="tooltip" data-placement="top" title="Visualizar/Anexar documentos">

below, the function where I should recover / implement this filter ( in case generate a separate "magnifying glass" only for company documents:

protected function getDocs() {


    global $prestador;

    try {

       $query = "SELECT ps.c_razao as prestador, A.prestador_tipo_doc_id, A.prestador_tipo_doc_nome, B.prestador_documento_id, 
                COUNT(B.prestador_documento_id) AS qnt 
                FROM prestador_tipo_doc AS A
                LEFT JOIN prestador_documentos AS B ON (A.prestador_tipo_doc_id = B.prestador_tipo_doc_id AND B.id_prestador = $prestador)
                JOIN prestadorservico as ps on ps.id_prestador = $prestador
                WHERE A.status = 1    
                GROUP BY A.prestador_tipo_doc_id
                ORDER BY A.ordem";

        $this->rh->Prestadorservico->setDefault()->setIdPrestador($prestador)->select("c_razao")->getRow();
        $this->nomePrestador = $this->rh->Prestadorservico->getCRazao();

        $exec = $this->db->setDefault()->setQuery(QUERY, $query)->execute();
        if (!$exec->isOk()){
            $this->error->set("Houve um erro na montagem da listagem dos DOCs", E_FRAMEWORK_ERROR);
        }

        $this->rsDocs = $exec->getArray();

         if (!include_once(ROOT_APP_TEMPLATE . 'admin/prestador/listar_docs.php')) die('Não foi possível incluir ' . ROOT_APP_TEMPLATE . 'admin/prestador/listar_docs.php');


    } catch (Exception $ex) {
        $this->setValue(0)->error->set(array(1, __METHOD__), E_FRAMEWORK_WARNING, $ex);
        echo $this->getAlertHtml($this->rh->getAllMsgCode(null, "<br/>"));
        // return $this;
        //echo $this->rh->error->getAllMsgCodeJson(array('code' => 0, 'status' => $this->isOk()));
    }

}

I have tried to understand, what interaction the html/javascript tags do with the php function above, to get an idea of how I will modify it. That’s the way they pointed me in the office, but it’s been hard to relate one thing to the other. Most of the questions and solutions I found are very generic.

To make it easier to understand the question, when I inspect Chrome it clearly shows me the getDocs method being invoked. But I would really like to understand, in which place the tags below this is passed:

<a href="javascript:;" class="btn btn-xs btdoc btn-default" data-key="<?= $value['id_prestador'] ?>" data-toggle="tooltip" data-placement="top" title="Visualizar/Anexar documentos">

EDIT: When debugging with firefox, I found the reference in the tag above (btdoc) in the script below:

$(document).on("click", ".btdoc", function () {
        var $this = $(this);
        var key = $this.data("key");
        /*var kids = $this.parents("tr").children();
        var razao = kids.next().next().html();*/
        cria_carregando_modal();

        $.post("?class=admin/prestador/gestao", {prestador: key, method: "getDocs"}, function (data) {
            remove_carregando_modal();
            bootDialog(data, 'Lista de Documentos', '', 'info');
        }, 'html');
    });

Basically what I did was "replicate" (yes, I understand that was a gambiarra) the same script, but this time with a reference ".btdoc_prestador" , calling a method similar to the one I named getDocs_prestador:

protected function getDocs_prestador() {


    global $prestador;

    try {

        $query2 = "SELECT ps.c_razao as prestador, A.prestador_tipo_doc_id, A.prestador_tipo_doc_nome, B.prestador_documento_id, 
                COUNT(B.prestador_documento_id) AS qnt 
                FROM prestador_tipo_doc AS A
                LEFT JOIN prestador_documentos AS B ON (A.prestador_tipo_doc_id = B.prestador_tipo_doc_id AND B.id_prestador = $prestador)
                JOIN prestadorservico as ps on ps.id_prestador = $prestador
                WHERE  A.status = 1 AND A.tipo_doc = 2
                GROUP BY A.prestador_tipo_doc_id
                ORDER BY A.ordem";

        $this->rh->Prestadorservico->setDefault()->setIdPrestador($prestador)->select("c_razao")->getRow();
        $this->nomePrestador = $this->rh->Prestadorservico->getCRazao();

        $exec = $this->db->setDefault()->setQuery(QUERY, $query2)->execute();
        if (!$exec->isOk()){
            $this->error->set("Houve um erro na montagem da listagem dos DOCs", E_FRAMEWORK_ERROR);
        }

It is returning me the list of documents according to the flag I put in the query : A.tipo_doc = 2

The problem now is that the display of the modals with the listing was super buggy, as in the image below:

inserir a descrição da imagem aqui

EDIT 2 In addition to the result I expected, actually the page is loading several modals in the act of the same click. Including different types.

EDIT 3 The rendering of the modal ta taking too long tbm:

inserir a descrição da imagem aqui

  • $query = "SELECT ps.c_razao as provider, in that part of the code should not "provider" be as a variable?

  • Or rather, what value is returned?

  • Hi, @Pedrohenrique Actually, provider sets only one alias for the table. I was able to implement the call of the different document lists according to the SQL classification in the methods. I edited the topic and added an image for better understanding.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.