Browse Source

Little Tweeks + Sort Function for array

pull/1/head
GamerClassN7 1 year ago
parent
commit
5ad11cbb10
3 changed files with 31 additions and 14 deletions
  1. +25
    -0
      app/models/Utilities.php
  2. +4
    -12
      app/views/Device.php
  3. +2
    -2
      app/views/Plugins.php

+ 25
- 0
app/models/Utilities.php View File

@ -178,4 +178,29 @@ class Utilities
return $result;
}
/**
* Sort Array by keys
*
* @param array $data
* @param [type] $key
* @param string $operator ('asc'/'desc')
* @return void
*/
static function sortArrayByKey($data = [], $key, $operator = "asc"){
if ($operator == "asc")
{
uasort($data, function($a, $b) use ($key){
if ($a[$key] == $b[$key]) return 0;
return ($a[$key] < $b[$key]) ? -1 : 1;
});
} else{
uasort($data, function($a, $b) use ($key){
if ($a[$key] == $b[$key]) return 0;
return ($a[$key] > $b[$key]) ? -1 : 1;
});
}
return $data;
}
}

+ 4
- 12
app/views/Device.php View File

@ -103,23 +103,15 @@ class Device extends Template
if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "firmware") {
if ($_GET['sortType'] == "DESC") {
usort($devices, function($a, $b) {
return $a['firmware_hash'] <=> $b['firmware_hash'];
});
return Utilities::sortArrayByKey($devices, 'firmware_hash', "desc");
} else if ($_GET['sortType'] == "ASC") {
usort($devices, function($a, $b) {
return $b['firmware_hash'] <=> $a['firmware_hash'];
});
return Utilities::sortArrayByKey($devices, 'firmware_hash', "asc");
}
} else if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "signal") {
if ($_GET['sortType'] == "DESC") {
usort($devices, function($a, $b) {
return $a['signal'] <=> $b['signal'];
});
return Utilities::sortArrayByKey($devices, 'signal', "desc");
} else if ($_GET['sortType'] == "ASC") {
usort($devices, function($a, $b) {
return $b['signal'] <=> $a['signal'];
});
return Utilities::sortArrayByKey($devices, 'signal', "asc");
}
}

+ 2
- 2
app/views/Plugins.php View File

@ -21,8 +21,8 @@ class Plugins extends Template
$plugins[$key]['status'] = $status;
}
sort($plugins);
$plugins = Utilities::sortArrayByKey($plugins, 'status', "desc");
$template = new Template('plugins');
$template->prepare('baseDir', BASEDIR);
$template->prepare('debugMod', DEBUGMOD);

Loading…
Cancel
Save