From 94cdb0f2356ee26d01bc879eb1facd2f8a05a665 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Wed, 12 Mar 2025 15:04:53 +0100 Subject: [PATCH 1/2] completed suggested tasks list --- assets/css/page-widgets/suggested-tasks.css | 8 +++ classes/badges/class-monthly.php | 60 ++++++++++++++++----- views/page-widgets/suggested-tasks.php | 20 +++++++ 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/assets/css/page-widgets/suggested-tasks.css b/assets/css/page-widgets/suggested-tasks.css index 3f3a84d7b..ac2e36103 100644 --- a/assets/css/page-widgets/suggested-tasks.css +++ b/assets/css/page-widgets/suggested-tasks.css @@ -103,6 +103,14 @@ font-weight: 600; } } + + .prpl-montly-completed-tasks-list { + + li { + display: flex; + justify-content: space-between; + } + } } .prpl-dashboard-widget-suggested-tasks { diff --git a/classes/badges/class-monthly.php b/classes/badges/class-monthly.php index 35892af53..13cfbc030 100644 --- a/classes/badges/class-monthly.php +++ b/classes/badges/class-monthly.php @@ -200,6 +200,34 @@ public function progress_callback() { return $saved_progress; } + $activities = $this->get_monthly_activities(); + + $points = 0; + foreach ( $activities as $activity ) { + $points += $activity->get_points( $activity->date ); + } + + $return_progress = ( $points > self::TARGET_POINTS ) + ? [ + 'progress' => 100, + 'remaining' => 0, + ] : [ + 'progress' => (int) max( 0, min( 100, floor( 100 * $points / self::TARGET_POINTS ) ) ), + 'remaining' => self::TARGET_POINTS - $points, + ]; + + $this->save_progress( $return_progress ); + + return $return_progress; + } + + /** + * Get the monthly activities. + * + * @return array + */ + protected function get_monthly_activities() { + $month = self::get_months()[ 'm' . $this->get_month() ]; $year = $this->get_year(); $month_num = (int) $this->get_month(); @@ -216,22 +244,26 @@ public function progress_callback() { ], ); - $points = 0; - foreach ( $activities as $activity ) { - $points += $activity->get_points( $activity->date ); - } + return $activities; + } - $return_progress = ( $points > self::TARGET_POINTS ) - ? [ - 'progress' => 100, - 'remaining' => 0, - ] : [ - 'progress' => (int) max( 0, min( 100, floor( 100 * $points / self::TARGET_POINTS ) ) ), - 'remaining' => self::TARGET_POINTS - $points, - ]; + /** + * Get the tasks for the badge. + * + * @return array + */ + public function get_monthly_tasks() { + $activities = $this->get_monthly_activities(); - $this->save_progress( $return_progress ); + $tasks = []; + foreach ( $activities as $activity ) { + $task = \progress_planner()->get_suggested_tasks()->get_task_by_task_id( $activity->data_id ); - return $return_progress; + if ( $task && isset( $task['provider_id'] ) ) { + $tasks[] = \progress_planner()->get_suggested_tasks()->get_local()->get_task_details( $task['task_id'] ); + } + } + + return $tasks; } } diff --git a/views/page-widgets/suggested-tasks.php b/views/page-widgets/suggested-tasks.php index ef7ac0f76..05b727ab1 100644 --- a/views/page-widgets/suggested-tasks.php +++ b/views/page-widgets/suggested-tasks.php @@ -76,6 +76,26 @@ class="prpl-info-icon" + get_monthly_tasks(); ?> + + +
+
+

+ +

+ + +
+ +
From 51abdee86eeac148172edfe9c0891e41043a8125 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Tue, 1 Apr 2025 08:46:17 +0200 Subject: [PATCH 2/2] update function call --- classes/badges/class-monthly.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/badges/class-monthly.php b/classes/badges/class-monthly.php index f8eb50b83..29dd0a8de 100644 --- a/classes/badges/class-monthly.php +++ b/classes/badges/class-monthly.php @@ -257,10 +257,10 @@ public function get_monthly_tasks() { $tasks = []; foreach ( $activities as $activity ) { - $task = \progress_planner()->get_suggested_tasks()->get_task_by_task_id( $activity->data_id ); + $task = \progress_planner()->get_suggested_tasks()->get_tasks_by( 'task_id', $activity->data_id ); - if ( $task && isset( $task['provider_id'] ) ) { - $tasks[] = \progress_planner()->get_suggested_tasks()->get_local()->get_task_details( $task['task_id'] ); + if ( isset( $task[0] ) && isset( $task[0]['provider_id'] ) ) { + $tasks[] = \progress_planner()->get_suggested_tasks()->get_local()->get_task_details( $task[0]['task_id'] ); } }