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:
<?php
abstract class HTMLTableDateComparatorSQLFilter extends AbstractHTMLTableFilter implements SQLFragmentBuilder
{
private static $param_id_index = 0;
private $db_field;
public function __construct($db_field, $name, $label)
{
$this->db_field = $db_field;
$form_field_class = $this->get_form_field_class();
$field = new $form_field_class($name, $label);
parent::__construct($name, $field);
}
public function get_sql()
{
$parameter_name = $this->get_sql_value_parameter_prefix() . '_' . $this->db_field;
$query = $this->db_field . ' ' . $this->get_sql_comparator_symbol() . ' :' . $parameter_name;
$parameters = array($parameter_name => $this->get_value()->get_timestamp());
return new SQLFragment($query, $parameters);
}
public function is_value_allowed($value)
{
if (preg_match("/\d{4}\-\d{2}-\d{2}/", $value) || preg_match("/\d{2}\/\d{2}\/\d{4}/", $value))
{
$this->set_value(new Date($this->get_timestamp($value), Timezone::SERVER_TIMEZONE));
return true;
}
return false;
}
protected function get_sql_value_parameter_prefix()
{
return __CLASS__ . '_' . self::$param_id_index++;
}
abstract protected function get_sql_comparator_symbol();
abstract protected function get_form_field_class();
protected function get_timestamp($value)
{
return strtotime($value);
}
}
?>