# Copyright (c) 2001-2007 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: LocationBase.pm,v 2.7 2010/04/06 21:34:18 moeller Exp $ package Bivio::Biz::Model::LocationBase; use strict; use Bivio::Base 'Bivio::Biz::PropertyModel'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.7 $ =~ /\d+/g); my($_L) = b_use('Type.Location'); my($_DEFAULT_LOCATION) = $_L->get_default; sub DEFAULT_LOCATION { return $_DEFAULT_LOCATION; } sub create { my($self, $values) = @_; $values->{location} ||= $_DEFAULT_LOCATION; $values->{realm_id} ||= $self->req('auth_id'); return $self->SUPER::create($values); } sub execute_load_home { my($proto, $req) = @_; $proto->new($req)->load({ location => $_L->HOME, }); return 0; } sub internal_unique_load_values { my($self, $values) = @_; return { map(($_ => $values->{$_} || return), 'realm_id', ), location => $values->{location} || $_DEFAULT_LOCATION, }; } sub unauth_load { my($self) = shift; # If I is set and I isn't, sets I to I # and calls SUPER. my($query) = int(@_) == 1 ? @_ : {@_}; $query->{location} = $_DEFAULT_LOCATION if !$query->{location} && $query->{realm_id}; return $self->SUPER::unauth_load($query); } 1;