| 1 |
<?php |
| 2 |
/** |
| 3 |
* Report: Chart |
| 4 |
* |
| 5 |
* @package SimplePay |
| 6 |
* @subpackage Core |
| 7 |
* @copyright Copyright (c) 2023, Sandhills Development, LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 4.6.7 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace SimplePay\Core\Report\Chart; |
| 13 |
|
| 14 |
/** |
| 15 |
* ChartTrait trait. |
| 16 |
* |
| 17 |
* @since 4.6.7 |
| 18 |
*/ |
| 19 |
trait ChartTrait { |
| 20 |
|
| 21 |
/** |
| 22 |
* Calculates a dataset's "total" amount. |
| 23 |
* |
| 24 |
* @since 4.6.7 |
| 25 |
* |
| 26 |
* @param array<int, array<string, mixed>> $dataset The formatted dataset. |
| 27 |
* @return int |
| 28 |
*/ |
| 29 |
private function get_chart_formatted_dataset_total( $dataset ) { |
| 30 |
return array_reduce( |
| 31 |
$dataset, |
| 32 |
function( $total, $datapoint ) { |
| 33 |
/** @var array<string, mixed> $datapoint */ |
| 34 |
/** @var int $total */ |
| 35 |
/** @var int $y */ |
| 36 |
$y = $datapoint['y']; |
| 37 |
return $total + $y; |
| 38 |
}, |
| 39 |
0 |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Returns the primary color for the current user's admin color scheme. |
| 45 |
* |
| 46 |
* @since 4.7.3 |
| 47 |
* |
| 48 |
* @return array<int> RGB color values. |
| 49 |
*/ |
| 50 |
protected function get_user_color_scheme_pref_primary_color() { |
| 51 |
$color_scheme = get_user_meta( |
| 52 |
get_current_user_id(), |
| 53 |
'admin_color', |
| 54 |
true |
| 55 |
); |
| 56 |
|
| 57 |
switch ( $color_scheme ) { |
| 58 |
case 'modern': |
| 59 |
return array( 56, 88, 233 ); |
| 60 |
case 'light': |
| 61 |
case 'blue': |
| 62 |
return array( 9, 100, 132 ); |
| 63 |
case 'coffee': |
| 64 |
return array( 199, 165, 137 ); |
| 65 |
case 'ectoplasm': |
| 66 |
return array( 163, 183, 69 ); |
| 67 |
case 'midnight': |
| 68 |
case 'ocean': |
| 69 |
return array( 105, 168, 187 ); |
| 70 |
case 'sunrise': |
| 71 |
return array( 207, 73, 68 ); |
| 72 |
default: |
| 73 |
return array( 66, 138, 202 ); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|