You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

appsettingscontroller.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * @author Lukas Reschke
  4. * @author Thomas Müller
  5. * @copyright 2014 Lukas Reschke lukas@owncloud.com, 2014 Thomas Müller deepdiver@owncloud.com
  6. *
  7. * This file is licensed under the Affero General Public License version 3 or
  8. * later.
  9. * See the COPYING-README file.
  10. */
  11. namespace OC\Settings\Controller;
  12. use OC\App\DependencyAnalyzer;
  13. use OC\App\Platform;
  14. use \OCP\AppFramework\Controller;
  15. use OCP\IRequest;
  16. use OCP\IL10N;
  17. use OCP\IConfig;
  18. /**
  19. * @package OC\Settings\Controller
  20. */
  21. class AppSettingsController extends Controller {
  22. /** @var \OCP\IL10N */
  23. private $l10n;
  24. /** @var IConfig */
  25. private $config;
  26. /**
  27. * @param string $appName
  28. * @param IRequest $request
  29. * @param IL10N $l10n
  30. * @param IConfig $config
  31. */
  32. public function __construct($appName,
  33. IRequest $request,
  34. IL10N $l10n,
  35. IConfig $config) {
  36. parent::__construct($appName, $request);
  37. $this->l10n = $l10n;
  38. $this->config = $config;
  39. }
  40. /**
  41. * Get all available categories
  42. * @return array
  43. */
  44. public function listCategories() {
  45. $categories = array(
  46. array('id' => 0, 'displayName' => (string)$this->l10n->t('Enabled') ),
  47. array('id' => 1, 'displayName' => (string)$this->l10n->t('Not enabled') ),
  48. );
  49. if($this->config->getSystemValue('appstoreenabled', true)) {
  50. $categories[] = array('id' => 2, 'displayName' => (string)$this->l10n->t('Recommended') );
  51. // apps from external repo via OCS
  52. $ocs = \OC_OCSClient::getCategories();
  53. foreach($ocs as $k => $v) {
  54. $categories[] = array(
  55. 'id' => $k,
  56. 'displayName' => str_replace('ownCloud ', '', $v)
  57. );
  58. }
  59. }
  60. $categories['status'] = 'success';
  61. return $categories;
  62. }
  63. /**
  64. * Get all available categories
  65. * @param int $category
  66. * @return array
  67. */
  68. public function listApps($category = 0) {
  69. $apps = array();
  70. switch($category) {
  71. // installed apps
  72. case 0:
  73. $apps = \OC_App::listAllApps(true);
  74. $apps = array_filter($apps, function($app) {
  75. return $app['active'];
  76. });
  77. break;
  78. // not-installed apps
  79. case 1:
  80. $apps = \OC_App::listAllApps(true);
  81. $apps = array_filter($apps, function($app) {
  82. return !$app['active'];
  83. });
  84. break;
  85. default:
  86. if ($category === 2) {
  87. $apps = \OC_App::getAppstoreApps('approved');
  88. $apps = array_filter($apps, function($app) {
  89. return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
  90. });
  91. } else {
  92. $apps = \OC_App::getAppstoreApps('approved', $category);
  93. }
  94. if (!$apps) {
  95. $apps = array();
  96. }
  97. usort($apps, function ($a, $b) {
  98. $a = (int)$a['score'];
  99. $b = (int)$b['score'];
  100. if ($a === $b) {
  101. return 0;
  102. }
  103. return ($a > $b) ? -1 : 1;
  104. });
  105. break;
  106. }
  107. // fix groups to be an array
  108. $apps = array_map(function($app){
  109. $groups = array();
  110. if (is_string($app['groups'])) {
  111. $groups = json_decode($app['groups']);
  112. }
  113. $app['groups'] = $groups;
  114. $app['canUnInstall'] = !$app['active'] && $app['removable'];
  115. // analyse dependencies
  116. $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($this->config), $this->l10n);
  117. $missing = $dependencyAnalyzer->analyze();
  118. $app['canInstall'] = empty($missing);
  119. $app['missingDependencies'] = $missing;
  120. return $app;
  121. }, $apps);
  122. return array('apps' => $apps, 'status' => 'success');
  123. }
  124. }