mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Refactor order assignment logic in sortChannelsBySubscribers.php for clarity and consistency
This commit is contained in:
parent
383fc29cca
commit
50354a0cfd
1 changed files with 6 additions and 8 deletions
|
@ -33,17 +33,16 @@ uasort($sections, function ($a, $b) {
|
||||||
return $b['total_subscribers'] <=> $a['total_subscribers'];
|
return $b['total_subscribers'] <=> $a['total_subscribers'];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get all available current_order values (sorted ascending)
|
// Get all existing order values and sort them
|
||||||
$availableOrders = array_column($sections, 'current_order');
|
$availableOrders = array_column($sections, 'current_order');
|
||||||
sort($availableOrders);
|
sort($availableOrders);
|
||||||
|
|
||||||
// Reassign the lowest available order to the user with most subscribers
|
// Assign the sorted order values to the sorted channels
|
||||||
$index = 0;
|
$orderIndex = 0;
|
||||||
foreach ($sections as $key => &$section) {
|
foreach ($sections as $key => &$section) {
|
||||||
$newOrder = $availableOrders[$index];
|
$obj->$key = $availableOrders[$orderIndex];
|
||||||
$obj->$key = $newOrder;
|
$section['new_order'] = $availableOrders[$orderIndex];
|
||||||
$section['new_order'] = $newOrder;
|
$orderIndex++;
|
||||||
$index++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the new object data
|
// Save the new object data
|
||||||
|
@ -56,5 +55,4 @@ foreach ($sections as $data) {
|
||||||
$u = new User($data['users_id']);
|
$u = new User($data['users_id']);
|
||||||
$channelName = $u->getChannelName();
|
$channelName = $u->getChannelName();
|
||||||
echo "User: [{$data['users_id']}][$channelName]{$identification} | New Order: {$data['new_order']} | Subscribers: {$data['total_subscribers']}\n";
|
echo "User: [{$data['users_id']}][$channelName]{$identification} | New Order: {$data['new_order']} | Subscribers: {$data['total_subscribers']}\n";
|
||||||
//echo "users_id: {$data['users_id']} | Subscribers: {$data['total_subscribers']} | New Order: {$data['new_order']}\n";
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue