# logtivity/1.10.0/Admin/Logtivity_Log_Index_Controller.php

Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity, version 1.10.0. 60 lines.

- Page: https://pluginprobe.com/plugins/logtivity/1.10.0/code/Admin/Logtivity_Log_Index_Controller.php
- Raw: https://pluginprobe.com/plugins/logtivity/1.10.0/raw/Admin/Logtivity_Log_Index_Controller.php
- Modified: 2022-02-14T14:00:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/logtivity/1.10.0/code/Admin/Logtivity_Log_Index_Controller.php#L10-L20`.

```php
<?php

class Logtivity_Log_Index_Controller
{
	public function __construct()
	{
		add_action("wp_ajax_nopriv_logtivity_log_index_filter", [$this, 'search']);
		add_action("wp_ajax_logtivity_log_index_filter", [$this, 'search']);
	}

	public function search()
	{
		if ( !current_user_can( 'manage_options' ) )  {
			wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
		}

		$response = json_decode(
			(new Logtivity_Api)->get('/logs', [
				'page' => $this->getInput('page'),
				'action' => $this->getInput('search_action'),
				'context' => $this->getInput('search_context'),
				'action_user' => $this->getInput('action_user'),
			])
		);

		if ($response->message) {
			return $this->errorReponse($response->message);
		}

		return $this->successResponse($response);
	}

	private function successResponse($response)
	{
		return wp_send_json([
			'view' => logtivity_view('_logs-loop', [
				'logs' => $response->data,
				'meta' => $response->meta,
				'hasNextPage' => $response->links->next,
			])
		]);
	}

	private function errorReponse($message)
	{
		return wp_send_json([
			'view' => logtivity_view('_logs-loop', [
				'message' => $message,
				'logs' => [],
			])
		]);
	}

	private function getInput($field)
	{
		return ( isset($_GET[$field]) && is_string($_GET[$field]) ? $_GET[$field] : null);
	}
}

new Logtivity_Log_Index_Controller;
```
