# Copyright (c) 2006 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: RealmBase.pm,v 1.5 2008/10/24 22:22:56 nagler Exp $ package Bivio::Biz::Model::RealmBase; use strict; use Bivio::Base 'Biz.PropertyModel'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.5 $ =~ /\d+/g); my($_DT) = Bivio::Type->get_instance('DateTime'); sub REALM_ID_FIELD { return 'realm_id'; } sub USER_ID_FIELD { return 'user_id'; } sub create { my($self, $values) = @_; my($req) = $self->get_request; $values->{$self->REALM_ID_FIELD} ||= $req->get('auth_id'); $values->{$self->USER_ID_FIELD} ||= $req->get('auth_user_id') if $self->USER_ID_FIELD && $self->has_fields($self->USER_ID_FIELD); my($t); foreach my $f (qw(modified_date_time creation_date_time)) { $values->{$f} ||= ($t ||= $_DT->now) if $self->has_fields($f); } return shift->SUPER::create(@_); } sub internal_initialize { my($self) = @_; return $self->merge_initialize_info($self->SUPER::internal_initialize, { columns => { $self->REALM_ID_FIELD => ['RealmOwner.realm_id', 'NOT_NULL'], }, auth_id => $self->REALM_ID_FIELD, }); } sub update { my($self, $values) = @_; $values->{modified_date_time} ||= $_DT->now if $self->has_fields('modified_date_time'); return shift->SUPER::update(@_); } 1;