//It has a product of genres table (LojaGenerosProdutos) that when the user 
registers a product id of the genre and the id of the product is stored in 
this table.

//Would like done an IN id in the genre of this table, for example, if a 
product is of three kinds: 1,2,3 (id of genres) find in other fields either 
of these.


   <?php
   // If a logged-in user performs these queries
            //Based on the interest it checks which product genres
            $queryStringUser1 = 'select i.id, g.idGenero as generoId from 
Interesses\Entity\LojaInteresses i
        JOIN Interesses\Entity\LojaGenerosProdutos gp with i.lojaProdutos = 
gp.lojaProdutos
        JOIN Interesses\Entity\LojaProdutos p with p.id = gp.lojaProdutos
        JOIN Interesses\Entity\LojaSubCategorias s with p.subcategoria = 
s.slug
        JOIN Interesses\Entity\LojaGeneros g with g.idGenero = gp.generos
        WHERE i.lojaClientes = :id ORDER BY i.id DESC
        ';

            $results1 = $em->createQuery($queryStringUser1)
                ->setParameter("id", $id)
->getArrayResult();
          
// Keep the ids of genres in the variable $idGeneros
            foreach ($results1 as $valores1) {
                @$idGeneros [] = $valores1['generoId'];
            }
//Picks the last 6 genres
            $ultimosGeneros = array_slice((array_unique($idGeneros)), 0, 6);

//            var_dump($ultimosGeneros);exit;

            $queryStringUser2 = 'select l.id as produtoId from 
Interesses\Entity\LojaGenerosProdutos gp
        JOIN gp.lojaProdutos l
        WHERE gp.generos in (:iDsGeneros)
        ';
            $results2 = $em->createQuery($queryStringUser2)
                //->setParameter("id", $id)
                ->setParameter("iDsGeneros", @$ultimosGeneros)
                ->getArrayResult();

            foreach ($results2 as $valores2) {
                @$idProdutos [] = $valores2['produtoId'];
            }

            $queryStringUser3 = 'select p2, (p2.pontos / p2.votos) as media 
from Interesses\Entity\LojaInteresses i
        JOIN Interesses\Entity\LojaGenerosProdutos gp with i.lojaProdutos = 
gp.lojaProdutos
        JOIN Interesses\Entity\LojaProdutos p with p.id = gp.lojaProdutos
        JOIN Interesses\Entity\LojaSubCategorias s with p.subcategoria = 
s.slug
        JOIN Interesses\Entity\LojaGeneros g with g.idGenero = gp.generos
        JOIN Interesses\Entity\LojaGenerosProdutos gp2 with gp2.generos in 
(:iDsGeneros)
        JOIN Interesses\Entity\LojaProdutos p2 with p2.id in (:iDsProds)
        WHERE i.lojaClientes = :id group by p2.titulo order by i.id DESC
        ';

            $results = $em->createQuery($queryStringUser3)
                ->setParameter("id", $id)
                ->setParameter("iDsGeneros", $ultimosGeneros)
                ->setParameter("iDsProds", $idProdutos)
//                ->setMaxResults(3)
                ->getArrayResult();

            shuffle($results);
            foreach ($results as $number) {
                if ($number['media'] >= 3)//Verifies that the product has 
average> or = 3 to enter in $produto
                    $produto [] = $number;
            }          

            $results = array_slice($produto, 0, 15);// Choose 15 products 
of random products.

        }

        return new JsonModel($results);
    }

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

<<attachment: InteressesController.php>>

Reply via email to