Infractions::bam_getAllInfractions PHP Method

bam_getAllInfractions() public method

Params: $uuid (string), UUID of a user. If null, will list all infractions
public bam_getAllInfractions ( $uuid = null )
    public function bam_getAllInfractions($uuid = null)
    {
        if ($uuid !== null) {
            $field = "UUID";
            $symbol = "=";
            $equals = $uuid;
        } else {
            $field = "UUID";
            $symbol = "<>";
            $equals = "0";
        }
        $bans = $this->_db->get('history', array($field, $symbol, $equals))->results();
        $mutes = $this->_db->get('mutes', array($field, $symbol, $equals))->results();
        $results = array();
        $i = 0;
        foreach ($bans as $ban) {
            $results[$i]["id"] = htmlspecialchars($ban->name) . ';' . strtotime($ban->time);
            $results[$i]["uuid"] = str_replace('-', '', $ban->UUID);
            $results[$i]["staff"] = htmlspecialchars($ban->banner);
            $results[$i]["issued"] = strtotime($ban->time);
            $results[$i]["issued_human"] = date("jS M Y, H:i", strtotime($ban->time));
            if ($ban->cause !== null) {
                $results[$i]["reason"] = htmlspecialchars($ban->cause);
            } else {
                $results[$i]["reason"] = "-";
            }
            if ($ban->dauer !== 'Permanent') {
                $results[$i]["type"] = "temp_ban";
                $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['temp_ban'] . '</span>';
                // Todo: determine expire time
                $results[$i]["expires"] = '';
                $results[$i]["expires_human"] = '';
            } else {
                $results[$i]["type"] = "ban";
                $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['ban'] . '</span>';
                $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
                // Todo: determine if revoked or not
            }
            $i++;
        }
        foreach ($mutes as $mute) {
            $results[$i]["id"] = htmlspecialchars($mute->name) . ';' . strtotime($mute->time);
            $results[$i]["uuid"] = str_replace('-', '', $mute->UUID);
            $results[$i]["staff"] = htmlspecialchars($mute->banner);
            if ($mute->cause !== null) {
                $results[$i]["reason"] = htmlspecialchars($mute->cause);
            } else {
                $results[$i]["reason"] = "-";
            }
            $results[$i]["type"] = "mute";
            $results[$i]["type_human"] = '<span class="label label-warning">' . $this->_language['mute'] . '</span>';
            if ($mute->time !== null) {
                $results[$i]["expires"] = strtotime($mute->time);
                $results[$i]["expires_human"] = '<span class="label label-danger" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($mute->time)), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
            } else {
                $results[$i]['expires'] = 0;
                $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
            }
            $i++;
        }
        // Sort by date
        function date_compare($a, $b)
        {
            if (isset($a['issued'])) {
                $t1 = $a['issued'];
            } else {
                $t1 = $a['expires'];
            }
            if (isset($b['issued'])) {
                $t2 = $b['issued'];
            } else {
                $t2 = $b['expires'];
            }
            return $t2 - $t1;
        }
        usort($results, 'date_compare');
        return $results;
    }

Usage Example

Example #1
0
</h2>
		<?php 
if (!isset($_GET['type']) && !isset($_GET['id'])) {
    // Get all infractions, depending on plugin
    switch ($inf_plugin) {
        case 'bat':
            $all_infractions = $infractions->bat_getAllInfractions();
            break;
        case 'bm':
            $all_infractions = $infractions->bm_getAllInfractions();
            break;
        case 'lb':
            $all_infractions = $infractions->lb_getAllInfractions();
            break;
        case 'bam':
            $all_infractions = $infractions->bam_getAllInfractions();
            break;
        case 'bu':
            $all_infractions = $infractions->bu_getAllInfractions();
            break;
    }
    // Pagination
    $paginate = PaginateArray($p);
    $n = $paginate[0];
    $f = $paginate[1];
    if (count($all_infractions) > $f) {
        $d = $p * 10;
    } else {
        $d = count($all_infractions) - $n;
        $d = $d + $n;
    }