PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | app/Assist/Controllers/TasksController.php +23 -21 0.11.13.2.1 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * Controls Tasks
4 5 */
5 6
@@ -4,35 +5,19 @@
4 5 */
5 6
6 7 namespace Extendify\Assist\Controllers;
7 8
8 -use Extendify\Http;
9 +defined('ABSPATH') || die('No direct access.');
9 10
10 -if (!defined('ABSPATH')) {
11 - die('No direct access.');
12 -}
11 +use Extendify\Shared\Services\Sanitizer;
13 12
14 13 /**
15 14 * The controller for plugin dependency checking, etc
16 15 */
16 +
17 17 class TasksController
18 18 {
19 -
20 19 /**
21 - * Return tasks from either database or source.
22 - *
23 - * @return \WP_REST_Response
24 - */
25 - public static function fetchTasks()
26 - {
27 - $response = Http::get('/tasks');
28 - return new \WP_REST_Response(
29 - $response,
30 - wp_remote_retrieve_response_code($response)
31 - );
32 - }
33 -
34 - /**
35 20 * Return the data
36 21 *
37 22 * @return \WP_REST_Response
38 23 */
@@ -49,9 +34,26 @@
49 34 * @return \WP_REST_Response
50 35 */
51 36 public static function store($request)
52 37 {
53 - $data = json_decode($request->get_param('data'), true);
54 - update_option('extendify_assist_tasks', $data);
38 + $data = json_decode($request->get_param('state'), true);
39 + update_option('extendify_assist_tasks', Sanitizer::sanitizeArray($data));
55 40 return new \WP_REST_Response($data);
41 + }
42 +
43 + /**
44 + * Returns remaining incomplete tasks.
45 + *
46 + * @return int
47 + */
48 + public function getRemainingCount()
49 + {
50 + $tasks = get_option('extendify_assist_tasks', []);
51 + if (!isset($tasks['state']['seenTasks'])) {
52 + return 0;
53 + }
54 +
55 + $seenTasks = count($tasks['state']['seenTasks']);
56 + $completedTasks = count($tasks['state']['completedTasks']);
57 + return max(($seenTasks - $completedTasks), 0);
56 58 }
57 59 }