cp6 / my-idlers

Web app for displaying, organizing and storing information about servers (VPS), shared hosting, reseller hosting, domains and more.
https://demo.myidlers.com
MIT License
244 stars 30 forks source link

Wrong data type when counting service count #108

Open AhmadShamli opened 6 months ago

AhmadShamli commented 6 months ago

my-idlers V2.3.2

on file app/Models/Home.php

    public static function servicesCount()
        {
            return Cache::remember('services_count', now()->addHours(6), function () {
                $count = DB::table('pricings')
                    ->select('service_type', DB::raw('COUNT(*) as amount'))
                    ->groupBy('service_type')
                    ->where('active', 1)
                    ->get();
                var_dump($count);
                return $count;
            });
        }

will produce

    object(Illuminate\Support\Collection)#1121 (2) { ["items":protected]=> array(2) { [0]=> object(stdClass)#1269 (2) { ["service_type"]=> string(1) "1" ["amount"]=> string(1) "3" } [1]=> object(stdClass)#1282 (2) { ["service_type"]=> string(1) "3" ["amount"]=> string(1) "1" } } ["escapeWhenCastingToString":protected]=> bool(false) }

notice that the service_type is string

while on the same file

    public static function doServicesCount($services_count): array
        {
            $services_count = json_decode($services_count, true);
            return Cache::remember('services_count_all', now()->addWeek(1), function () use ($services_count) {
                $servers_count = $domains_count = $shared_count = $reseller_count = $other_count = $seedbox_count = $total_services = 0;
                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
                );
            });

        }

it is try to match exact type of int value, this result in empty (0) value on Home page....

AhmadShamli commented 6 months ago

the same goes for breakdownPricing() in the same file

AhmadShamli commented 6 months ago

on file resources/views/home.blade.php

also require to change to @if(Session::get('timer_version_footer', 0) == 1) as the type didnt match

cp6 commented 6 months ago

@AhmadShamli

Im not getting the string type when debugging and the counts work as expected, interested to see if others get this issue:

= Illuminate\Support\Collection {#5611 all: [ {#5609 +"service_type": 1, +"amount": 1, }, {#5605 +"service_type": 2, +"amount": 1, }, {#5607 +"service_type": 3, +"amount": 1, }, {#5606 +"service_type": 4, +"amount": 1, }, ], }

AhmadShamli commented 6 months ago

HI,

below would be the server information:

Host: Namecrane (BuyShared) server: lv-shared01.dapanel.net php: php 8.1.28 loaded ext: Array ( [0] => Core [1] => date [2] => libxml [3] => openssl [4] => pcre [5] => sqlite3 [6] => zlib [7] => bz2 [8] => calendar [9] => ctype [10] => curl [11] => hash [12] => filter [13] => ftp [14] => gettext [15] => json [16] => iconv [17] => SPL [18] => pcntl [19] => readline [20] => Reflection [21] => session [22] => standard [23] => mbstring [24] => shmop [25] => SimpleXML [26] => tokenizer [27] => xml [28] => litespeed [29] => i360 [30] => bcmath [31] => dom [32] => fileinfo [33] => gd [34] => imagick [35] => intl [36] => exif [37] => mysqlnd [38] => mysqli [39] => PDO [40] => pdo_mysql [41] => pdo_sqlite [42] => Phar [43] => posix [44] => soap [45] => sockets [46] => sodium [47] => xmlreader [48] => xmlwriter [49] => xsl [50] => zip )