/var/www/html_uk/wp-content/plugins/automatewoo/admin/reports/logs.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
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

if ( ! 
defined'ABSPATH' ) ) exit;

/**
 * @class Report_Logs
 */
class Report_Logs extends Admin_List_Table {

    public 
$name 'logs';


    function 
__construct() {
        
parent::__construct([
            
'singular' => __'Log''automatewoo' ),
            
'plural' => __'Logs''automatewoo' ),
            
'ajax' => false
        
]);
    }


    function 
filters() {
        
$this->output_workflow_filter();
        
$this->output_customer_filter();
    }


    function 
no_items() {
        
_e'No logs found.''automatewoo' );
    }


    
/**
     * @param $log Log
     * @return string
     */
    
function column_cb$log ) {
        return 
'<input type="checkbox" name="log_ids[]" value="' absint$log->get_id() ) . '" />';
    }


    
/**
     * @param Log $log
     * @param mixed $column_name
     * @return string
     */
    
function column_default$log$column_name ) {

        switch( 
$column_name ) {
            case 
'id':
                echo 
'#' $log->get_id();
                if ( 
$log->has_errors() ) {
                    echo 
Admin::badge'warning''warning'__'Errors occurred when running this workflow. See log notes for more info.''automatewoo' ) );
                }
                if ( 
$log->has_blocked_emails() ) {
                    echo 
Admin::badge'blocked-email''email'__'An email was blocked from sending. See log notes for more info.''automatewoo' ) );
                }
                break;

            case 
'workflow':
                return 
$this->format_workflow_title$log->get_workflow() );
                break;

            case 
'user':

                
$data_layer $log->get_data_layer'object' );

                if ( 
$data_layer->get_customer() ) {
                    return 
Format::customer$data_layer->get_customer() );
                }
                elseif ( 
$data_layer->get_guest() ) {
                    return 
$this->format_guest$data_layer->get_guest()->get_email() );
                }
                elseif ( 
$data_layer->get_user() ) {
                    return 
$this->format_user$data_layer->get_user() );
                }
                else {
                    return 
$this->format_blank();
                }
                break;

            case 
'time':
                return 
$this->format_date$log->get_date() );
                break;

            case 
'actions':

                
$url add_query_arg([
                    
'action' => 'aw_modal_log_info',
                    
'log_id' => $log->get_id()
                    ], 
admin_url('admin-ajax.php') );

                echo 
'<a class="button view aw-button-icon js-open-automatewoo-modal" href="' $url '">View</a>';

                break;
        }
    }

    
/**
     * get_columns function.
     */
    
function get_columns() {
        
$columns = [
            
'cb' => '<input type="checkbox" />',
            
'id'  => __'Log''automatewoo' ),
            
'workflow'  => __'Workflow''automatewoo' ),
            
'user' => __'Customer''automatewoo' ),
            
'time' => __'Time''automatewoo' ),
            
'actions' => '',
        ];

        return 
$columns;
    }


    function 
prepare_items() {

        
$this->_column_headers = [ $this->get_columns(), [], $this->get_sortable_columns() ];
        
$current_page absint$this->get_pagenum() );
        
$per_page $this->get_items_per_page'automatewoo_logs_per_page' );

        
$this->get_items$current_page$per_page );

        
$this->set_pagination_args([
            
'total_items' => $this->max_items,
            
'per_page'    => $per_page,
            
'total_pages' => ceil$this->max_items $per_page )
        ]);
    }


    
/**
     * @param $current_page
     * @param $per_page
     */
    
function get_items$current_page$per_page ) {

        
$query = new Log_Query();
        
$query->set_calc_found_rowstrue );
        
$query->set_limit$per_page );
        
$query->set_page$current_page );
        
$query->set_ordering('date''DESC');

        if ( ! empty(
$_GET['_workflow']) ) {
            
$query->where_workflowabsint$_GET['_workflow'] ) );
        }

        if ( 
$customer_id absintaw_request('filter_customer' ) ) ) {
            if ( 
$customer Customer_Factory::get$customer_id ) ) {
                
$query->where_customer_or_legacy_user$customer );
            }
        }

        
$this->items $query->get_results();
        
$this->max_items $query->found_rows;

    }


    
/**
     * Retrieve the bulk actions
     */
    
function get_bulk_actions() {
        
$actions = [
            
'bulk_delete' => __'Delete''automatewoo' ),
        ];

        return 
$actions;
    }


}