/**
  *
  *
  * @param  UsrList $list
  * @param  type    $usr_id
  * @return UsrList
  */
 public function findByListAndUsrId(UsrList $list, $usr_id)
 {
     $dql = 'SELECT o FROM Phraseanet:UsrListOwner o
           JOIN o.list l
         WHERE l.id = :list_id AND o.user = :usr_id';
     $params = ['usr_id' => $usr_id, 'list_id' => $list->getId()];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     try {
         $owner = $query->getSingleResult();
     } catch (NoResultException $e) {
         throw new NotFoundHttpException('Owner is not found', null, $e);
     }
     return $owner;
 }
 private function insertUsrLists(EntityManager $em, \Pimple $DI)
 {
     $owner1 = new UsrListOwner();
     $owner1->setRole(UsrListOwner::ROLE_ADMIN);
     $owner1->setUser($DI['user']);
     $owner2 = new UsrListOwner();
     $owner2->setRole(UsrListOwner::ROLE_ADMIN);
     $owner2->setUser($DI['user_alt1']);
     $list1 = new UsrList();
     $list1->setName('new list');
     $list1->addOwner($owner1);
     $owner1->setList($list1);
     $entry1 = new UsrListEntry();
     $entry1->setUser($DI['user']);
     $entry1->setList($list1);
     $list1->addEntrie($entry1);
     $entry2 = new UsrListEntry();
     $entry2->setUser($DI['user_alt1']);
     $entry2->setList($list1);
     $list1->addEntrie($entry2);
     $list2 = new UsrList();
     $list2->setName('new list');
     $list2->addOwner($owner2);
     $owner2->setList($list2);
     $entry3 = new UsrListEntry();
     $entry3->setUser($DI['user_alt1']);
     $entry3->setList($list2);
     $list2->addEntrie($entry3);
     $entry4 = new UsrListEntry();
     $entry4->setUser($DI['user_alt2']);
     $entry4->setList($list2);
     $list2->addEntrie($entry4);
     $em->persist($owner1);
     $em->persist($owner2);
     $em->persist($list1);
     $em->persist($list2);
     $em->persist($entry1);
     $em->persist($entry2);
     $em->persist($entry3);
     $em->persist($entry4);
 }
 private function formatUserList(UsrList $list)
 {
     $entries = [];
     foreach ($list->getEntries() as $entry) {
         $entries[] = ['Id' => $entry->getId(), 'User' => $this->formatUser($entry->getUser())];
     }
     return ['type' => 'LIST', 'list_id' => $list->getId(), 'name' => $list->getName(), 'length' => count($entries), 'entries' => $entries];
 }
 /**
  * {@inheritDoc}
  */
 public function has(\Alchemy\Phrasea\Model\Entities\User $user)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'has', array($user));
     return parent::has($user);
 }