set :: sort CakePHP array

0

I need to sort an array in cakephp according to the order passed by parameter.

The code that does the sort would be this:

 //Realizar a ordenação de acordo com o que receber do formulário no ajax

    if ($this->request->data['Advertencia']['campo_ordem'] == 'Funcionario.quantidade|asc') {
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.quantidade', 'asc');
    }else if($this->request->data['Advertencia']['campo_ordem'] == 'Funcionario.quantidade|desc'){
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.quantidade', 'desc');
    }else if($this->request->data['Advertencia']['campo_ordem'] == 'Funcionario.matricula|asc'){
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.matricula', 'asc');
    }else if($this->request->data['Advertencia']['campo_ordem'] == 'Funcionario.matricula|desc'){
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.matricula', 'desc');
    }else if($this->request->data['Advertencia']['campo_ordem'] == 'Funcionario.nome|desc'){
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.nome', 'desc');
    }else{
        $retornoFinal = Set::sort($retornoFinal, '{n}.{s}.Funcionario.nome', 'asc');
    } 

The array is initially in this format:

Array
(
[5307] => Array
    (
        [A] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 2
                        [matricula] => 5307
                        [nome] => DIOMAR 
                        [tipo_punicao] => A
                    )

            )

        [CA] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 4
                        [matricula] => 5307
                        [nome] => DIOMAR 
                        [tipo_punicao] => CA
                    )

            )

        [RC] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 4
                        [matricula] => 5307
                        [nome] => DIOMAR 
                        [tipo_punicao] => RC
                    )

            )

        [SR] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 2
                        [matricula] => 5307
                        [nome] => 
                        [tipo_punicao] => SR
                    )

            )

    )

[5401] => Array
    (
        [A] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 2
                        [matricula] => 5401
                        [nome] => VALDOMIRO 
                        [tipo_punicao] => A
                    )

            )

        [CA] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 1
                        [matricula] => 5401
                        [nome] => VALDOMIRO 
                        [tipo_punicao] => CA
                    )

            )

        [RC] => Array
            (
                [Funcionario] => Array
                    (
                        [quantidade] => 2
                        [matricula] => 5401
                        [nome] => VALDOMIRO 
                        [tipo_punicao] => RC
                    )

            )

    )
)

When entering the IFs that order by 'Name' or 'Enrollment' works correctly, however by 'QUANTITY' does not work and this is the most important. Is it possible to do otherwise or arrange?

    
asked by anonymous 08.05.2015 / 15:36

1 answer

0

I do not have enough reputation to comment on your question, so I'll write here. Is this ordering you want to do just visual (for the user) or does it have to be ordered in the array as well? If it is visual only use via JavaScript;)

    
08.05.2015 / 18:39