public static function report_assignee_by_month($assignee_type, $assignee_id, $args)
 {
     $defaults = array('start_date' => date('Y-m-d', strtotime('-1 year')), 'check_permissions' => true, 'base_url' => admin_url('admin.php?page=gravityflow-reports'));
     $args = array_merge($defaults, $args);
     $rows = Gravity_Flow_Activity::get_report_data_for_assignee_by_month($assignee_type, $assignee_id, $args['start_date']);
     if (empty($rows)) {
         esc_html_e('No data to display', 'gravityflow');
         return;
     }
     $chart_data = array();
     $chart_data[] = array(esc_html__('Month', 'gravityflow'), esc_html__('Workflows Completed', 'gravityflow'), esc_html__('Average Duration (hours)', 'gravityflow'));
     global $wp_locale;
     foreach ($rows as $row) {
         $chart_data[] = array($wp_locale->get_month($row->month) . ' ' . $row->year, absint($row->c), absint($row->av) / HOUR_IN_SECONDS);
     }
     if ($assignee_type == 'user_id') {
         $user = get_user_by('id', $assignee_id);
         $display_name = $user->display_name;
     } else {
         $display_name = $assignee_id;
     }
     $chart_options = array('chart' => array('title' => esc_html($display_name), 'subtitle' => esc_html__('Workflows completed and average duration by month', 'gravityflow')), 'bars' => 'horizontal', 'height' => 200 + count($rows) * 100, 'series' => array(array('axis' => 'count'), array('axis' => 'average_duration')), 'axes' => array('x' => array('count' => array('side' => 'top', 'label' => esc_html__('Workflows Completed', 'gravityflow')), 'average_duration' => array('label' => esc_html__('Average Duration (hours)', 'gravityflow')))));
     $data_table_json = htmlentities(json_encode($chart_data), ENT_QUOTES, 'UTF-8', true);
     $options_json = htmlentities(json_encode($chart_options), ENT_QUOTES, 'UTF-8', true);
     echo '<div id="gravityflow_chart_top_level" style="padding:20px;background-color:white;" class="gravityflow_chart" data-type="Bar" data-table="' . $data_table_json . '" data-options="' . $options_json . '""></div>';
 }
    public static function display($args)
    {
        $defaults = array('check_permissions' => true, 'detail_base_url' => admin_url('admin.php?page=gravityflow-inbox&view=entry'));
        $args = array_merge($defaults, $args);
        if ($args['check_permissions'] && !GFAPI::current_user_can_any('gravityflow_activity')) {
            esc_html_e("You don't have permission to view this page", 'gravityflow');
            return;
        }
        $events = Gravity_Flow_Activity::get_events();
        if (sizeof($events) > 0) {
            ?>

			<table id="gravityflow-activity" class="widefat" cellspacing="0" style="border:0px;">
				<thead>
				<tr>
					<th data-label="<?php 
            esc_html_e('Event ID', 'gravityflow');
            ?>
"><?php 
            esc_html_e('Event ID', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Date', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Form', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Entry ID', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Type', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Event', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Step', 'gravityflow');
            ?>
</th>
					<th><?php 
            esc_html_e('Duration', 'gravityflow');
            ?>
</th>
				</tr>
				</thead>

				<tbody class="list:user user-list">
				<?php 
            foreach ($events as $event) {
                $form = GFAPI::get_form($event->form_id);
                $base_url = $args['detail_base_url'];
                $url_entry = $base_url . sprintf('&id=%d&lid=%d', $event->form_id, $event->lead_id);
                $url_entry = esc_url_raw($url_entry);
                $link = "<a href='%s'>%s</a>";
                ?>
					<tr>
						<td data-label="<?php 
                esc_html_e('ID', 'gravityflow');
                ?>
">
							<?php 
                echo esc_html($event->id);
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Date', 'gravityflow');
                ?>
">
							<?php 
                echo esc_html(GFCommon::format_date($event->date_created));
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Form', 'gravityflow');
                ?>
">
							<?php 
                printf($link, $url_entry, $form['title']);
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Entry ID', 'gravityflow');
                ?>
">
							<?php 
                printf($link, $url_entry, $event->lead_id);
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Type', 'gravityflow');
                ?>
">
							<?php 
                echo esc_html($event->log_object);
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Event', 'gravityflow');
                ?>
">
							<?php 
                switch ($event->log_object) {
                    case 'workflow':
                        echo $event->log_event;
                        break;
                    case 'step':
                        echo esc_html($event->log_event);
                        break;
                    case 'assignee':
                        echo esc_html($event->display_name) . ' <i class="fa fa-arrow-right"></i> ' . esc_html($event->log_value);
                        break;
                    default:
                        echo esc_html($event->log_value);
                }
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Step', 'gravityflow');
                ?>
">
							<?php 
                if ($event->feed_id) {
                    $step = gravity_flow()->get_step($event->feed_id);
                    if ($step) {
                        $step_name = $step->get_name();
                        echo esc_html($step_name);
                    }
                }
                ?>
						</td>
						<td data-label="<?php 
                esc_html_e('Event', 'gravityflow');
                ?>
">
							<?php 
                if (!empty($event->duration)) {
                    echo self::format_duration($event->duration);
                }
                ?>
						</td>

					</tr>
				<?php 
            }
            ?>
				</tbody>
			</table>

		<?php 
        } else {
            ?>
				<div id="gravityflow-no-activity-container">

					<div id="gravityflow-no-activity-content">
						<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>
						<br /><br />
						<?php 
            esc_html_e('Waiting for workflow activity', 'gravityflow');
            ?>
					</div>

				</div>
			<?php 
        }
    }
 private function uninstall_db()
 {
     global $wpdb;
     $table = Gravity_Flow_Activity::get_activity_log_table_name();
     $wpdb->query("DROP TABLE IF EXISTS {$table}");
 }