. */ namespace OCA\SideMenu\Controller; use OCA\SideMenu\Service\AppRepository; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use OC\App\AppStore\Fetcher\CategoryFetcher; use OCP\L10N\IFactory; class NavController extends Controller { /** * @var \OCP\IConfig */ protected $config; /** * @var AppRepository */ protected $appRepository; /** * @var IL10N */ protected $trans; /** * @var IFactory */ protected $l10nFactory; /** * @var CategoryFetcher */ protected $categoryFetcher; /** * @param string $appName */ public function __construct( $appName, IRequest $request, IConfig $config, AppRepository $appRepository, CategoryFetcher $categoryFetcher, IFactory $l10nFactory, IL10N $trans) { parent::__construct($appName, $request); $this->config = $config; $this->appRepository = $appRepository; $this->categoryFetcher = $categoryFetcher; $this->l10nFactory = $l10nFactory; $this->trans = $trans; } /** * @NoAdminRequired * @NoCSRFRequired * @PublicPage * * @return JSONResponse */ public function items() { $apps = $this->appRepository->getVisibleApps(); $currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2); $categoriesLabels = $this->categoryFetcher->get(); $items = []; foreach ($categoriesLabels as $k => $category) { $categoriesLabels[$category['id']] = $category['translations'][$currentLanguage]['name'] ?? $category['translations']['en']['name']; unset($categoriesLabels[$k]); } foreach ($apps as $app) { $categories = $app['category']; foreach ($categories as $category) { if (!isset($items[$category])) { $items[$category] = [ 'name' => $categoriesLabels[$category], 'apps' => [], ]; } $items[$category]['apps'][$app['id']] = [ 'name' => $app['name'], 'href' => '#', 'icon' => $app['previewAsIcon'] ? $app['preview'] : null, ]; } } $items['other'] = [ 'label' => $this->trans->t('Other'), 'apps' => [], ]; // foreach ($items as $category => $value) { // if ($category !== 'other') { // if (count($value['apps']) < 0) { // $items['other']['apps'] = array_merge( // $items['other']['apps'], // $value['apps'] // ); // // unset($items[$category]); // } // } // } return new JSONResponse([ 'items' => $items, ]); } }