From 518a65df78c122b7b23e31136e30f800f2508f62 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Tue, 31 Jan 2006 21:45:17 +0000 Subject: [PATCH] the beginnings of the message log replacement --- lib/WebGUI/User.pm | 23 +++- lib/WebGUI/User/Inbox.pm | 121 +++++++++++++++++++++ lib/WebGUI/User/Inbox/Message.pm | 173 +++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 lib/WebGUI/User/Inbox.pm create mode 100644 lib/WebGUI/User/Inbox/Message.pm diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 405e50286..d2d9edf6a 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -17,7 +17,7 @@ package WebGUI::User; use strict; use WebGUI::Cache; use WebGUI::Group; - +use WebGUI::User::Inbox; =head1 NAME @@ -46,6 +46,8 @@ This package provides an object-oriented way of managing WebGUI users as well as $u->deleteFromGroups(\@arr); $u->delete; + my $inbox = $u->inbox; + =head1 METHODS These methods are available from this class: @@ -137,6 +139,7 @@ Deletes this user. sub delete { my $self = shift; $self->uncache; + $self->inbox->delete; foreach my $groupId (@{$self->getGroups($self->userId)}) { WebGUI::Group->new($self->session,$groupId)->deleteUsers([$self->userId]); } @@ -179,6 +182,7 @@ Deconstructor. sub DESTROY { my $self = shift; + $self->{_inbox}->DESTROY if (exists $self->{_inbox}); undef $self; } @@ -230,6 +234,23 @@ sub identifier { return $self->{_user}{"identifier"}; } +#------------------------------------------------------------------- + +=head2 inbox + +Returns the user's WebGUI::User::Inbox object. + +=cut + +sub inbox { + my $self = shift; + unless ($self->{_inbox}) { + $self->{_inbox} = WebGUI::User::Inbox->new($self); + } + return $self->{_inbox}; +} + + #------------------------------------------------------------------- =head2 isInGroup ( [ groupId ] ) diff --git a/lib/WebGUI/User/Inbox.pm b/lib/WebGUI/User/Inbox.pm new file mode 100644 index 000000000..6a13e5de2 --- /dev/null +++ b/lib/WebGUI/User/Inbox.pm @@ -0,0 +1,121 @@ +package WebGUI::User::Inbox; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; + +=head1 NAME + +Package WebGUI::User::Inbox; + +=head1 DESCRIPTION + +This package provides an API for working with a User's inbox. + +=head1 SYNOPSIS + + my $inbox = $user->inbox; + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 addMessage ( ) + +=cut + +sub addMessage { + my $self = shift; + return WebGUI::User::Inbox::Message->create($self); +} + +#------------------------------------------------------------------- + +=head2 deleteAllMessages + +Deletes all the messages in this user's inbox. + +=cut + +sub deleteAllMessages { + my $self = shift; + my $sth = $self->session->db->prepare("delete from userInbox where userId=?"); + $sth->execute($self->user->userId); +} + +#------------------------------------------------------------------- + +=head DESTROY ( ) + +Deconstructor. + +=cut + +sub DESTROY { + my $self = shift; + undef $self; +} + +#------------------------------------------------------------------- + +=head2 new ( user ) + +Constructor. + +=head3 user + +A reference to the user who's inbox that we'll be manipulating. + +=cut + +sub new { + my $class = shift; + my $user = shift; + bless {_user=>$user}, $class; +} + +#------------------------------------------------------------------- + +=head2 session + +Returns a reference to the current session. + +=cut + +sub session { + my $self = shift; + return $self->user->session; +} + +#------------------------------------------------------------------- + +=head2 user + +Returns a reference to the user who owns this inbox. + +=cut + +sub user { + my $self = shift; + return $self->{_user}; +} + +1; + diff --git a/lib/WebGUI/User/Inbox/Message.pm b/lib/WebGUI/User/Inbox/Message.pm new file mode 100644 index 000000000..df3cae6ca --- /dev/null +++ b/lib/WebGUI/User/Inbox/Message.pm @@ -0,0 +1,173 @@ +package WebGUI::User::Inbox::Message; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; + +=head1 NAME + +Package WebGUI::User::Inbox::Message; + +=head1 DESCRIPTION + +This package provides an API for working with a User's inbox messages. + +=head1 SYNOPSIS + + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 create ( ) + +=cut + +sub create { + my $self = shift; +} + +#------------------------------------------------------------------- + +=head2 delete + +Deletes this message from the inbox. + +=cut + +sub delete { + my $self = shift; + my $sth = $self->session->db->prepare("delete from userInbox where messageId=?"); + $sth->execute($self->getId); +} + +#------------------------------------------------------------------- + +=head DESTROY ( ) + +Deconstructor. + +=cut + +sub DESTROY { + my $self = shift; + undef $self; +} + +#------------------------------------------------------------------- + +=head2 get ( property ) + +Returns the value of a property. + +=head3 property + +The name of any property of an inbox message. + +=head4 message + +=head4 subject + +=cut + +sub get { + my $self = shift; + unless ($self->{_properties}) { + $self->{_properties} = $self->session->db->getRow("userInbox","messageId",$self->getId); + } + return $self->{_properties}{shift}; +} + + +#------------------------------------------------------------------- + +=head2 getId () + +Returns the ID of this message. + +=cut + +sub getId { + my $self = shift; + return $self->{_messageId}; +} + +#------------------------------------------------------------------- + +=head2 inbox + +Returns a reference to the user's inbox. + +=cut + +sub inbox { + my $self = shift; + return $self->{_inbox}; +} + +#------------------------------------------------------------------- + +=head2 new ( inbox, messageId ) + +Constructor. + +=head3 inbox + +A reference to a user's inbox object. + +=head3 messageId + +=cut + +sub new { + my $class = shift; + my $inbox = shift; + my $messageId = shift; + bless {_inbox=>$inbox, _messageId=>$messageId}, $class; +} + +#------------------------------------------------------------------- + +=head2 session + +Returns a reference to the current session. + +=cut + +sub session { + my $self = shift; + return $self->inbox->session; +} + +#------------------------------------------------------------------- + +=head2 user + +Returns a reference to the user who owns this inbox. + +=cut + +sub user { + my $self = shift; + return $self->inbox->user; +} + +1; +