Skip to content

Commit

Permalink
Select only public entities
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Apr 17, 2017
1 parent 9cfe05f commit 85690bb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/Controller/DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,25 @@ public function __construct(Request $request, EntityManager $em, View $view) {
}

/**
* Return a single entity by name
* Return a single public entity by name
* @param $name
* @throws ORMException on empty or multiple results
* @return mixed
*/
protected function getSingleEntityByName($name) {
$dql = 'SELECT a, p
FROM Volkszaehler\Model\Entity a
LEFT JOIN a.properties p
$dql = 'SELECT e, p
FROM Volkszaehler\Model\Entity e
LEFT JOIN e.properties p
JOIN e.properties public
WHERE p.key = :key
AND p.value = :name';
AND p.value = :name
AND public.key = :key2
AND public.value = 1';

$q = $this->em->createQuery($dql)
->setParameter('key', 'title')
->setParameter('name', $name);
->setParameter('name', $name)
->setParameter('key2', 'public');

$entity = $q->getSingleResult();
return $entity;
Expand All @@ -92,7 +96,7 @@ public function get($uuid) {
$uuid = $entity->getUuid();
}
catch (ORMException $e) {
throw new \Exception('Channel \'' . $uuid . '\' does not exist or is not unique.');
throw new \Exception('Channel \'' . $uuid . '\' does not exist, is not public or its name is not unique.');
}
}

Expand Down

0 comments on commit 85690bb

Please sign in to comment.