From 3889921888032ab84a0bc5c7b65fa76ada0dd61e Mon Sep 17 00:00:00 2001 From: bessantoy Date: Mon, 16 Sep 2024 09:55:43 +0200 Subject: [PATCH 1/5] Add cards and filter --- hook.php | 8 + inc/dashboardcards.class.php | 619 +++++++++++++++++++++++++++++++++ inc/dashboardfilters.class.php | 73 ++++ setup.php | 2 + 4 files changed, 702 insertions(+) create mode 100644 inc/dashboardcards.class.php create mode 100644 inc/dashboardfilters.class.php diff --git a/hook.php b/hook.php index c0db3e9..d95e51d 100644 --- a/hook.php +++ b/hook.php @@ -176,3 +176,11 @@ function plugin_credit_get_datas(NotificationTargetTicket $target) ]; } } + +function plugin_credit_dashboardcards($cards = []): array +{ + if (is_null($cards)) { + $cards = []; + } + return array_merge($cards, PluginCreditDashboardCards::getCards()); +} \ No newline at end of file diff --git a/inc/dashboardcards.class.php b/inc/dashboardcards.class.php new file mode 100644 index 0000000..5093792 --- /dev/null +++ b/inc/dashboardcards.class.php @@ -0,0 +1,619 @@ + ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Initial credit"), + 'provider' => PluginCreditDashboardCards::class . "::nbCredits", + 'filters' => [ + 'credit' + ] + ]; + + $cards["bn_credit_used"] = [ + 'widgettype' => ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Used credit"), + 'provider' => PluginCreditDashboardCards::class . "::nbCreditsUsed", + 'filters' => [ + 'credit' + ] + ]; + + $cards["bn_credit_remaining"] = [ + 'widgettype' => ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Remaining credit"), + 'provider' => PluginCreditDashboardCards::class . "::nbCreditsRemaining", + 'filters' => [ + 'credit' + ] + ]; + + $cards["bn_percent_credit_remaining"] = [ + 'widgettype' => ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Proportion of credit remaining"), + 'provider' => PluginCreditDashboardCards::class . "::percentCreditsRemaining", + 'filters' => [ + 'credit','entity' + ] + ]; + + $cards["bn_percent_credit_used"] = [ + 'widgettype' => ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Proportion of credit used"), + 'provider' => PluginCreditDashboardCards::class . "::percentCreditsUsed", + 'filters' => [ + 'credit' + ] + ]; + + $cards["date_end_ticket"] = [ + 'widgettype' => ["bigNumber"], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("End date of the contract"), + 'provider' => PluginCreditDashboardCards::class . "::getDateEndingCredit", + 'filters' => [ + 'credit' + ] + ]; + + $cards["credits_consumption_ticket"] = [ + 'widgettype' => ['bars'], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Credit consumption by ticket"), + 'provider' => PluginCreditDashboardCards::class . "::getCreditsConsumption", + 'filters' => [ + 'credit' + ] + ]; + + $cards["credits_evolution_period"] = [ + 'widgettype' => ['lines', 'bars', 'areas'], + 'itemtype' => "\\Credit", + 'group' => __('Credit'), + 'label' => __("Evolutions of credit consumption"), + 'provider' => PluginCreditDashboardCards::class . "::getCreditsEvolution", + 'filters' => [ + 'credit' + ] + ]; + + return $cards; + } + + /** + * @param array $params + * @return array + */ + public static function nbCredits(array $params = []): array + { + global $DB; + + $active_entity = Session::getActiveEntity(); + + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'initial quantity of credit' + ]; + $params = array_merge($default_params, $params); + + $t_table = PluginCreditEntity::getTable(); + + $criteria = array_merge_recursive( + [ + 'SELECT' => [ + 'quantity' + ], + 'FROM' => $t_table, + 'WHERE' => [ + "$t_table.entities_id" => $active_entity + ] + + ], + + Provider::getFiltersCriteria($t_table, $params['apply_filters']) + ); + + $nb_items=0; + foreach ($DB->request($criteria) as $id => $row) { + $nb_items+=$row['quantity']; + } + + return [ + 'number' => $nb_items, + 'url' => '', + 'label' => 'Initial quantity of credit', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + /** + * Date format : MM/YY + * + * @param array $params default values for + * - 'title' of the card + * - 'icon' of the card + * - 'apply_filters' values from dashboard filters + * + * @return array + */ + public static function getDateEndingCredit(array $params = []): array + { + global $DB; + + $active_entity = Session::getActiveEntity(); + + + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'End date of the contract', + ]; + $params = array_merge($default_params, $params); + + $t_table = PluginCreditEntity::getTable(); + $criteria = array_merge_recursive( + [ + 'SELECT' => [ + 'end_date', + ], + 'FROM' => $t_table, + 'WHERE' => [ + "$t_table.entities_id" => $active_entity + ] + + ], + Provider::getFiltersCriteria($t_table, $params['apply_filters']) + ); + + + $iterator = $DB->request($criteria); + + $result = $iterator->current(); + + if(isset($result['end_date'])){ + $date = date_create($result['end_date']); + $date = date_format($date, 'm/y'); + return [ + 'number' => $date, + 'url' => '', + 'label' => 'End date of the contract', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + + }else{ + + return [ + 'number' => 0, + 'url' => '', + 'label' => 'No end date', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + + } + + /** + * + * @param array $params default values for + * - 'title' of the card + * - 'icon' of the card + * - 'apply_filters' values from dashboard filters + * + * @return array + */ + public static function nbCreditsUsed(array $params = []): array + { + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'Quantity of credit used', + ]; + $params = array_merge($default_params, $params); + + $tab = self::getCredits($params); + + return [ + 'number' => $tab['sum'], + 'url' => '', + 'label' => 'Quantity of credit used', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + /** + * + * @param array $params default values for + * - 'title' of the card + * - 'icon' of the card + * - 'apply_filters' values from dashboard filters + * + * @return array + */ + public static function nbCreditsRemaining(array $params = []): array + { + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'Quantity of credit remaining', + ]; + $params = array_merge($default_params, $params); + + $tab = self::getCredits($params); + + $result = $tab['quantity'] - $tab['sum']; + + $result = $result < 0 ? 0 : $result; + + return [ + 'number' => $result, + 'url' => '', + 'label' => 'Quantity of credit remaining', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + /** + * @param array $params + * @return array + */ + public static function percentCreditsUsed(array $params = []): array + { + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'Proportion of credit used', + ]; + $params = array_merge($default_params, $params); + + $tab = self::getCredits($params); + + $result = $tab['quantity']!=0 ? (($tab['sum']) / $tab['quantity']) * 100 : 0; + + return [ + 'number' => round($result,0,PHP_ROUND_HALF_DOWN) . '%', + 'url' => '', + 'label' => 'Proportion of credit used', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + /** + * @param array $params + * @return array + */ + public static function percentCreditsRemaining(array $params = []): array + { + $default_params = [ + 'label' => "", + 'icon' => self::getIconWallet(), + 'apply_filters' => [], + 'alt' =>'Proportion of credits remaining', + ]; + $params = array_merge($default_params, $params); + + $tab = self::getCredits($params); + + $result = $tab['quantity']!=0 ? (($tab['quantity'] - $tab['sum']) / $tab['quantity']) * 100 : 0; + + $result = $result < 0 ? 0 : $result; + + + + return [ + 'number' => round($result,0,PHP_ROUND_HALF_DOWN) . '%', + 'url' => '', + 'label' => 'Proportion of credits remaining', + 'icon' => $default_params['icon'], + 'alt' => $default_params['alt'] + ]; + } + + /** + * + * @param array $params default values for + * - 'title' of the card + * - 'icon' of the card + * - 'apply_filters' values from dashboard filters + * + * @return array + */ + public static function getCreditsConsumption(array $params = []): array + { + global $DB; + + $active_entity = Session::getActiveEntity(); + + + $default_params = [ + 'label' => "", + 'icon' => "", + 'apply_filters' => [], + 'alt' =>'Quantity of credit consumed', + ]; + $params = array_merge($default_params, $params); + + $t_table = PluginCreditEntity::getTable(); + $s_table = PluginCreditTicket::getTable(); + + $criteria = array_merge_recursive( + [ + 'SELECT' => [ + new QueryExpression( + "SUM(IFNULL({$s_table}.consumed, 0)) + as consumed"), + "$s_table.tickets_id" + ], + 'FROM' => $t_table, + 'INNER JOIN' => [ + $s_table => [ + 'ON' => [ + $s_table => 'plugin_credit_entities_id', + $t_table => 'id', + ], + ], + ], + 'WHERE' => [ + "$t_table.entities_id" => $active_entity + ], + 'GROUP'=> [ + "$s_table.tickets_id" + ] + ], Provider::getFiltersCriteria($t_table, $params['apply_filters']) + + ); + + $series = []; + $tickets = []; + $i = 0; + $tab = array(); + + foreach ($DB->request($criteria) as $id => $row) { + $tab += [$row['tickets_id'] => $row['consumed']]; + } + + + foreach ($tab as $ticket => $value) { + + $tickets[$i] = 'Ticket n°' . $ticket; + $series['credit']['name'] = 'Crédit'; + $series['credit']['data'][$i] = [ + 'value' => $value, + 'url' => Ticket::getFormURL() . "?id=" . $ticket + ]; + $i++; + } + + return [ + 'data' => [ + 'labels' => $tickets, + 'series' => array_values($series), + ], + 'label' => $params['label'], + 'icon' => $params['icon'], + 'alt' => $params['alt'] + ]; + } + + /** + * + * @param array $params default values for + * - 'title' of the card + * - 'icon' of the card + * - 'apply_filters' values from dashboard filters + * + * @return array + */ + public static function getCreditsEvolution(array $params = []): array + { + global $DB; + + $active_entity = Session::getActiveEntity(); + + $default_params = [ + 'label' => "", + 'icon' => "", + 'apply_filters' => [], + 'alt' =>'Evolution of credit consumption', + ]; + + $params = array_merge($default_params, $params); + + $e_table = PluginCreditEntity::getTable(); + $t_table = PluginCreditTicket::getTable(); + + $criteria = array_merge_recursive([ + 'SELECT' => [ + new QueryExpression( + "FROM_UNIXTIME(UNIX_TIMESTAMP(" . $DB->quoteName("{$t_table}.date_creation") . "),'%Y-%m') AS period" + ), + new QueryExpression( + "SUM(IFNULL({$t_table}.consumed, 0)) + as ". $DB->quoteValue(_x('status', 'consumed')) + ), + ], + 'FROM' => $t_table, + 'JOIN' => [ + $e_table => [ + 'ON' => [ + $e_table => 'id', + $t_table => 'plugin_credit_entities_id', + ], + ], + ], + 'WHERE' => [ + "$e_table.entities_id" => $active_entity + ], + 'ORDER' => 'period ASC', + 'GROUP' => ['period'], + ],Provider::getFiltersCriteria($e_table, $params['apply_filters'])); + + $monthYears = []; + $series = []; + + $i = 0; + $iterator = $DB->request($criteria); + + foreach ($iterator as $result) { + + $monthYears[] = $result['period']; + $tmp = $result; + + unset($tmp['period']); + + foreach ($tmp as $value) { + + + $series['parmois']['name'] = "Consumption per month"; + $series['parmois']['data'][] = [ + 'value' => (int)$value, + 'url' => '', + ]; + + $series['total']['name'] = "Total consumption"; + if ($i > 0) + { + $series['total']['data'][] = [ + 'value' => (int)$value + $series['total']['data'][$i-1]['value'], + 'url' => '', + ]; + } + else { + $series['total']['data'][] = [ + 'value' => (int)$value, + 'url' => '', + ]; + } + } + $i++; + } + + array_unshift($monthYears, ''); + if (isset($series['total']['data'])){ + array_unshift($series['total']['data'], ['value' => 0, 'url' => '']); + array_unshift($series['parmois']['data'], ['value' => 0, 'url' => '']); + } + + return [ + 'data' => [ + 'labels' => $monthYears, + 'series' => array_values($series), + ], + 'label' => $params['label'], + 'icon' => $params['icon'], + 'alt' => $params['alt'] + ]; + } + + + + public static function getCredits(array $params = []): array + { + global $DB; + + $active_entity = Session::getActiveEntity(); + + + $t_table = PluginCreditEntity::getTable(); + $s_table = PluginCreditTicket::getTable(); + + $criteria_quantity = array_merge_recursive( + [ + 'SELECT' => [ + 'quantity' + ], + 'FROM' => $t_table, + 'WHERE' => [ + "$t_table.entities_id" => $active_entity + ] + + ], + + Provider::getFiltersCriteria($t_table, $params['apply_filters']) + ); + + + $result_quantity = 0; + + foreach ($DB->request($criteria_quantity) as $id => $row) { + $result_quantity += $row['quantity']; + } + + $criteria_sum = array_merge_recursive( + [ + 'SELECT' => [ + 'SUM' => "$s_table.consumed AS sum", + ], + 'FROM' => $t_table, + 'INNER JOIN' => [ + $s_table => [ + 'ON' => [ + $s_table => 'plugin_credit_entities_id', + $t_table => 'id', + ], + ], + ], + 'WHERE' => [ + "$t_table.entities_id" => $active_entity + ] + ], + Provider::getFiltersCriteria($t_table, $params['apply_filters']) + ); + + $result_sum=0; + foreach ($DB->request($criteria_sum) as $id => $row) { + $result_sum += $row['sum']; + } + + return [ + 'quantity' => $result_quantity, + 'sum' => $result_sum + ]; + } + + static function getIconWallet(): string + { + return "fas fa-wallet"; + } +} \ No newline at end of file diff --git a/inc/dashboardfilters.class.php b/inc/dashboardfilters.class.php new file mode 100644 index 0000000..afac034 --- /dev/null +++ b/inc/dashboardfilters.class.php @@ -0,0 +1,73 @@ +fieldExists($table, self::FIELD); + } + + public static function getHtml($value): string + { + return self::displayList( + self::getName(), + is_string($value) ? $value : "", + self::getId(), + PluginCreditEntity::class + ); + } + + public static function getCriteria(string $table, $value): array + { + if ((int) $value > 0) { + $field = self::FIELD; + return [ + "WHERE" => [ + "$table.$field" => (int) $value + ] + ]; + } + + return []; + } + + public static function getSearchCriteria(string $table, $value): array + { + if ((int) $value > 0) { + return [ + [ + 'link' => 'AND', + 'searchtype' => 'equals', + 'value' => (int) $value, + 'field' => self::getSearchOptionID( + $table, + self::FIELD, + PluginCreditEntity::getTable() + ), + ] + ]; + } + + return []; + } + + +} \ No newline at end of file diff --git a/setup.php b/setup.php index d806962..bd840b2 100644 --- a/setup.php +++ b/setup.php @@ -83,6 +83,8 @@ function plugin_init_credit() 'js/credit.js' ]; $PLUGIN_HOOKS['item_get_datas']['credit'] = ['NotificationTargetTicket' => 'plugin_credit_get_datas']; + $PLUGIN_HOOKS['dashboard_cards']['credit'] = 'plugin_credit_dashboardcards'; + $PLUGIN_HOOKS['dashboard_filters']['credit'] = [PluginCreditDashboardFilters::class]; } Plugin::registerClass(PluginCreditProfile::class, ['addtabon' => Profile::class]); From 3f8d749e90878ad21428ac1b775b606824cf2b6a Mon Sep 17 00:00:00 2001 From: bessantoy Date: Wed, 18 Sep 2024 09:49:54 +0200 Subject: [PATCH 2/5] fix CI --- hook.php | 10 ++-- inc/dashboardcards.class.php | 85 +++++++++++++++------------------- inc/dashboardfilters.class.php | 6 +-- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/hook.php b/hook.php index d95e51d..2be3498 100644 --- a/hook.php +++ b/hook.php @@ -179,8 +179,8 @@ function plugin_credit_get_datas(NotificationTargetTicket $target) function plugin_credit_dashboardcards($cards = []): array { - if (is_null($cards)) { - $cards = []; - } - return array_merge($cards, PluginCreditDashboardCards::getCards()); -} \ No newline at end of file + if (is_null($cards)) { + $cards = []; + } + return array_merge($cards, PluginCreditDashboardCards::getCards()); +} diff --git a/inc/dashboardcards.class.php b/inc/dashboardcards.class.php index 5093792..78e3a6c 100644 --- a/inc/dashboardcards.class.php +++ b/inc/dashboardcards.class.php @@ -123,7 +123,7 @@ public static function nbCredits(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'initial quantity of credit' + 'alt' => 'initial quantity of credit' ]; $params = array_merge($default_params, $params); @@ -140,14 +140,13 @@ public static function nbCredits(array $params = []): array ] ], - Provider::getFiltersCriteria($t_table, $params['apply_filters']) ); - $nb_items=0; + $nb_items = 0; foreach ($DB->request($criteria) as $id => $row) { - $nb_items+=$row['quantity']; - } + $nb_items += $row['quantity']; + } return [ 'number' => $nb_items, @@ -179,7 +178,7 @@ public static function getDateEndingCredit(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'End date of the contract', + 'alt' => 'End date of the contract', ]; $params = array_merge($default_params, $params); @@ -203,7 +202,7 @@ public static function getDateEndingCredit(array $params = []): array $result = $iterator->current(); - if(isset($result['end_date'])){ + if (isset($result['end_date'])) { $date = date_create($result['end_date']); $date = date_format($date, 'm/y'); return [ @@ -213,9 +212,7 @@ public static function getDateEndingCredit(array $params = []): array 'icon' => $default_params['icon'], 'alt' => $default_params['alt'] ]; - - }else{ - + } else { return [ 'number' => 0, 'url' => '', @@ -224,8 +221,6 @@ public static function getDateEndingCredit(array $params = []): array 'alt' => $default_params['alt'] ]; } - - } /** @@ -243,7 +238,7 @@ public static function nbCreditsUsed(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'Quantity of credit used', + 'alt' => 'Quantity of credit used', ]; $params = array_merge($default_params, $params); @@ -273,7 +268,7 @@ public static function nbCreditsRemaining(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'Quantity of credit remaining', + 'alt' => 'Quantity of credit remaining', ]; $params = array_merge($default_params, $params); @@ -302,16 +297,16 @@ public static function percentCreditsUsed(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'Proportion of credit used', + 'alt' => 'Proportion of credit used', ]; $params = array_merge($default_params, $params); $tab = self::getCredits($params); - $result = $tab['quantity']!=0 ? (($tab['sum']) / $tab['quantity']) * 100 : 0; + $result = $tab['quantity'] != 0 ? (($tab['sum']) / $tab['quantity']) * 100 : 0; return [ - 'number' => round($result,0,PHP_ROUND_HALF_DOWN) . '%', + 'number' => round($result, 0, PHP_ROUND_HALF_DOWN) . '%', 'url' => '', 'label' => 'Proportion of credit used', 'icon' => $default_params['icon'], @@ -329,20 +324,20 @@ public static function percentCreditsRemaining(array $params = []): array 'label' => "", 'icon' => self::getIconWallet(), 'apply_filters' => [], - 'alt' =>'Proportion of credits remaining', + 'alt' => 'Proportion of credits remaining', ]; $params = array_merge($default_params, $params); $tab = self::getCredits($params); - $result = $tab['quantity']!=0 ? (($tab['quantity'] - $tab['sum']) / $tab['quantity']) * 100 : 0; + $result = $tab['quantity'] != 0 ? (($tab['quantity'] - $tab['sum']) / $tab['quantity']) * 100 : 0; $result = $result < 0 ? 0 : $result; - + return [ - 'number' => round($result,0,PHP_ROUND_HALF_DOWN) . '%', + 'number' => round($result, 0, PHP_ROUND_HALF_DOWN) . '%', 'url' => '', 'label' => 'Proportion of credits remaining', 'icon' => $default_params['icon'], @@ -370,7 +365,7 @@ public static function getCreditsConsumption(array $params = []): array 'label' => "", 'icon' => "", 'apply_filters' => [], - 'alt' =>'Quantity of credit consumed', + 'alt' => 'Quantity of credit consumed', ]; $params = array_merge($default_params, $params); @@ -381,8 +376,9 @@ public static function getCreditsConsumption(array $params = []): array [ 'SELECT' => [ new QueryExpression( - "SUM(IFNULL({$s_table}.consumed, 0)) - as consumed"), + "SUM(IFNULL({$s_table}.consumed, 0)) + as consumed" + ), "$s_table.tickets_id" ], 'FROM' => $t_table, @@ -397,11 +393,11 @@ public static function getCreditsConsumption(array $params = []): array 'WHERE' => [ "$t_table.entities_id" => $active_entity ], - 'GROUP'=> [ + 'GROUP' => [ "$s_table.tickets_id" ] - ], Provider::getFiltersCriteria($t_table, $params['apply_filters']) - + ], + Provider::getFiltersCriteria($t_table, $params['apply_filters']) ); $series = []; @@ -411,11 +407,10 @@ public static function getCreditsConsumption(array $params = []): array foreach ($DB->request($criteria) as $id => $row) { $tab += [$row['tickets_id'] => $row['consumed']]; - } - + } - foreach ($tab as $ticket => $value) { + foreach ($tab as $ticket => $value) { $tickets[$i] = 'Ticket n°' . $ticket; $series['credit']['name'] = 'Crédit'; $series['credit']['data'][$i] = [ @@ -455,7 +450,7 @@ public static function getCreditsEvolution(array $params = []): array 'label' => "", 'icon' => "", 'apply_filters' => [], - 'alt' =>'Evolution of credit consumption', + 'alt' => 'Evolution of credit consumption', ]; $params = array_merge($default_params, $params); @@ -470,7 +465,7 @@ public static function getCreditsEvolution(array $params = []): array ), new QueryExpression( "SUM(IFNULL({$t_table}.consumed, 0)) - as ". $DB->quoteValue(_x('status', 'consumed')) + as " . $DB->quoteValue(_x('status', 'consumed')) ), ], 'FROM' => $t_table, @@ -487,7 +482,7 @@ public static function getCreditsEvolution(array $params = []): array ], 'ORDER' => 'period ASC', 'GROUP' => ['period'], - ],Provider::getFiltersCriteria($e_table, $params['apply_filters'])); + ], Provider::getFiltersCriteria($e_table, $params['apply_filters'])); $monthYears = []; $series = []; @@ -496,15 +491,12 @@ public static function getCreditsEvolution(array $params = []): array $iterator = $DB->request($criteria); foreach ($iterator as $result) { - $monthYears[] = $result['period']; $tmp = $result; unset($tmp['period']); foreach ($tmp as $value) { - - $series['parmois']['name'] = "Consumption per month"; $series['parmois']['data'][] = [ 'value' => (int)$value, @@ -512,14 +504,12 @@ public static function getCreditsEvolution(array $params = []): array ]; $series['total']['name'] = "Total consumption"; - if ($i > 0) - { + if ($i > 0) { $series['total']['data'][] = [ - 'value' => (int)$value + $series['total']['data'][$i-1]['value'], + 'value' => (int)$value + $series['total']['data'][$i - 1]['value'], 'url' => '', ]; - } - else { + } else { $series['total']['data'][] = [ 'value' => (int)$value, 'url' => '', @@ -530,11 +520,11 @@ public static function getCreditsEvolution(array $params = []): array } array_unshift($monthYears, ''); - if (isset($series['total']['data'])){ + if (isset($series['total']['data'])) { array_unshift($series['total']['data'], ['value' => 0, 'url' => '']); array_unshift($series['parmois']['data'], ['value' => 0, 'url' => '']); } - + return [ 'data' => [ 'labels' => $monthYears, @@ -569,7 +559,6 @@ public static function getCredits(array $params = []): array ] ], - Provider::getFiltersCriteria($t_table, $params['apply_filters']) ); @@ -578,7 +567,7 @@ public static function getCredits(array $params = []): array foreach ($DB->request($criteria_quantity) as $id => $row) { $result_quantity += $row['quantity']; - } + } $criteria_sum = array_merge_recursive( [ @@ -601,10 +590,10 @@ public static function getCredits(array $params = []): array Provider::getFiltersCriteria($t_table, $params['apply_filters']) ); - $result_sum=0; + $result_sum = 0; foreach ($DB->request($criteria_sum) as $id => $row) { $result_sum += $row['sum']; - } + } return [ 'quantity' => $result_quantity, @@ -616,4 +605,4 @@ static function getIconWallet(): string { return "fas fa-wallet"; } -} \ No newline at end of file +} diff --git a/inc/dashboardfilters.class.php b/inc/dashboardfilters.class.php index afac034..fbb32a7 100644 --- a/inc/dashboardfilters.class.php +++ b/inc/dashboardfilters.class.php @@ -3,10 +3,8 @@ use Glpi\Dashboard\Filters\AbstractFilter; use PluginCreditEntity; - class PluginCreditDashboardFilters extends AbstractFilter { - const FIELD = "id"; public static function getName(): string @@ -68,6 +66,4 @@ public static function getSearchCriteria(string $table, $value): array return []; } - - -} \ No newline at end of file +} From fdeda41fcf71cd68b94068e2d80dfbca91afba03 Mon Sep 17 00:00:00 2001 From: bessantoy Date: Wed, 18 Sep 2024 09:52:18 +0200 Subject: [PATCH 3/5] fix CI --- inc/dashboardcards.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/dashboardcards.class.php b/inc/dashboardcards.class.php index 78e3a6c..428ed4e 100644 --- a/inc/dashboardcards.class.php +++ b/inc/dashboardcards.class.php @@ -601,7 +601,7 @@ public static function getCredits(array $params = []): array ]; } - static function getIconWallet(): string + private static function getIconWallet(): string { return "fas fa-wallet"; } From 2069afcfdad63c0feb099a7eec2590730304361b Mon Sep 17 00:00:00 2001 From: bessantoy Date: Wed, 18 Sep 2024 09:57:49 +0200 Subject: [PATCH 4/5] add missing PHPDoc for global variable $DB --- inc/dashboardcards.class.php | 5 +++++ inc/dashboardfilters.class.php | 1 + 2 files changed, 6 insertions(+) diff --git a/inc/dashboardcards.class.php b/inc/dashboardcards.class.php index 428ed4e..689ec2a 100644 --- a/inc/dashboardcards.class.php +++ b/inc/dashboardcards.class.php @@ -115,6 +115,7 @@ public static function getCards(): array */ public static function nbCredits(array $params = []): array { + /** @var \DBmysql $DB */ global $DB; $active_entity = Session::getActiveEntity(); @@ -169,6 +170,7 @@ public static function nbCredits(array $params = []): array */ public static function getDateEndingCredit(array $params = []): array { + /** @var \DBmysql $DB */ global $DB; $active_entity = Session::getActiveEntity(); @@ -356,6 +358,7 @@ public static function percentCreditsRemaining(array $params = []): array */ public static function getCreditsConsumption(array $params = []): array { + /** @var \DBmysql $DB */ global $DB; $active_entity = Session::getActiveEntity(); @@ -442,6 +445,7 @@ public static function getCreditsConsumption(array $params = []): array */ public static function getCreditsEvolution(array $params = []): array { + /** @var \DBmysql $DB */ global $DB; $active_entity = Session::getActiveEntity(); @@ -540,6 +544,7 @@ public static function getCreditsEvolution(array $params = []): array public static function getCredits(array $params = []): array { + /** @var \DBmysql $DB */ global $DB; $active_entity = Session::getActiveEntity(); diff --git a/inc/dashboardfilters.class.php b/inc/dashboardfilters.class.php index fbb32a7..2acceba 100644 --- a/inc/dashboardfilters.class.php +++ b/inc/dashboardfilters.class.php @@ -19,6 +19,7 @@ public static function getId(): string public static function canBeApplied(string $table): bool { + /** @var \DBmysql $DB */ global $DB; return $DB->fieldExists($table, self::FIELD); } From a986e468d290d72dc92decef4e04d191f79e3ca5 Mon Sep 17 00:00:00 2001 From: bessantoy Date: Wed, 18 Sep 2024 10:04:38 +0200 Subject: [PATCH 5/5] add missing licence headers --- inc/dashboardcards.class.php | 29 +++++++++++++++++++++++++++++ inc/dashboardfilters.class.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/inc/dashboardcards.class.php b/inc/dashboardcards.class.php index 689ec2a..2ffca2c 100644 --- a/inc/dashboardcards.class.php +++ b/inc/dashboardcards.class.php @@ -1,5 +1,34 @@ . + * ------------------------------------------------------------------------- + * @author François Legastelois + * @copyright Copyright (C) 2017-2023 by Credit plugin team. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://github.com/pluginsGLPI/credit + * ------------------------------------------------------------------------- + */ + use CommonDBTM; use PluginCreditEntity; use PluginCreditTicket; diff --git a/inc/dashboardfilters.class.php b/inc/dashboardfilters.class.php index 2acceba..c33032d 100644 --- a/inc/dashboardfilters.class.php +++ b/inc/dashboardfilters.class.php @@ -1,5 +1,34 @@ . + * ------------------------------------------------------------------------- + * @author François Legastelois + * @copyright Copyright (C) 2017-2023 by Credit plugin team. + * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html + * @link https://github.com/pluginsGLPI/credit + * ------------------------------------------------------------------------- + */ + use Glpi\Dashboard\Filters\AbstractFilter; use PluginCreditEntity;