Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 77 lines (65 sloc) 2.141 kb
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
<?php

/*
* Copyright © 2010 - 2012 Modo Labs Inc. All rights reserved.
*
* The license governing the contents of this file is located in the LICENSE
* file located at the root directory of this distribution. If the LICENSE file
* is missing, please contact sales@modolabs.com.
*
*/

class KurogoStatsFilter {
    protected $field = '';
    protected $comparison = '';
    protected $value = '';

    protected function isValidField($field) {
        return preg_match("/^[a-zA-Z_]+$/", $field);
    }
    
    protected function isValidComparison($comparison = '') {
        $result = in_array($comparison, array('LT', 'GT', 'EQ', 'NEQ', 'GTE', 'LTE', 'IN'));
        return $result;
    }
    
    public function getDBString() {
        $symbol = $this->comparisonSymbol($this->comparison);
        if ($symbol == 'IN') {
            $value = is_array($this->value) ? "('" . array_fill(0, count($this->value), '?') . ')' : '(?)';
        } else {
            $value = '?';
        }

        return $this->field . $this->comparisonSymbol($this->comparison) . $value;
    }
    
    public function getValue() {
        return $this->value;
    }

    public function getField() {
        return $this->field;
    }
    
    protected function comparisonSymbol($comparison) {
        $Comparisons = array(
            'LT' => '<',
            'GT' => '>',
            'EQ' => '=',
            'NEQ' => '!=',
            'GTE' => '>=',
            'LTE' => '<=',
            'IN' => 'IN',
        );
        return isset($Comparisons[$comparison]) ? $Comparisons[$comparison] : '';
    }
    
    public function setField($field) {
        if ($this->isValidField($field)) {
            $this->field = $field;
        } else {
            throw new Exception("Invalid field $field");
        }
    }

    public function setValue($value) {
        $this->value = $value;
    }
    
    public function setComparison($comparison) {
        if ($this->isValidComparison($comparison)) {
            $this->comparison = $comparison;
        } else {
            throw new Exception("Invalid comparison $comparison");
        }
    }
}
Something went wrong with that request. Please try again.