Little Tweeks + Sort Function for array
This commit is contained in:
parent
a4cdb250b9
commit
5ad11cbb10
@ -178,4 +178,29 @@ class Utilities
|
|||||||
|
|
||||||
return $result;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,23 +103,15 @@ class Device extends Template
|
|||||||
|
|
||||||
if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "firmware") {
|
if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "firmware") {
|
||||||
if ($_GET['sortType'] == "DESC") {
|
if ($_GET['sortType'] == "DESC") {
|
||||||
usort($devices, function($a, $b) {
|
return Utilities::sortArrayByKey($devices, 'firmware_hash', "desc");
|
||||||
return $a['firmware_hash'] <=> $b['firmware_hash'];
|
|
||||||
});
|
|
||||||
} else if ($_GET['sortType'] == "ASC") {
|
} else if ($_GET['sortType'] == "ASC") {
|
||||||
usort($devices, function($a, $b) {
|
return Utilities::sortArrayByKey($devices, 'firmware_hash', "asc");
|
||||||
return $b['firmware_hash'] <=> $a['firmware_hash'];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "signal") {
|
} else if (!empty ($_GET['sort']) && !empty ($_GET['sortType']) && $_GET['sort'] == "signal") {
|
||||||
if ($_GET['sortType'] == "DESC") {
|
if ($_GET['sortType'] == "DESC") {
|
||||||
usort($devices, function($a, $b) {
|
return Utilities::sortArrayByKey($devices, 'signal', "desc");
|
||||||
return $a['signal'] <=> $b['signal'];
|
|
||||||
});
|
|
||||||
} else if ($_GET['sortType'] == "ASC") {
|
} else if ($_GET['sortType'] == "ASC") {
|
||||||
usort($devices, function($a, $b) {
|
return Utilities::sortArrayByKey($devices, 'signal', "asc");
|
||||||
return $b['signal'] <=> $a['signal'];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class Plugins extends Template
|
|||||||
$plugins[$key]['status'] = $status;
|
$plugins[$key]['status'] = $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
sort($plugins);
|
$plugins = Utilities::sortArrayByKey($plugins, 'status', "desc");
|
||||||
|
|
||||||
$template = new Template('plugins');
|
$template = new Template('plugins');
|
||||||
$template->prepare('baseDir', BASEDIR);
|
$template->prepare('baseDir', BASEDIR);
|
||||||
|
Loading…
Reference in New Issue
Block a user