side_menu/lib/Service/AppRepository.php

85 lines
2.1 KiB
PHP
Raw Normal View History

2020-08-06 15:00:59 +02:00
<?php
namespace OCA\SideMenu\Service;
2020-08-13 11:21:06 +02:00
use OC_App;
use OCP\L10N\IFactory;
2020-08-06 15:00:59 +02:00
/**
* class AppRepository.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class AppRepository
{
/**
* @var OC_App
*/
protected $ocApp;
2020-08-13 11:21:06 +02:00
/**
* @var IFactory
*/
protected $l10nFactory;
public function __construct(OC_App $ocApp, IFactory $l10nFactory)
2020-08-06 15:00:59 +02:00
{
$this->ocApp = $ocApp;
2020-08-13 11:21:06 +02:00
$this->l10nFactory = $l10nFactory;
2020-08-06 15:00:59 +02:00
}
/**
* Retrieves visibles apps.
*
* @return array
*/
public function getVisibleApps()
{
2020-08-13 11:21:59 +02:00
$navigation = $this->ocApp->getNavigation();
$apps = $this->ocApp->listAllApps();
2020-08-06 15:00:59 +02:00
$visibleApps = [];
foreach ($apps as $app) {
$id = $app['id'];
2020-08-19 09:18:29 +02:00
foreach ([$app['id'], $app['id'].'_index'] as $id) {
if (isset($navigation[$id])) {
$app['name'] = $this->l10nFactory->get($id)->t($app['name']);
$app['href'] = $navigation[$id]['href'];
$app['icon'] = $navigation[$id]['icon'];
2020-08-13 11:21:06 +02:00
2020-08-19 09:18:29 +02:00
$visibleApps[$id] = $app;
}
2020-08-06 15:00:59 +02:00
}
}
2020-08-11 15:52:15 +02:00
foreach ($navigation as $app) {
2020-08-13 11:21:59 +02:00
if ('external_index' === substr($app['id'], 0, 14)) {
2020-08-11 15:52:15 +02:00
$visibleApps[$app['id']] = [
'id' => $app['id'],
2020-08-13 11:21:06 +02:00
'name' => $this->l10nFactory->get($app['id'])->t($app['name']),
2020-08-14 13:30:48 +02:00
'href' => $app['href'],
2020-08-19 09:18:29 +02:00
'icon' => $app['icon'],
2020-08-11 15:52:15 +02:00
'category' => [
'external_links',
],
];
2020-08-13 11:21:59 +02:00
} elseif ('files' === $app['id']) {
2020-08-12 16:27:43 +02:00
$visibleApps[$app['id']] = [
'id' => $app['id'],
2020-08-13 11:21:06 +02:00
'name' => $this->l10nFactory->get($app['id'])->t($app['name']),
2020-08-14 13:30:48 +02:00
'href' => $app['href'],
2020-08-19 09:18:29 +02:00
'icon' => $app['icon'],
2020-08-12 16:27:43 +02:00
'category' => [],
];
2020-08-11 15:52:15 +02:00
}
}
2020-08-13 11:21:59 +02:00
usort($visibleApps, function ($a, $b) {
2020-08-12 16:32:26 +02:00
return ($a['name'] < $b['name']) ? -1 : 1;
});
2020-08-06 15:00:59 +02:00
return $visibleApps;
}
}