Blacklist.class.php 904 Bytes
Newer Older
Zohten's avatar
Zohten committed
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
<?php

class Blacklist extends Model
{

    // ===========
    // = Statics =
    // ===========

    protected static $table_name = 'MJ_BLACKLIST';

    public static function getList()
    {
        $stm = parent::exec('GET_BLACKLIST');
        return $stm->fetchAll();
    }

    public static function isBannedIP($ip)
    {
        $stm = parent::exec('CHECK_BLACKLIST', ['ip' => $ip]);
        $result = $stm->fetch();
        if($result){
            return true;
        }
        return false;
    }

    public static function addIP($ip)
    {
        $begin_date = date('Y-m-d');
        $pimped_array = ['ip'=>$ip,'date'=>$begin_date];
        $stm = parent::exec('ADD_BLACKLIST', $pimped_array);
    }

    public static function removeIP($ip)
    {
        $stm = parent::exec('REMOVE_BLACKLIST', ['ip' => $ip]);
    }

    public function ip()
    {
        return trim($this->IP);
    }

}