| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 1.0.13 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2022 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Admin\Analytics\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class ResultsHelper |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Sumarize the total metrics from a set of results |
| 23 |
* |
| 24 |
* @param array $results |
| 25 |
* |
| 26 |
* @return int |
| 27 |
*/ |
| 28 |
public static function sumTotalFromResults($results) |
| 29 |
{ |
| 30 |
if (!$results) |
| 31 |
{ |
| 32 |
return 0; |
| 33 |
} |
| 34 |
|
| 35 |
if (!is_array($results)) |
| 36 |
{ |
| 37 |
return 0; |
| 38 |
} |
| 39 |
|
| 40 |
if (!count($results)) |
| 41 |
{ |
| 42 |
return 0; |
| 43 |
} |
| 44 |
|
| 45 |
$sum = array_reduce($results, function($total, $res) |
| 46 |
{ |
| 47 |
$res = (array) $res; |
| 48 |
|
| 49 |
if (!isset($res['total'])) |
| 50 |
{ |
| 51 |
return $total += 0; |
| 52 |
} |
| 53 |
|
| 54 |
return $total += (float) $res['total']; |
| 55 |
}); |
| 56 |
|
| 57 |
return $sum; |
| 58 |
} |
| 59 |
} |