0
votes

The first entity called BUNDLE

/**
 * @var \Doctrine\Common\Collections\Collection of \Akademie\Course\Course
 * @ManyToMany(targetEntity="Akademie\Course\Course", mappedBy="bundles")
 */
private $courses;

The second entity is called COURSE

/**
 * @var \Doctrine\Common\Collections\Collection of \Akademie\Bundle\Bundle
 * @ManyToMany(targetEntity="Akademie\Bundle\Bundle", inversedBy="courses")
 */
    private $bundles;

/**
 * @var \Doctrine\Common\Collections\Collection of \Akademie\Course\CourseDate
 * @OneToMany(targetEntity="Akademie\Course\CourseDate", mappedBy="course")
 */
    private $courseDates;

/**
 * @var int
 * @Column(type="boolean")
 */
    private $hidden;

and the third is called COURSEDATE

/**
 * @var \Akademie\Course\Course
 * @ManyToOne(targetEntity="Akademie\Course\Course", inversedBy="courseDates")
 * @JoinColumn(nullable=false)
 */
    private $course;

/**
 * @var \DateTime
 * @Column(type="datetimetz", nullable=true)
 */
    private $beginDate;

I have parameter course and I need to get all bundles, which contains this course. What's more, all other courses in that bundle has to have courseDate newer than current date and can't be hidden. Otherwise I don't want to get this bundle. I hope it is clear now...

1

1 Answers

0
votes

In a repository (bundle of entity BUNDLE for example), you have to create a custom method :

public function myMethod($course){
        $qb = $this->createQueryBuilder("b")
                       ->join("b.course", "c")
                       ->join("c.courseDates", "cd")
                       ->Where("c = :course")
                       ->andWhere(" cd.beginDate > :now ")
                       ->andWhere("c.hidden = 1")// if 1 means not hidden
                       ->setParameter(":course", $course)
                       ->setParameter(":now", new \DateTime('now'));

And then, in your controller, you have to do something like that :

$bundles = $this->getDoctrine()->getManager()->getRepository('namespace of your BUNDLE entity')->myMethod($course);