public function getRandomQuestions($category, $limit, $questionsLevel = array(), $excludeQuestions = array())
    {
        $query = $this->createQueryBuilder('q')
            ->addSelect('RAND() as HIDDEN rand, q, c, a')
            ->leftJoin('q.category', 'c')
            ->leftJoin('q.answers', 'a')
            ->where('q.category = :category')
            ->andWhere('q.enabled = 1')
            ->setParameter('category', $category)
            ->orderBy('rand');

        if (!empty($questionsLevel)) {
            $query->andWhere('q.level IN(:level)')
                ->setParameter('level', $questionsLevel);
        }

        if (!empty($excludeQuestions)) {
            $query->andWhere('q.id NOT IN(:questions)')
                ->setParameter('questions', $excludeQuestions);
        }

        $questions = array_slice($query->getQuery()->getResult(), 0, $limit);

        return $questions;
    }
public function getRandomQuestions($category, $limit, $questionsLevel = array(), $excludeQuestions = array())
    {
        $query = $this->createQueryBuilder('q')
            ->addSelect('RAND() as HIDDEN rand, q, c, a')
            ->leftJoin('q.category', 'c')
            ->leftJoin('q.answers', 'a')
            ->where('q.category = :category')
            ->andWhere('q.enabled = 1')
            ->setParameter('category', $category)
            ->orderBy('rand');

        if (!empty($questionsLevel)) {
            $query->andWhere('q.level IN(:level)')
                ->setParameter('level', $questionsLevel);
        }

        if (!empty($excludeQuestions)) {
            $query->andWhere('q.id NOT IN(:questions)')
                ->setParameter('questions', $excludeQuestions);
        }

        $questions = array_slice($query->getQuery()->getResult(), 0, $limit);

        return $questions;
    }
public function getRandomQuestions ( $ category , $ limit , $ questionsLevel = array ( ) , $ excludeQuestions = array ( ) ) { $ query = $ this -> createQueryBuilder ( 'q' ) -> addSelect ( 'RAND() as HIDDEN rand, q, c, a' ) -> leftJoin ( 'q.category' , 'c' ) -> leftJoin ( 'q.answers' , 'a' ) -> where ( 'q.category = :category' ) -> andWhere ( 'q.enabled = 1' ) -> setParameter ( 'category' , $ category ) -> orderBy ( 'rand' ) ; if ( ! empty ( $ questionsLevel ) ) { $ query -> andWhere ( 'q.level IN(:level)' ) -> setParameter ( 'level' , $ questionsLevel ) ; } if ( ! empty ( $ excludeQuestions ) ) { $ query -> andWhere ( 'q.id NOT IN(:questions)' ) -> setParameter ( 'questions' , $ excludeQuestions ) ; } $ questions = array_slice ( $ query -> getQuery ( ) -> getResult ( ) , 0 , $ limit ) ; return $ questions ; }
Get random questions

@param integer $category
@param integer $limit
@param array   $questionsLevel
@param array   $excludeQuestions

@return array
Get random questions