/**
  * {@inheritDoc}
  */
 public function id()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'id', array());
     return parent::id();
 }
 /**
  * @param Organization $organization
  * @param Isbn $isbn
  * @return Book
  */
 public function bookOfIsbn(Organization $organization, Isbn $isbn)
 {
     $qb = $this->em->createQueryBuilder();
     $query = $qb->select('b')->from($this->bookClass, 'b')->where($qb->expr()->eq('b.organization', '?1'), $qb->expr()->eq('b.isbn', '?2'))->setParameter(1, $organization->id())->setParameter(2, $isbn->toString());
     return $query->getQuery()->getOneOrNullResult();
 }
 /**
  * @param Organization $organization
  * @return ArrayCollection
  */
 public function all(Organization $organization)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('a')->from($this->assetClass, 'a')->join('a.organization', 'o')->where($qb->expr()->eq('o.id', ':org'))->setParameter('org', $organization->id());
     return $qb->getQuery()->getResult();
 }
 /**
  * Shows all events between a timespan (start, end) of one Organization
  * @param Organization $organization
  * @param $start
  * @param $end
  * @return ArrayCollection
  */
 public function eventsBetween(Organization $organization, $start, $end)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('c')->from($this->calendarClass, 'c')->where($qb->expr()->eq('c.organization', '?1'), $qb->expr()->orX($qb->expr()->andX($qb->expr()->gte('c.start', '?2'), $qb->expr()->lte('c.start', '?3')), $qb->expr()->andX($qb->expr()->gte('c.end', '?2'), $qb->expr()->lte('c.end', '?3'))))->setParameter(1, $organization->id())->setParameter(2, $start)->setParameter(3, $end);
     return $qb->getQuery()->getResult();
 }
 /**
  * Gets all the roles associated with an user
  * @param User $user
  * @param Organization $organization
  * @return mixed
  */
 public function rolesOfUser(User $user, Organization $organization)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('r')->from($this->roleClass, 'r')->join('r.user_roles', 'ur')->where($qb->expr()->eq('ur.user', '?1'), $qb->expr()->eq('ur.organization', '?2'))->setParameter(1, $user->id())->setParameter(2, $organization->id());
     return $qb->getQuery()->getResult();
 }
 /**
  * @param Organization $organization
  * @return ArrayCollection
  */
 public function all(Organization $organization)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('b, i')->from($this->blogClass, 'b')->leftJoin('b.image', 'i')->where($qb->expr()->eq('b.organization', '?1'))->orderBy('b.weborder')->setParameter(1, $organization->id());
     return $qb->getQuery()->getResult();
 }
 /**
  * Find a user by their username and load all ACL along
  * @param Username $username
  * @param Organization $organization
  * @return User
  */
 public function userWithACL(Username $username, Organization $organization)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('u, ur, r')->from($this->class, 'u')->join('u.user_roles', 'ur')->join('ur.role', 'r')->where($qb->expr()->eq('u.username', '?1'), $qb->expr()->eq('ur.organization', '?2'))->setParameter(1, $username->toString())->setParameter(2, $organization->id());
     return $qb->getQuery()->getOneOrNullResult();
 }