Skip to content

Commit

Permalink
Merge branch 'develop' into filip/check-user-capability
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Dec 20, 2024
2 parents ef54495 + 1f91923 commit f8723c6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
28 changes: 6 additions & 22 deletions classes/class-chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function the_chart( $args = [] ) {
* Get data for the chart.
*
* @param array $args The arguments for the chart.
* ['query_params'] The query parameters.
* See \Progress_Planner\Query::query_activities for the available parameters.
*
* ['items_callback'] The callback to get items.
* ['filter_results'] The callback to filter the results. Leave empty/null to skip filtering.
* ['dates_params'] The dates parameters for the query.
* ['start_date'] The start date for the chart.
Expand All @@ -50,7 +48,9 @@ public function get_chart_data( $args = [] ) {
$args = \wp_parse_args(
$args,
[
'query_params' => [],
'items_callback' => function ( $start_date, $end_date ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
return 0;
},
'filter_results' => null,
'dates_params' => [],
'normalized' => false,
Expand Down Expand Up @@ -83,15 +83,7 @@ public function get_chart_data( $args = [] ) {
if ( $args['normalized'] ) {
$previous_month_start = ( clone $periods[0]['start_date'] )->modify( '-1 month' );
$previous_month_end = ( clone $periods[0]['start_date'] )->modify( '-1 day' );
$previous_period_activities = \progress_planner()->get_query()->query_activities(
array_merge(
$args['query_params'],
[
'start_date' => $previous_month_start,
'end_date' => $previous_month_end,
]
)
);
$previous_period_activities = $args['items_callback']( $previous_month_start, $previous_month_end );
if ( $args['filter_results'] ) {
$activities = $args['filter_results']( $activities );
}
Expand Down Expand Up @@ -124,15 +116,7 @@ public function get_chart_data( $args = [] ) {
*/
public function get_period_data( $period, $args, $previous_period_activities ) {
// Get the activities for the period.
$activities = \progress_planner()->get_query()->query_activities(
array_merge(
$args['query_params'],
[
'start_date' => $period['start_date'],
'end_date' => $period['end_date'],
]
)
);
$activities = $args['items_callback']( $period['start_date'], $period['end_date'] );
// Filter the results if a callback is provided.
if ( $args['filter_results'] ) {
$activities = $args['filter_results']( $activities );
Expand Down
9 changes: 8 additions & 1 deletion classes/class-rest-api-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ public function get_stats( \WP_REST_Request $request ) {

$scores = \progress_planner()->get_chart()->get_chart_data(
[
'query_params' => [],
'items_callback' => function ( $start_date, $end_date ) {
return \progress_planner()->get_query()->query_activities(
[
'start_date' => $start_date,
'end_date' => $end_date,
]
);
},
'dates_params' => [
'start_date' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( '-6 months' ),
'end_date' => new \DateTime(),
Expand Down
14 changes: 10 additions & 4 deletions classes/widgets/class-published-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ public function get_chart_args_content_count() {
public function get_chart_args() {
return [
'type' => 'line',
'query_params' => [
'category' => 'content',
'type' => 'publish',
],
'items_callback' => function ( $start_date, $end_date ) {
return \progress_planner()->get_query()->query_activities(
[
'category' => 'content',
'type' => 'publish',
'start_date' => $start_date,
'end_date' => $end_date,
]
);
},
'dates_params' => [
'start_date' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $this->get_range() ),
'end_date' => new \DateTime(),
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ parameters:
- '#Call to an undefined method Progress_Planner\\Base\:\:get_[a-zA-Z0-9\\_]+().#'
- '#Cannot call method modify\(\) on DateTime\|false.#'
- '#Cannot call method format\(\) on DateTime\|false.#'
- '#Parameter \#1 \$[a-zA-Z0-9\\_]+ of function esc_attr expects string, mixed given.#'
- '#Parameter \#1 \$[a-zA-Z0-9\\_]+ of function sanitize_text_field expects string, mixed given.#'
9 changes: 8 additions & 1 deletion views/page-widgets/activity-scores.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ class="prpl-info-icon"
\progress_planner()->get_chart()->the_chart(
[
'type' => 'bar',
'query_params' => [],
'items_callback' => function ( $start_date, $end_date ) {
return \progress_planner()->get_query()->query_activities(
[
'start_date' => $start_date,
'end_date' => $end_date,
]
);
},
'dates_params' => [
'start_date' => \DateTime::createFromFormat( 'Y-m-d', \gmdate( 'Y-m-01' ) )->modify( $prpl_widget->get_range() ),
'end_date' => new \DateTime(),
Expand Down

0 comments on commit f8723c6

Please sign in to comment.