Returns an array of serialized categories.
If parentKey is set, only the children of the category which is assigned to the given key are returned.

@param string $locale
@param string $parentKey key of parent category

@return array
18671
public function getCategoriesFunction($locale, $parentKey = null)
    {
        return $this->memoizeCache->memoizeById(
            'sulu_categories',
            func_get_args(),
            function($locale, $parentKey = null) {
                $entities = $this->categoryManager->findChildrenByParentKey($parentKey);
                $categories = $this->categoryManager->getApiObjects($entities, $locale);
                $context = SerializationContext::create();
                $context->setSerializeNull(true);

                return $this->serializer->serialize($categories, 'array', $context);
            }
        );
    }
153800
protected function getDatabaseTranslations(Locale $locale)
    {
        $messages   = [];
        $collection = $this->repository->getCollection();
        
        $collection->map(function (Dictionary $dictionary) use ($locale, &$messages) {
            $messages[$dictionary->getIdentifier()] = $dictionary->translate($locale->getCode())->getValue();
        });
        
        return $messages;
    }
178523
private function findChildNodeWithKey($parentId, $key)
	{
        $result = array();
        $relations = $this->getRelations();

        if (isset($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId])) {
            foreach ($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId] as $id) {
                // Current found node
                $node = $relations[RelationBuilder::TREE_PARAM_ITEMS][$id][$key];

                $result = array_merge($result, $this->findChildNodeWithKey($id, $key));
                $result[] = $node;
            }
        }

        return $result;
    }
403422
protected function getTranslation(string $key, string $locale)
    {
        return $this->translations()
            ->where('key', $key)
            ->where('locale', $locale)
            ->value('translation');
    }
696899
public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
    {
        if ($parentNodeCategory === null) {
            if ($this->getCurrentCategoryId()) {
                $this->getRootByIds([$this->getCurrentCategoryId()]);
            }
        }

        return parent::getRoot($parentNodeCategory, $recursionLevel);
    }
1256793
private function gatherChildrenData($entity, $parentLocalization, $filter = null, $levels = null, $count = false)
	{
		$input = $this->getRequestInput();
		$localeId = $this->getCurrentLocale()->getId();
		
		// @TODO: existing_only flag is used for LinkManager, when it requests for available pages for linking.
		// should split that onto two separate methods.
		$existingOnly = $input->filter('existing_only', false, false, FILTER_VALIDATE_BOOLEAN);

		$customTitleQuery = $input->get('query', false);

		$entityManager = $this->getEntityManager();
		$pageFinder = $entity === Page::CN() 
				? new PageFinder($entityManager)
				: new TemplateFinder($entityManager);

		// Reading by one level because need specific reading strategy for application pages
		if (empty($parentLocalization)) {
			$pageFinder->addLevelFilter(0, 0);
		} else {
			$rootNode = $parentLocalization->getMaster();
			$pageFinder->addFilterByParent($rootNode, 1, 1);
		}

		$queryBuilder = $pageFinder->getQueryBuilder();

		if ($existingOnly) {
			$queryBuilder->leftJoin('e.localizations', 'l_', 'WITH', 'l_.locale = :locale')
					->setParameter('locale', $localeId)
					->leftJoin('e.localizations', 'l')
					->andWhere('l_.id IS NOT NULL OR e INSTANCE OF ' . GroupPage::CN());
		} else {
			$queryBuilder->leftJoin('e.localizations', 'l_', 'WITH', 'l_.locale = :locale')
					->setParameter('locale', $localeId)
					->leftJoin('e.localizations', 'l')
					->andWhere('l_.id IS NOT NULL OR e.global = true OR (e.level = 0 AND e.global = false)');
		}

		if($customTitleQuery) {
			$queryBuilder->andWhere('l_.title LIKE :customTitleQuery');
			$queryBuilder->setParameter('customTitleQuery', $customTitleQuery . '%');
		}

		$filterFolders = array();
		$application = null;

		if ($parentLocalization instanceof ApplicationLocalization) {

			// This is bad solution for detecting where the sitemap has been requested from.
			// Should group by month if sitemap requested in the sidebar.
			//FIXME: JS should pass preference maybe
			if (empty($filter) && $existingOnly) {
				$filter = 'group';
			}

			$application = $this->getPageApplicationManager()
					->createApplicationFor($parentLocalization, $this->getEntityManager());

			$filterFolders = $application->getFilterFolders($queryBuilder, $filter);
			
			$application->applyFilters($queryBuilder, $filter);
		}

		$query = $queryBuilder->getQuery();

		if ($input->has('offset')) {
			$offset = $input->getInt('offset');
			$query->setFirstResult($offset);
		}

		if ($input->has('resultsPerRequest')) {
			$limit = $input->getInt('resultsPerRequest');
			$query->setMaxResults($limit);
		}

		$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($query, true);

		// TODO: fix, shouldn't return mixed result depending on arguments
		if ($count) {
			// When only the count is needed...
			$count = count($filterFolders) + count($paginator);

			return $count;
		} else {

			$response = array();

			// Prepend the filter folders
			$pages = array_merge($filterFolders, iterator_to_array($paginator));

			if ( ! is_null($levels)) {
				$levels --;
			}

			foreach ($filterFolders as $filterFolder) {
				if ( ! $filterFolder instanceof TemporaryGroupPage) {
					throw new \LogicException("Application " . get_class($application) . ' returned invalid filter folders');
				}
			}

			foreach ($pages as $page) {

				$pageData = $this->convertPageToArray($page, $localeId);

				// Skipping the page
				if (is_null($pageData)) {
					continue;
				}

				$pageData['children_count'] = 0;

				$localization = $page->getLocalization($localeId);

				if ( ! empty($localization)) {
					$filter = null;
					if ($page instanceof TemporaryGroupPage) {
						$filter = $page->getTitle();
						$localization = $parentLocalization;

						// TODO: for now it's enabled for all filter folders
						$pageData['childrenListStyle'] = 'scrollList';
						$pageData['selectable'] = false;
						$pageData['editable'] = false;
						$pageData['isDraggable'] = false;
						$pageData['isDropTarget'] = true;
						$pageData['new_children_first'] = true;
					}

					if ($levels === 0 && $page instanceof TemporaryGroupPage && $page->hasCalculatedNumberChildren()) {
						$pageData['children_count'] = $page->getNumberChildren();
					} elseif ($levels === 0) {
						$pageData['children_count'] = $this->gatherChildrenData($entity, $localization, $filter, $levels, true);
					} else {
						$pageData['children'] = $this->gatherChildrenData($entity, $localization, $filter, $levels, false);
						$pageData['children_count'] = count($pageData['children']);
					}

//					// TODO: might be job for JS
//					if ($pageData['children_count'] > 0
//							&& ! empty($pageData['icon'])
//							&& $pageData['icon'] === 'page') {
//
//						$pageData['icon'] = 'folder';
//					}
				}

				$response[] = $pageData;
			}

			return $response;
		}
	}
863565
public static function get($key, $default = null, $locale = null)
    {
        return self::all($locale)->get($key, $default);
    }
1091181
private function convertRecursive(array $array, $parentKey = null)
    {
        $return = [];
        if (!is_null($parentKey))
            $parentKey .= '.';

        foreach ($array as $k => $v) {
            if (is_array($v))
                $return[] = $this->convertRecursive($v, $parentKey . $k);
            else
                $return[$parentKey . $k] = $v;
        }
        return $this->array_flatten($return);
    }
753763
public static function getByLocale($locale)
    {
        if (!$locale) {
            return null;
        }

        if ($locale instanceof Locale) {
            return $locale;
        }

        if (!static::$locales_by_title) {
            static::$locales_by_title = [];
            foreach (Locale::getCached() as $localeObj) {
                static::$locales_by_title[$localeObj->Locale] = $localeObj;
            }
        }

        // Get filtered locale
        return isset(static::$locales_by_title[$locale]) ? static::$locales_by_title[$locale] : null;
    }
1316952
public function getDescendants($parentCategories = null)
    {
        if(empty($parentCategories)) {
            $childCategories = $this->getChildren();
        }
        else {
            $childCategories = Category::find()
                ->where(['in', 'parent_id', ArrayHelper::map($parentCategories, 'id', 'id')])
                ->with('translation')
                ->all();
        }
        if(!empty($childCategories)) {
            return array_merge($childCategories, $this->getDescendants($childCategories));
        }
        return $childCategories;
    }
1096589
public function getLocalizedColumn($key, $locale = 'en')
    {
        if (empty($locale)) {
            $locale = 'en';
        }
        $localizedKey = $key.'_'.strtolower($locale);
        $value        = $this->$localizedKey;
        if (empty($value)) {
            $localizedKey = $key.'_en';
            $value        = $this->$localizedKey;
        }

        return $value;
    }
760842
private function find($locale, $dictionary, $keys)
    {
        if (!isset($this->entries[$locale][$dictionary])) {
            if (!isset($this->entries[$locale])) {
                $this->entries[$locale] = [];
            }
            $file = $this->dictionaryFile($dictionary, $locale);
            /** @noinspection PhpIncludeInspection */
            $this->entries[$locale][$dictionary] = $file !== null && file_exists($file) ? include $file : [];
        }

        $entries = $this->entries[$locale][$dictionary];
        foreach ($keys as $key) {
            if (!isset($entries[$key])) {
                return null;
            }
            $entries = $entries[$key];
        }

        return $entries;
    }
797950
public function getLocalization($locale)
    {
        $dataCollection = $this->getLocalizations();
        $data = $dataCollection->get($locale);

        return $data;
    }
128252
public function getCatalogs($locale = null, $domain = null) {
		$cache = $this->getCacheFrontend();
		
		if (is_array($locale)) {
			$catalogs = $cache->getMany($locale);
			
			return empty($catalogs) ? null : $catalogs;
		}
		
		$catalogs = $cache->get($locale);
		
		if ($catalogs === null) {
			return;
		}
		
		return [$locale => $catalogs];
	}
940024
protected function getTranslation($key, $locale) {
        if( isset($this->translations[$locale][$key]) )
            return $this->translations[$locale][$key];

        return $key;
    }
649677
public function getCategories($id, $locale)
    {
        $groups    = $this->getGroups($id, $locale)->toArray();
        $available = antares('memory')->get('extensions.available');
        $list      = ['all' => 'All', 'foundation' => trans('Core')];

        array_walk($groups, function($item) use($available, &$list) {
            $group = str_replace('antares/', '', $item['group']);
            foreach ($available as $extension) {
                if ($group == $extension['name']) {
                    $list[$group] = $extension['full_name'];
                }
            }
        });
        $return = [
            'all'           => 'All',
            'core'          => [
                'label'      => trans('antares/translations::messages.group.core'),
                'extensions' => []
            ],
            'configuration' => [
                'label'      => trans('antares/translations::messages.group.configuration'),
                'extensions' => []
            ],
        ];
        foreach ($list as $name => $value) {
            if (in_array($name, ['foundation', 'widgets', 'search', 'control'])) {
                $return['core']['extensions'][$name] = $value;
            } elseif (in_array($name, ['two_factor_auth', 'api'])) {
                $return['configuration']['extensions'][$name] = $value;
            } else {
                $return[$name] = $value;
            }
        }
        return $return;
    }
1159382
private function getParentNode($parent, $webspaceKey, $languageCode)
    {
        if (null != $parent) {
            return $this->getMapper()->load($parent, $webspaceKey, $languageCode);
        } else {
            return $this->getMapper()->loadStartPage($webspaceKey, $languageCode);
        }
    }