2017-06-07 00:29:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Filter {
|
2017-06-19 17:24:02 +00:00
|
|
|
|
|
|
|
public $defaults = array(
|
|
|
|
'Name' => '',
|
|
|
|
'AutoExecute' => 0,
|
|
|
|
'AutoExecuteCmd' => 0,
|
|
|
|
'AutoEmail' => 0,
|
|
|
|
'AutoDetail' => 0,
|
|
|
|
'AutoArchive' => 0,
|
|
|
|
'AutoVideo' => 0,
|
|
|
|
'AutoMessage' => 0,
|
|
|
|
'Background' => 0,
|
|
|
|
'Concurrent' => 0,
|
|
|
|
'limit' => 100,
|
|
|
|
'terms' => array(),
|
|
|
|
'sort_field' => ZM_WEB_EVENT_SORT_FIELD,
|
|
|
|
'sort_asc' => (ZM_WEB_EVENT_SORT_ORDER == 'asc'),
|
|
|
|
);
|
|
|
|
|
|
|
|
public function __construct( $IdOrRow=NULL ) {
|
2017-06-07 00:29:17 +00:00
|
|
|
$row = NULL;
|
|
|
|
if ( $IdOrRow ) {
|
|
|
|
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
|
|
|
|
$row = dbFetchOne( 'SELECT * FROM Filters WHERE Id=?', NULL, array( $IdOrRow ) );
|
|
|
|
if ( ! $row ) {
|
|
|
|
Error('Unable to load Filter record for Id=' . $IdOrRow );
|
|
|
|
}
|
|
|
|
} elseif ( is_array( $IdOrRow ) ) {
|
|
|
|
$row = $IdOrRow;
|
|
|
|
} else {
|
|
|
|
$backTrace = debug_backtrace();
|
|
|
|
$file = $backTrace[1]['file'];
|
|
|
|
$line = $backTrace[1]['line'];
|
|
|
|
Error("Unknown argument passed to Filter Constructor from $file:$line)");
|
|
|
|
Error("Unknown argument passed to Filter Constructor ($IdOrRow)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} # end if isset($IdOrRow)
|
|
|
|
|
|
|
|
if ( $row ) {
|
|
|
|
foreach ($row as $k => $v) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // end function __construct
|
|
|
|
|
2017-06-19 17:24:02 +00:00
|
|
|
public function __call( $fn, array $args ) {
|
|
|
|
if ( count( $args ) ) {
|
|
|
|
$this->{$fn} = $args[0];
|
|
|
|
}
|
2017-06-07 00:29:17 +00:00
|
|
|
if ( array_key_exists( $fn, $this ) ) {
|
|
|
|
return $this->{$fn};
|
2017-06-19 17:24:02 +00:00
|
|
|
} else if ( array_key_exists( $fn, $this->defaults ) ) {
|
|
|
|
return $this->defaults{$fn};
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$backTrace = debug_backtrace();
|
|
|
|
$file = $backTrace[1]['file'];
|
|
|
|
$line = $backTrace[1]['line'];
|
|
|
|
Warning( "Unknown function call Filter->$fn from $file:$line" );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function terms( ) {
|
|
|
|
if ( func_num_args( ) ) {
|
|
|
|
$this->{'terms'} = func_get_arg(0);
|
|
|
|
Warning("terms set " . $this->{'terms'} );
|
|
|
|
}
|
|
|
|
if ( ! isset( $this->{'terms'} ) ) {
|
|
|
|
Warning("terms not set " . array_key_exists( 'Query', $this ) );
|
|
|
|
if ( array_key_exists( 'Query', $this ) and $this->{'Query'} ) {
|
|
|
|
Warning("Decoding terms not set");
|
|
|
|
|
|
|
|
$this->{'terms'} = jsonDecode( $this->{'Query'} );
|
|
|
|
} else {
|
|
|
|
Warning("Defaulting terms not set");
|
|
|
|
$this->{'terms'} = array();
|
|
|
|
}
|
2017-06-07 00:29:17 +00:00
|
|
|
}
|
2017-06-19 17:24:02 +00:00
|
|
|
return $this->{'terms'};
|
2017-06-07 00:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function find_all() {
|
|
|
|
$filters = array();
|
|
|
|
$result = dbQuery( 'SELECT * FROM Filters ORDER BY Name');
|
|
|
|
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter' );
|
|
|
|
foreach ( $results as $row => $obj ) {
|
|
|
|
$filters[] = $obj;
|
|
|
|
}
|
|
|
|
return $filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete() {
|
|
|
|
dbQuery( 'DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}) );
|
|
|
|
} # end function delete()
|
|
|
|
|
2017-06-19 17:24:02 +00:00
|
|
|
public function set( $data ) {
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if ( is_array( $v ) ) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
} else if ( is_string( $v ) ) {
|
|
|
|
$this->{$k} = trim( $v );
|
|
|
|
} else if ( is_integer( $v ) ) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
} else if ( is_bool( $v ) ) {
|
|
|
|
$this->{$k} = $v;
|
|
|
|
} else {
|
|
|
|
Error( "Unknown type $k => $v of var " . gettype( $v ) );
|
|
|
|
$this->{$k} = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-07 00:29:17 +00:00
|
|
|
} # end class
|
|
|
|
|
|
|
|
?>
|