2

I'm working on website for multiple choice questions where I use symfony. The thought is to have a very big question database that categorized by topic. And then a test 1 - n chapterSelections. Each chapterSelections should contain a chapterID and a number. The number decides how many random questions it should pick from that chapter.

In the chapter entity it has a getQuestions function, and in the quetions entity, it has an getAlternatives functions.

BUT, I need a function in the chapterSelections entity that says, getRandomQuestions(int n)???

In my view, I was thinking of something like:

{% block body %}
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
    <h1>Welcome</h1>
    <h1>{{ test.name }}</h1>

    {% for c in test.chapterSelections %}
        <h1>Chapter: {{ c.getChapterID() }} - {{ c.numberOfQuestions }}</h1>
        {% for q in c.randomQuestions %}
            <h3>{{ q.questionText}} </h3>
            {% for a in q.alternatives %}
                <p> {{a.alternativeText }} </p>
            {% endfor %}
        {% endfor %}
    {% endfor %}
</div>
{% endblock %}

I know I'm still missing the formcontrols like radiobuttons and formgroups, but this is the hardest part. I need a way to access a number of random questions from the chapterSelection entity. Any thoughts? Some info that is helpful that I have left out?

EDIT This is how i use getQuestions in my chapter entity:

Entity/chapter.php

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\OneToMany(targetEntity="question", mappedBy="chapterID", cascade={"persist", "remove"}, orphanRemoval=true)
 */
protected $questions;


public function __construct()
{
    $this->questions= new ArrayCollection();
}

public function getQuestions()
{
    return $this->questions;
}

But I want this functionality in my chapterSelection, with random selection and a specified (in each chapterSelection record) number of questions.

Ruben Ravnå
  • 659
  • 7
  • 17

0 Answers0