Update Filter object, specifying fields and using parent's find methods
This commit is contained in:
parent
58fae48736
commit
4bd0cca4b8
|
@ -49,49 +49,34 @@ use ZoneMinder::Database qw(:all);
|
||||||
require ZoneMinder::Storage;
|
require ZoneMinder::Storage;
|
||||||
require ZoneMinder::Server;
|
require ZoneMinder::Server;
|
||||||
|
|
||||||
sub Name {
|
use vars qw/ $table $primary_key %fields /;
|
||||||
if ( @_ > 1 ) {
|
$table = 'Users';
|
||||||
$_[0]{Name} = $_[1];
|
$primary_key = 'Id';
|
||||||
}
|
|
||||||
return $_[0]{Name};
|
|
||||||
} # end sub Path
|
|
||||||
|
|
||||||
sub find {
|
%fields = map { $_ => $_ } qw(
|
||||||
shift if $_[0] eq 'ZoneMinder::Filter';
|
Id
|
||||||
my %sql_filters = @_;
|
Name
|
||||||
|
Query_json
|
||||||
my $sql = 'SELECT * FROM Filters';
|
AutoArchive
|
||||||
my @sql_filters;
|
AutoVideo
|
||||||
my @sql_values;
|
AutoUpload
|
||||||
|
AutoEmail
|
||||||
if ( exists $sql_filters{Name} ) {
|
EmailTo
|
||||||
push @sql_filters , ' Name = ? ';
|
EmailSubject
|
||||||
push @sql_values, $sql_filters{Name};
|
EmailBody
|
||||||
}
|
AutoMessage
|
||||||
|
AutoExecute
|
||||||
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
AutoExecuteCmd
|
||||||
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
AutoDelete
|
||||||
|
AutoMove
|
||||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached($sql)
|
AutoMoveTo
|
||||||
or Fatal("Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr());
|
AutoCopy
|
||||||
my $res = $sth->execute(@sql_values)
|
AutoCopyTo
|
||||||
or Fatal("Can't execute '$sql': ".$sth->errstr());
|
UpdateDiskSpace
|
||||||
|
UserId
|
||||||
my @results;
|
Background
|
||||||
|
Concurrent
|
||||||
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
);
|
||||||
my $filter = new ZoneMinder::Filter($$db_filter{Id}, $db_filter);
|
|
||||||
push @results, $filter;
|
|
||||||
} # end while
|
|
||||||
$sth->finish();
|
|
||||||
|
|
||||||
return @results;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub find_one {
|
|
||||||
my @results = find(@_);
|
|
||||||
return $results[0] if @results;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub Execute {
|
sub Execute {
|
||||||
my $self = $_[0];
|
my $self = $_[0];
|
||||||
|
@ -458,6 +443,15 @@ sub DateTimeToSQL {
|
||||||
return POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($dt_val));
|
return POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($dt_val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub User {
|
||||||
|
my $self = shift;
|
||||||
|
$$self{User} = shift if @_;
|
||||||
|
if ( ! $$self{User} and $$self{UserId} ) {
|
||||||
|
$$self{User} = ZoneMinder::User->find_one(Id=>$$self{UserId});
|
||||||
|
}
|
||||||
|
return $$self{User};
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
__END__
|
__END__
|
||||||
# Below is stub documentation for your module. You'd better edit it!
|
# Below is stub documentation for your module. You'd better edit it!
|
||||||
|
|
Loading…
Reference in New Issue