/**
  * Returns all datas necessary to display the list of all workspaces visible for all users
  * that are open for self-registration.
  */
 public function getDatasForSelfRegistrationWorkspaceList(User $user, $search = '')
 {
     $workspaceQueue = $this->workspaceQueueRepo->findByUser($user);
     $listworkspacePending = array();
     foreach ($workspaceQueue as $w) {
         $listworkspacePending[$w->getWorkspace()->getId()] = $w->getWorkspace()->getId();
     }
     if (empty($search)) {
         $workspaces = $this->workspaceRepo->findWorkspacesWithSelfRegistration($user);
     } else {
         $workspaces = $this->workspaceRepo->findWorkspacesWithSelfRegistrationBySearch($user, $search);
     }
     $tags = $this->getNonEmptyAdminTags();
     try {
         $relTagWorkspace = $this->getTagRelationsByAdminAndWorkspaces($workspaces);
     } catch (\InvalidArgumentException $e) {
         $relTagWorkspace = array();
     }
     $tagWorkspaces = array();
     // create an array: tagId => [associated_workspace_relation]
     foreach ($relTagWorkspace as $tagWs) {
         if (empty($tagWorkspaces[$tagWs['tag_id']])) {
             $tagWorkspaces[$tagWs['tag_id']] = array();
         }
         $tagWorkspaces[$tagWs['tag_id']][] = $tagWs['rel_ws_tag'];
     }
     $tagsHierarchy = $this->getAllAdminHierarchies();
     $rootTags = $this->getAdminRootTags();
     $hierarchy = array();
     // create an array : tagId => [direct_children_id]
     foreach ($tagsHierarchy as $tagHierarchy) {
         if ($tagHierarchy->getLevel() === 1) {
             if (!isset($hierarchy[$tagHierarchy->getParent()->getId()]) || !is_array($hierarchy[$tagHierarchy->getParent()->getId()])) {
                 $hierarchy[$tagHierarchy->getParent()->getId()] = array();
             }
             $hierarchy[$tagHierarchy->getParent()->getId()][] = $tagHierarchy->getTag();
         }
     }
     // create an array indicating which tag is displayable
     // a tag is displayable if it or one of his children contains is associated to a workspace
     $displayable = array();
     $allAdminTags = $this->getTagsByUser(null);
     foreach ($allAdminTags as $adminTag) {
         $adminTagId = $adminTag->getId();
         $displayable[$adminTagId] = $this->isTagDisplayable($adminTag, $tagWorkspaces, $hierarchy);
     }
     $tagWorkspacePager = array();
     foreach ($tagWorkspaces as $key => $content) {
         $tagWorkspacePager[$key] = $this->pagerFactory->createPagerFromArray($content, 1);
     }
     return array('user' => $user, 'workspaces' => $this->pagerFactory->createPagerFromArray($workspaces, 1), 'tags' => $tags, 'tagWorkspaces' => $tagWorkspacePager, 'hierarchy' => $hierarchy, 'rootTags' => $rootTags, 'displayable' => $displayable, 'listworkspacePending' => $listworkspacePending, 'search' => $search);
 }