Issues (1369)

classes/Pages/Deprecated/PageAdminModules.php (4 issues)

1
<?php
2
/**
3
 * Created by Gorlum 05.03.2018 12:57
4
 */
5
6
namespace Pages\Deprecated;
7
8
use Modules\sn_module;
9
use SN;
10
use SnTemplate;
11
12
class PageAdminModules extends PageDeprecated {
13
  const SORT_BY_PACKAGE = 0;
14
  const SORT_BY_ACTIVITY = 1;
15
16
  private static $sorting = [
17
    self::SORT_BY_PACKAGE  => ['PACKAGE', 'NAME', '!ACTIVE', '!INSTALLED',],
18
    self::SORT_BY_ACTIVITY => ['!ACTIVE', '!INSTALLED', 'PACKAGE', 'NAME',],
19
  ];
20
21
  private static $sortFields = [];
22
23
  /**
24
   * @param array $a
25
   * @param array $b
26
   *
27
   * @return int
28
   */
29
  private static function sortBy($a, $b) {
30
    $result = 0;
31
    foreach (static::$sortFields as $fieldName) {
0 ignored issues
show
Since $sortFields is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sortFields to at least protected.
Loading history...
32
      if (strpos($fieldName, '!') !== false) {
33
        $fieldName = substr($fieldName, 1);
34
        $c = $a;
35
        $a = $b;
36
        $b = $c;
37
      }
38
      if ($result = $a[$fieldName] > $b[$fieldName] ? 1 : ($a[$fieldName] < $b[$fieldName] ? -1 : 0)) {
39
        break;
40
      }
41
    }
42
43
    return $result;
44
  }
45
46
  public static function viewStatic($template = null) {
0 ignored issues
show
The parameter $template is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
  public static function viewStatic(/** @scrutinizer ignore-unused */ $template = null) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    define('IN_ADMIN', true);
48
49
    lng_include('admin');
50
51
    $modules = SN::$gc->modules->getModulesInGroup([], false);
52
53
    $render = [];
54
    foreach ($modules as $module) {
55
      $render[] = [
56
        'PACKAGE'   => $module->manifest['package'],
57
        'NAME'      => $module->manifest['name'],
58
        'VERSION'   => $module->getVersion(),
59
        'ACTIVE'    => $module->isActive(),
60
        'INSTALLED' => $module->isInstalled(),
61
      ];
62
    }
63
64
    $sortBy = sys_get_param_int('SORT_BY', self::SORT_BY_ACTIVITY);
65
    array_key_exists($sortBy, static::$sorting) ?: ($sortBy = self::SORT_BY_ACTIVITY);
0 ignored issues
show
Since $sorting is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sorting to at least protected.
Loading history...
66
    static::$sortFields = static::$sorting[$sortBy];
0 ignored issues
show
Since $sortFields is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $sortFields to at least protected.
Loading history...
67
    usort($render, [static::class, 'sortBy']);
68
69
    $template = SnTemplate::gettemplate('admin/admin_modules');
70
    $template->assign_recursive([
71
      '.'         => ['modules' => $render],
72
      'SORT_BY'   => $sortBy,
73
      'PAGE_NAME' => SN::$lang['menu_admin_modules'],
74
    ]);
75
76
    SnTemplate::display($template, SN::$lang['menu_admin_modules']);
77
  }
78
79
}
80