mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
101 lines
2.5 KiB
Perl
101 lines
2.5 KiB
Perl
# ==========================================================================
|
|
#
|
|
# ZoneMinder Zone Module
|
|
# Copyright (C) 2020 ZoneMinder LLC
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
#
|
|
# ==========================================================================
|
|
|
|
package ZoneMinder::Model;
|
|
|
|
use 5.006;
|
|
use strict;
|
|
use warnings;
|
|
|
|
require ZoneMinder::Base;
|
|
require ZoneMinder::Object;
|
|
|
|
#our @ISA = qw(Exporter ZoneMinder::Base);
|
|
use ZoneMinder::Logger qw(:all);
|
|
use parent qw(ZoneMinder::Object);
|
|
|
|
use vars qw/ $table $primary_key %fields $serial %defaults $debug/;
|
|
$table = 'Models';
|
|
$serial = $primary_key = 'Id';
|
|
%fields = map { $_ => $_ } qw(
|
|
Id
|
|
Name
|
|
ManufacturerId
|
|
);
|
|
|
|
%defaults = (
|
|
Name => '',
|
|
);
|
|
|
|
sub Manufacturer {
|
|
my $self = shift;
|
|
$$self{Manufacturer} = shift if @_;
|
|
if (!$$self{Manufacturer} and $$self{ManufacturerId}) {
|
|
require ZoneMinder::Manufacturer;
|
|
$$self{Manufacturer} = new ZoneMinder::Manufacturer($$self{ManufacturerId});
|
|
}
|
|
return $$self{Manufacturer};
|
|
}
|
|
|
|
sub save {
|
|
my $self = shift;
|
|
|
|
my $manufacturer = $self->Manufacturer();
|
|
|
|
if ($manufacturer and $manufacturer->Name() and !$self->ManufacturerId()) {
|
|
# save() returns the error string on failure, '' on success.
|
|
if (my $error = $manufacturer->save()) {
|
|
Error('Failed saving Manufacturer '.$manufacturer->Name().": $error");
|
|
} else {
|
|
$$self{ManufacturerId} = $manufacturer->Id();
|
|
}
|
|
}
|
|
|
|
my $error = $self->SUPER::save(@_);
|
|
return $error;
|
|
} # end sub save
|
|
|
|
|
|
1;
|
|
__END__
|
|
|
|
=head1 NAME
|
|
|
|
ZoneMinder::Model - Perl Class for Models
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use ZoneMinder::Model;
|
|
|
|
=head1 AUTHOR
|
|
|
|
Isaac Connor, E<lt>isaac@zoneminder.comE<gt>
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
Copyright (C) 2023 ZoneMinder Inc
|
|
|
|
Licensed under the GNU General Public License v2 or later; see the COPYING
|
|
file distributed with ZoneMinder for the full text.
|
|
|
|
|
|
=cut
|