# Copyright (c) 1999-2010 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: Address.pm,v 2.3 2010/08/17 11:51:09 nagler Exp $ package Bivio::Biz::Model::Address; use strict; use Bivio::Base 'Model.LocationBase'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.3 $ =~ /\d+/g); sub execute_load_home { my($proto, $req) = @_; $proto->new($req)->load({ location => Bivio::Type::Location->HOME, }); return 0; } sub format { my($self, $model, $model_prefix) = shift->internal_get_target(@_); my($m, $p) = ($model, $model_prefix); my($sep) = ', '; my($csz) = undef; foreach my $n ($m->unsafe_get($p.'city', $p.'state', $p.'zip')) { $csz .= $n.$sep if defined($n); $sep = ' '; } chop($csz), chop($csz) if defined($csz); my($res) = ''; my(@f) = $m->unsafe_get($p.'street1', $p.'street2', $p.'country'); splice(@f, 2, 0, $csz); foreach my $n (@f) { $res .= $n."\n" if defined($n); } chop($res); return $res; } sub internal_initialize { return { version => 1, table_name => 'address_t', columns => { realm_id => ['RealmOwner.realm_id', 'PRIMARY_KEY'], location => ['Location', 'PRIMARY_KEY'], street1 => ['Line', 'NONE'], street2 => ['Line', 'NONE'], city => ['Name', 'NONE'], state => ['Name', 'NONE'], zip => ['Name', 'NONE'], country => ['Country', 'NONE'], }, auth_id => 'realm_id', }; } 1;