From 7e37c6aec4804f0941ceab53db090b97f044e35c Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 13 Aug 2008 15:21:35 +0000 Subject: [PATCH] added the newByUserId constructor --- lib/WebGUI/Shop/Vendor.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/WebGUI/Shop/Vendor.pm b/lib/WebGUI/Shop/Vendor.pm index 9c01fc461..a754f2ae3 100644 --- a/lib/WebGUI/Shop/Vendor.pm +++ b/lib/WebGUI/Shop/Vendor.pm @@ -173,6 +173,35 @@ sub new { return $self; } +#------------------------------------------------------------------- + +=head2 newByUserId ( session, [userId] ) + +Constructor. + +=head3 session + +A reference to the current session. + +=head3 userId + +A unique userId. Will pull from the session if not specified. + +=cut + +sub newByUserId { + my ($class, $session, $userId) = @_; + unless (defined $session && $session->isa("WebGUI::Session")) { + WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session."); + } + $userId ||= $session->user->userId; + unless (defined $userId) { + WebGUI::Error::InvalidParam->throw( param=>$userId, error=>"Need a userId."); + } + return $class->new($session, $session->db->quickScalar("select vendorId from vendor where userId=?",[$userId])); +} + + #------------------------------------------------------------------- =head2 session ()