/var/www/html/wp-content/plugins/woocommerce/src/Admin/Features/OnboardingTasks/TaskListSection.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
 * Handles storage and retrieval of a task list section
 */

namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks;

/**
 * Task List section class.
 *
 * @deprecated 7.2.0
 */
class TaskListSection {

    
/**
     * Title.
     *
     * @var string
     */
    
public $id '';

    
/**
     * Title.
     *
     * @var string
     */
    
public $title '';

    
/**
     * Description.
     *
     * @var string
     */
    
public $description '';

    
/**
     * Image.
     *
     * @var string
     */
    
public $image '';

    
/**
     * Tasks.
     *
     * @var array
     */
    
public $task_names = array();

    
/**
     * Parent task list.
     *
     * @var TaskList
     */
    
protected $task_list;

    
/**
     * Constructor
     *
     * @param array         $data Task list data.
     * @param TaskList|null $task_list Parent task list.
     */
    
public function __construct$data = array(), $task_list null ) {
        
$defaults = array(
            
'id'          => '',
            
'title'       => '',
            
'description' => '',
            
'image'       => '',
            
'tasks'       => array(),
        );

        
$data wp_parse_args$data$defaults );

        
$this->task_list   $task_list;
        
$this->id          $data['id'];
        
$this->title       $data['title'];
        
$this->description $data['description'];
        
$this->image       $data['image'];
        
$this->task_names  $data['task_names'];
    }

    
/**
     * Returns if section is complete.
     *
     * @return boolean;
     */
    
private function is_complete() {
        
$complete true;
        foreach ( 
$this->task_names as $task_name ) {
            if ( 
null !== $this->task_list && isset( $this->task_list->task_class_id_map$task_name ] ) ) {
                
$task $this->task_list->get_task$this->task_list->task_class_id_map$task_name ] );
                if ( 
$task->can_view() && ! $task->is_complete() ) {
                    
$complete false;
                    break;
                }
            }
        }
        return 
$complete;
    }

    
/**
     * Get the list for use in JSON.
     *
     * @return array
     */
    
public function get_json() {
        return array(
            
'id'          => $this->id,
            
'title'       => $this->title,
            
'description' => $this->description,
            
'image'       => $this->image,
            
'tasks'       => array_map(
                function( 
$task_name ) {
                    if ( 
null !== $this->task_list && isset( $this->task_list->task_class_id_map$task_name ] ) ) {
                        return 
$this->task_list->task_class_id_map$task_name ];
                    }
                    return 
'';
                },
                
$this->task_names
            
),
            
'isComplete'  => $this->is_complete(),
        );
    }
}