Skip to content

Commit 51f689a

Browse files
committed
0 points for tasks which were completed in the past
1 parent eb45c38 commit 51f689a

3 files changed

Lines changed: 39 additions & 0 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-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)