/var/www/html_uk/wp-content/plugins/automatewoo/includes/Rest_Api/Schema/WorkflowSchema.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php

namespace AutomateWoo\Rest_Api\Schema;

use 
AutomateWoo\Workflows;

/**
 * Schema for a Workflow object in the REST API.
 *
 * @since   4.9.0
 *
 * @package AutomateWoo\Rest_Api\Schema
 */
trait WorkflowSchema {

    
/**
     * Retrieves the item's schema, conforming to JSON Schema.
     *
     * @return array Item schema data.
     */
    
public function get_item_schema() {
        
$schema = [
            
'$schema'    => 'https://json-schema.org/draft-04/schema#',
            
'title'      => 'workflow',
            
'type'       => 'object',
            
'properties' => $this->get_properties_schema(),
        ];

        return 
$this->add_additional_fields_schema$schema );
    }

    
/**
     * Retrieves the schema for the item properties.
     *
     * @return array Item properties schema data.
     */
    
protected function get_properties_schema() {
        return [
            
'id'                             => [
                
'description' => __'Unique identifier for the object.''automatewoo' ),
                
'type'        => 'integer',
                
'context'     => Context::VIEW_ONLY,
                
'readonly'    => true,
            ],
            
'title'                          => [
                
'description' => __'Workflow name''automatewoo' ),
                
'type'        => 'string',
                
'context'     => Context::ALL,
                
'required'    => true,
            ],
            
'status'                         => [
                
'description' => __'Whether the Workflow is active or disabled.''automatewoo' ),
                
'type'        => 'string',
                
'enum'        => [ 'disabled''active' ],
                
'context'     => Context::ALL,
            ],
            
'type'                           => [
                
'description' => __'The workflow type.''automatewoo' ),
                
'type'        => 'string',
                
'enum'        => array_keysWorkflows::get_types() ),
                
'context'     => Context::ALL,
            ],
            
'trigger'                        => [
                
'description' => __'The type of event that triggers the workflow to run.''automatewoo' ),
                
'type'        => 'object',
                
'context'     => Context::ALL,
                
'required'    => true,
                
'properties'  => [
                    
'name'    => [
                        
'description' => __'The name of the trigger for the workflow.''automatewoo' ),
                        
'type'        => 'string',
                        
'required'    => true,
                    ],
                    
'options' => [
                        
'description' => __'The options for the workflow trigger.''automatewoo' ),
                        
'type'        => 'object',
                    ],
                ],
            ],
            
'rules'                          => [
                
'description' => __'Collection of rules to add conditional logic to workflow.''automatewoo' ),
                
'type'        => 'array',
                
'context'     => Context::ALL,
                
'items'       => [
                    
'description' => __'Collection of rule groups.''automatewoo' ),
                    
'type'        => 'array',
                    
'items'       => [
                        
'type'       => 'object',
                        
'properties' => [
                            
'name'    => [
                                
'description' => __'Rule name.''automatewoo' ),
                                
'type'        => 'string',
                                
'required'    => true,
                            ],
                            
'compare' => [
                                
'description' => __'Rule comparison operator.''automatewoo' ),
                                
'type'        => 'string',
                            ],
                            
'value'   => [
                                
'description' => __'Rule value to compare.''automatewoo' ),
                                
'type'        => [ 'string''array''object' ],
                            ],
                        ],
                    ],
                ],
            ],
            
'actions'                        => [
                
'description' => __'Collection of actions to run for workflow.''automatewoo' ),
                
'type'        => 'array',
                
'context'     => Context::ALL,
                
'items'       => [
                    
'type'       => 'object',
                    
'properties' => [
                        
'action_name' => [
                            
'description' => __'Name of the action.''automatewoo' ),
                            
'type'        => 'string',
                            
'required'    => true,
                        ],
                    ],
                ],
            ],
            
'timing'                         => [
                
'description' => __'When the workflow will run in relation to the trigger.''automatewoo' ),
                
'type'        => 'object',
                
'context'     => Context::ALL,
                
'properties'  => [
                    
'type'      => [
                        
'description' => __'Timing type for when the workflow will run in relation to the trigger.''automatewoo' ),
                        
'type'        => 'string',
                        
'enum'        => [ 'immediately''delayed''scheduled''fixed''datetime' ],
                        
'required'    => true,
                    ],
                    
'delay'     => [
                        
'description' => __'Amount of time to delay before running the workflow.''automatewoo' ),
                        
'type'        => 'object',
                        
'properties'  => [
                            
'unit'  => [
                                
'description' => __'Unit of time to delay (hour, minute, day, week, month).''automatewoo' ),
                                
'type'        => 'string',
                                
'enum'        => [ 'h''m''d''w''month' ],
                            ],
                            
'value' => [
                                
'description' => __'Number of time to wait.''automatewoo' ),
                                
'type'        => 'number',
                            ],
                        ],
                    ],
                    
'scheduled' => [
                        
'description' => __'Scheduled time of day / days to run the workflow.''automatewoo' ),
                        
'type'        => 'object',
                        
'properties'  => [
                            
'time_of_day' => [
                                
'description' => __'Time of day to run the workflow (HH:mm).''automatewoo' ),
                                
'type'        => 'string',
                            ],
                            
'days'        => [
                                
'description' => __'Days of the week to run the workflow (empty is any day).''automatewoo' ),
                                
'type'        => 'array',
                                
'items'       => [
                                    
'type' => 'string',
                                    
'enum' => [ 'monday''tuesday''wednesday''thursday''friday''saturday''sunday' ],
                                ],
                            ],
                        ],
                    ],
                    
'datetime'  => [
                        
'description' => __'Fixed time to run the workflow.''automatewoo' ),
                        
'type'        => 'string',
                        
'format'      => 'date-time',
                    ],
                    
'variable'  => [
                        
'description' => __'Variable to use as scheduled time to run the workflow.''automatewoo' ),
                        
'type'        => 'string',
                    ],
                ],
            ],
            
'is_transactional'               => [
                
'description' => __'Whether the workflow is used for transactional emails instead of marketing emails.''automatewoo' ),
                
'type'        => 'boolean',
                
'context'     => Context::ALL,
            ],
            
'is_tracking_enabled'            => [
                
'description' => __'Whether tracking is enabled for the workflow.''automatewoo' ),
                
'type'        => 'boolean',
                
'context'     => Context::ALL,
            ],
            
'is_conversion_tracking_enabled' => [
                
'description' => __'Whether conversion tracking is enabled for the workflow.''automatewoo' ),
                
'type'        => 'boolean',
                
'context'     => Context::ALL,
            ],
            
'google_analytics_link_tracking' => [
                
'description' => __'Tracking variables to be appended to every link in the email or SMS.''automatewoo' ),
                
'type'        => 'string',
                
'context'     => Context::ALL,
            ],
            
'workflow_order'                 => [
                
'description' => __'The order in which the workflows will run.''automatewoo' ),
                
'type'        => 'integer',
                
'context'     => Context::ALL,
            ],
        ];
    }

    
/**
     * Retrieves the schema for update parameters.
     *
     * @return array Update parameters schema data.
     */
    
protected function get_update_parameters_schema() {
        return 
array_map(
            function ( 
$parameter ) {
                unset( 
$parameter['required'] );
                return 
$parameter;
            },
            
$this->get_properties_schema()
        );
    }

    
/**
     * Retrieves the schema for delete parameters.
     *
     * @return array Delete parameters schema data.
     */
    
protected function get_delete_parameters_schema() {
        return [
            
'force' => [
                
'description' => __'Use true to permanently delete the workflow, default is false.''automatewoo' ),
                
'type'        => 'boolean',
            ],
        ];
    }

    
/**
     * Adds the schema from additional fields to a schema array.
     *
     * The type of object is inferred from the passed schema.
     *
     * @param array $schema Schema array.
     *
     * @return array Modified Schema array.
     */
    
abstract protected function add_additional_fields_schema$schema );
}