Updated Home controller

Moved last logics into model

Added comments

Simplified calls
This commit is contained in:
cp6 2022-05-16 16:22:19 +10:00
parent 24a583f3fd
commit ebb8edaac3
2 changed files with 54 additions and 39 deletions

View File

@ -26,58 +26,37 @@ class HomeController extends Controller
$p = new Process(); $p = new Process();
$p->startTimer(); $p->startTimer();
$services_count = Home::servicesCount(); //Get & set the settings, 1 minute cache
$due_soon = Home::dueSoonData();
$server_summary = Home::serverSummary();
//Check for past due date and refresh the due date if so:
$due_soon = Home::doDueSoon($due_soon);
$recently_added = Home::recentlyAdded();
$settings = Settings::getSettings(); $settings = Settings::getSettings();
Settings::setSettingsToSession($settings); Settings::setSettingsToSession($settings);
$all_pricing = Pricing::allPricing(); //Check for past due date and refresh the due date if so:
$due_soon = Home::doDueSoon(Home::dueSoonData());
$services_count = json_decode($services_count, true); //Orders services most recently added first, cached with limit from settings
$recently_added = Home::recentlyAdded();
$servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0; //Get count tally for each of the services type
$service_count = Home::doServicesCount(Home::servicesCount());
foreach ($services_count as $sc) { //Get pricing for weekly, monthly, yearly, 2 yearly
$total_services += $sc['amount']; $pricing_breakdown = Home::breakdownPricing(Pricing::allPricing());
if ($sc['service_type'] === 1) {
$servers_count = $sc['amount'];
} else if ($sc['service_type'] === 2) {
$shared_count = $sc['amount'];
} else if ($sc['service_type'] === 3) {
$reseller_count = $sc['amount'];
} else if ($sc['service_type'] === 4) {
$domains_count = $sc['amount'];
} else if ($sc['service_type'] === 5) {
$other_count = $sc['amount'];
} else if ($sc['service_type'] === 6) {
$seedbox_count = $sc['amount'];
}
}
$pricing_breakdown = Home::breakdownPricing($all_pricing); //Summary of servers specs
$server_summary = Home::serverSummary();
$p->stopTimer(); $p->stopTimer();
$information = array( $information = array(
'servers' => $servers_count, 'servers' => $service_count['servers'],
'domains' => $domains_count, 'domains' => $service_count['domains'],
'shared' => $shared_count, 'shared' => $service_count['shared'],
'reseller' => $reseller_count, 'reseller' => $service_count['reseller'],
'misc' => $other_count, 'misc' => $service_count['other'],
'seedbox' => $seedbox_count, 'seedbox' => $service_count['seedbox'],
'labels' => Labels::labelsCount(), 'labels' => Labels::labelsCount(),
'dns' => DNS::dnsCount(), 'dns' => DNS::dnsCount(),
'total_services' => $total_services, 'total_services' => $service_count['total'],
'total_inactive' => $pricing_breakdown['inactive_count'], 'total_inactive' => $pricing_breakdown['inactive_count'],
'total_cost_weekly' => number_format($pricing_breakdown['total_cost_weekly'], 2), 'total_cost_weekly' => number_format($pricing_breakdown['total_cost_weekly'], 2),
'total_cost_monthly' => number_format($pricing_breakdown['total_cost_montly'], 2), 'total_cost_monthly' => number_format($pricing_breakdown['total_cost_montly'], 2),

View File

@ -151,4 +151,40 @@ class Home extends Model
'inactive_count' => $inactive_count, 'inactive_count' => $inactive_count,
); );
} }
public static function doServicesCount($services_count): array
{
$servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
$services_count = json_decode($services_count, true);
foreach ($services_count as $sc) {
$total_services += $sc['amount'];
if ($sc['service_type'] === 1) {
$servers_count = $sc['amount'];
} else if ($sc['service_type'] === 2) {
$shared_count = $sc['amount'];
} else if ($sc['service_type'] === 3) {
$reseller_count = $sc['amount'];
} else if ($sc['service_type'] === 4) {
$domains_count = $sc['amount'];
} else if ($sc['service_type'] === 5) {
$other_count = $sc['amount'];
} else if ($sc['service_type'] === 6) {
$seedbox_count = $sc['amount'];
}
}
return array(
'servers' => $servers_count,
'shared' => $shared_count,
'reseller' => $reseller_count,
'domains' => $domains_count,
'other' => $other_count,
'seedbox' => $seedbox_count,
'total' => $total_services
);
}
} }