<?php
/**
 * app/controllers/admin/logins.php
 *
 * This is the login logs 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 Logins extends AdminController {
    public static $log;

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

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

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

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

    public function clear() {
        self::$log->clear( 'login' );
        Issues::add( 'success', 'Login Logs Cleared' );
        $this->index();
    }
}
