/**
  * Checks if given tag or at least one of its children is associated to a workspace.
  *
  * @param int   $tagId
  * @param array $tagWorkspaces
  * @param array $hierarchy
  *
  * @return bool
  */
 private function isTagDisplayable(WorkspaceTag $tag, array $tagWorkspaces, array $hierarchy)
 {
     $displayable = false;
     $tagId = $tag->getId();
     if (isset($tagWorkspaces[$tagId]) && count($tagWorkspaces[$tagId]) > 0 || !is_null($tag->getWorkspace())) {
         $displayable = true;
     } else {
         if (isset($hierarchy[$tagId]) && count($hierarchy[$tagId]) > 0) {
             $children = $hierarchy[$tagId];
             foreach ($children as $child) {
                 $displayable = $this->isTagDisplayable($child, $tagWorkspaces, $hierarchy);
                 if ($displayable) {
                     break;
                 }
             }
         }
     }
     return $displayable;
 }
 public function findOneAdminByWorkspaceAndTag(Workspace $workspace, WorkspaceTag $tag)
 {
     $dql = '
         SELECT rwt
         FROM Claroline\\CoreBundle\\Entity\\Workspace\\RelWorkspaceTag rwt
         JOIN rwt.workspace w
         JOIN rwt.tag t
         WHERE t.user IS NULL
         AND w.id = :workspaceId
         AND t.id = :tagId
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('workspaceId', $workspace->getId());
     $query->setParameter('tagId', $tag->getId());
     return $query->getOneOrNullResult();
 }