Skip to content

Commit 858d8b9

Browse files
authored
Merge pull request #597 from ProgressPlanner/filip/v19/improve-was-completed-check
Improve "was task completed" check
2 parents 2d2600a + 51f689a commit 858d8b9

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

classes/class-suggested-tasks.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ public function rest_prepare_recommendation( $response, $post ) {
439439

440440
// This has to be the last item to be added because actions use data from previous items.
441441
$response->data['prpl_task_actions'] = $provider->get_task_actions( $response->data );
442+
443+
/*
444+
Check if task was completed before - for example, comments were disabled and then re-enabled, and remove points if so.
445+
* Those are tasks which are completed by toggling an option, so non repetitive & not user tasks.
446+
*/
447+
if ( ! $provider->is_repetitive() && $provider->task_has_activity( $response->data['meta']['prpl_task_id'] ) ) {
448+
$response->data['meta']['prpl_points'] = 0;
449+
}
442450
}
443451

444452
$category_term = \wp_get_object_terms( $post->ID, 'prpl_recommendations_category' );

classes/suggested-tasks/class-tasks-interface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,13 @@ public function get_popover_id();
120120
* @return array
121121
*/
122122
public function add_task_actions( $data = [], $actions = [] );
123+
124+
/**
125+
* Check if the task has activity.
126+
*
127+
* @param string $task_id The task ID.
128+
*
129+
* @return bool
130+
*/
131+
public function task_has_activity( $task_id = '' );
123132
}

classes/suggested-tasks/providers/class-select-locale.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ function ( $locale ) {
173173
* @return bool
174174
*/
175175
public function is_task_completed( $task_id = '' ) {
176-
$locale_activity = \progress_planner()->get_activities__query()->query_activities(
176+
$activity = \progress_planner()->get_activities__query()->query_activities(
177177
[
178178
'category' => 'suggested_task',
179179
'data_id' => static::PROVIDER_ID,
180180
]
181181
);
182182

183-
return ! empty( $locale_activity );
183+
return ! empty( $activity );
184184
}
185185

186186
/**

classes/suggested-tasks/providers/class-select-timezone.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ protected function get_title() {
8585
* @return bool
8686
*/
8787
public function should_add_task() {
88-
$timezone_activity = \progress_planner()->get_activities__query()->query_activities(
88+
$activity = \progress_planner()->get_activities__query()->query_activities(
8989
[
9090
'category' => 'suggested_task',
9191
'data_id' => static::PROVIDER_ID,
9292
]
9393
);
9494

95-
return ! $timezone_activity;
95+
return ! $activity;
9696
}
9797

9898
/**

classes/suggested-tasks/providers/class-tasks.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,4 +704,26 @@ function ( $a, $b ) {
704704
public function add_task_actions( $data = [], $actions = [] ) {
705705
return $actions;
706706
}
707+
708+
/**
709+
* Check if the task has activity.
710+
*
711+
* @param string $task_id The task ID.
712+
*
713+
* @return bool
714+
*/
715+
public function task_has_activity( $task_id = '' ) {
716+
if ( empty( $task_id ) ) {
717+
$task_id = $this->get_task_id();
718+
}
719+
720+
$activity = \progress_planner()->get_activities__query()->query_activities(
721+
[
722+
'category' => 'suggested_task',
723+
'data_id' => $task_id,
724+
]
725+
);
726+
727+
return ! empty( $activity );
728+
}
707729
}

0 commit comments

Comments
 (0)