2020-08-06 15:00:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\SideMenu\Service;
|
|
|
|
|
2022-11-04 21:07:44 +01:00
|
|
|
use OC\User\User;
|
2023-07-10 20:14:42 +02:00
|
|
|
use OCP\INavigationManager;
|
2020-08-13 11:21:06 +02:00
|
|
|
use OCP\L10N\IFactory;
|
2020-08-06 15:00:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* class AppRepository.
|
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
|
|
|
class AppRepository
|
|
|
|
{
|
|
|
|
/**
|
2020-10-14 09:57:42 +02:00
|
|
|
* @var \OC_App
|
2020-08-06 15:00:59 +02:00
|
|
|
*/
|
|
|
|
protected $ocApp;
|
|
|
|
|
2020-08-13 11:21:06 +02:00
|
|
|
/**
|
|
|
|
* @var IFactory
|
|
|
|
*/
|
|
|
|
protected $l10nFactory;
|
|
|
|
|
2022-01-11 19:59:51 +01:00
|
|
|
/**
|
|
|
|
* @var ConfigProxy
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CategoryRepository
|
|
|
|
*/
|
|
|
|
protected $categoryRepository;
|
|
|
|
|
2023-07-15 15:22:09 +02:00
|
|
|
/**
|
|
|
|
* @var INavigationManager
|
|
|
|
*/
|
|
|
|
protected $navigationManager;
|
|
|
|
|
2022-01-11 19:59:51 +01:00
|
|
|
public function __construct(
|
|
|
|
\OC_App $ocApp,
|
2023-07-15 14:50:15 +02:00
|
|
|
INavigationManager $navigationManager,
|
2022-01-11 19:59:51 +01:00
|
|
|
IFactory $l10nFactory,
|
|
|
|
ConfigProxy $config,
|
|
|
|
CategoryRepository $categoryRepository
|
2022-10-27 20:30:14 +02:00
|
|
|
) {
|
2020-08-06 15:00:59 +02:00
|
|
|
$this->ocApp = $ocApp;
|
2020-08-13 11:21:06 +02:00
|
|
|
$this->l10nFactory = $l10nFactory;
|
2022-01-11 19:59:51 +01:00
|
|
|
$this->config = $config;
|
2023-07-15 14:50:15 +02:00
|
|
|
$this->navigationManager = $navigationManager;
|
2022-01-11 19:59:51 +01:00
|
|
|
$this->categoryRepository = $categoryRepository;
|
2020-08-06 15:00:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves visibles apps.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getVisibleApps()
|
|
|
|
{
|
2023-07-10 20:14:42 +02:00
|
|
|
$navigation = $this->navigationManager->getAll();
|
2022-01-11 19:59:51 +01:00
|
|
|
$appCategoriesCustom = $this->config->getAppValueArray('apps-categories-custom', '[]');
|
|
|
|
$categories = $this->categoryRepository->getOrderedCategories();
|
2020-08-13 11:21:59 +02:00
|
|
|
$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])) {
|
2022-10-27 20:30:14 +02:00
|
|
|
$app['name'] = $this->getAppName($app);
|
2020-08-19 09:18:29 +02:00
|
|
|
$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'],
|
2022-10-27 20:30:14 +02:00
|
|
|
'name' => $this->getAppName($app),
|
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'],
|
2022-10-27 20:30:14 +02:00
|
|
|
'name' => $this->getAppName($app),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-11 19:59:51 +01:00
|
|
|
foreach ($visibleApps as $id => $app) {
|
2022-01-11 20:20:44 +01:00
|
|
|
if (isset($appCategoriesCustom[$id], $categories[$appCategoriesCustom[$id]])) {
|
2022-01-11 19:59:51 +01:00
|
|
|
$visibleApps[$id]['category'] = [$appCategoriesCustom[$id]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 15:00:59 +02:00
|
|
|
return $visibleApps;
|
|
|
|
}
|
2022-10-21 17:59:41 +02:00
|
|
|
|
2022-10-27 20:30:14 +02:00
|
|
|
public function getAppName($app)
|
|
|
|
{
|
|
|
|
return $this->config->getAppValue(
|
|
|
|
'app.navigation.name',
|
|
|
|
$this->l10nFactory->get($app['id'])->t($app['name']),
|
|
|
|
$app['id']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:07:44 +01:00
|
|
|
public function getOrderedApps(?User $user = null)
|
2022-10-21 17:59:41 +02:00
|
|
|
{
|
|
|
|
$apps = $this->getVisibleApps();
|
2022-10-27 21:51:58 +02:00
|
|
|
$orders = $this->config->getAppValueArray('apps-order', '[]');
|
2022-10-21 17:59:41 +02:00
|
|
|
|
2022-11-04 21:07:44 +01:00
|
|
|
if (null !== $user && !$this->config->getAppValueBool('force', '0')) {
|
|
|
|
$userOrders = $this->config->getUserValueArray($user, 'apps-order', '[]');
|
|
|
|
|
|
|
|
if (!empty($userOrders)) {
|
|
|
|
$orders = $userOrders;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 17:59:41 +02:00
|
|
|
usort($apps, function ($a, $b) use ($orders) {
|
|
|
|
$ak = array_keys($orders, $a['id'])[0] ?? null;
|
|
|
|
$bk = array_keys($orders, $b['id'])[0] ?? null;
|
|
|
|
|
2022-10-27 20:30:14 +02:00
|
|
|
if (null === $ak || null === $bk) {
|
2022-10-21 17:59:41 +02:00
|
|
|
return ($a['name'] < $b['name']) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ak < $bk ? -1 : 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
return $apps;
|
|
|
|
}
|
2020-08-06 15:00:59 +02:00
|
|
|
}
|