<?php
/**
 * app/controllers/admin/admin.php
 *
 * This is the admin log controller.
 *
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Controllers\Admin;

use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Models\Log;

class Admin extends AdminController {
    public static $log;

    public function __construct() {
        parent::__construct();
        self::$title = 'Admin - Admin Logs';
        self::$log = new Log;
    }

    public function delete( $id = null ) {
        if ( Input::exists( 'submit' ) ) {
            $id = Input::post( 'A_' );
        }
        if ( self::$log->delete( $id ) ) {
            Issues::add( 'success', 'Admin-log deleted' );
        } else {
            Issues::add( 'error', 'There was an error deleting log(s)' );
        }
        $this->index();
    }

    public function index() {
        return Views::view( 'admin.logs.admin_list', self::$log->list( 'admin' ) );
    }

    public function view( $id = null ) {
        return Views::view( 'admin.logs.admin', self::$log->findById( $id ) );
    }
}
