public function getDatasForWorkspaceList($withRoles = true, $search = '', $max = 20, $wsMax = 10) { if (empty($search)) { $workspaces = $this->workspaceRepo->findDisplayableWorkspaces(); } else { $workspaces = $this->workspaceRepo->findDisplayableWorkspacesBySearch($search); } $nonPersonalWs = $this->workspaceManager->getDisplayableNonPersonalWorkspaces(1, $max, $search); $personalWs = $this->workspaceManager->getDisplayablePersonalWorkspaces(1, $max, $search); $tags = $this->getNonEmptyAdminTags(); $relTagWorkspace = $this->getTagRelationsByAdmin(); $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); } $workspaceRoles = array(); if ($withRoles) { $roles = $this->roleManager->getAllWhereWorkspaceIsDisplayable(); foreach ($roles as $role) { $wsRole = $role->getWorkspace(); if (!is_null($wsRole)) { $code = $wsRole->getCode(); if (!isset($workspaceRoles[$code])) { $workspaceRoles[$code] = array(); } $workspaceRoles[$code][] = $role; } } } $tagWorkspacePager = array(); foreach ($tagWorkspaces as $key => $content) { $tagWorkspacePager[$key] = $this->pagerFactory->createPagerFromArray($content, 1); } return array('workspaces' => $this->pagerFactory->createPagerFromArray($workspaces, 1, $wsMax), 'tags' => $tags, 'tagWorkspaces' => $tagWorkspacePager, 'hierarchy' => $hierarchy, 'rootTags' => $rootTags, 'displayable' => $displayable, 'workspaceRoles' => $workspaceRoles, 'search' => $search, 'nonPersonalWs' => $nonPersonalWs, 'personalWs' => $personalWs, 'max' => $max, 'wsMax' => $wsMax); }
/** * @param string $search * @param integer $page * @param User $user * * @return \PagerFanta\PagerFanta */ public function getDisplayableWorkspacesBySearchPager($search, $page, $max = 20) { $workspaces = $this->workspaceRepo->findDisplayableWorkspacesBySearch($search); return $this->pagerFactory->createPagerFromArray($workspaces, $page, $max); }