NAME

Bric::Util::Alert - Interface to Bricolage Alerts

VERSION

$Revision: 1.9 $

DATE

$Date: 2002/08/30 22:13:41 $

SYNOPSIS

use Bric::Util::Alert;

# Constructors.
my $alert = Bric::Util::Alert->new($init);
$alert = Bric::Util::Alert->lookup({ id => 1 });
my @alerts = Bric::Util::Alert->list($params);

# Class Methods.
my @alert_ids = Bric::Util::Alert->list_ids($params);

# Instance Methods.
my $id = $alert->get_id;
my $at = $alert->get_alert_type;
my $at_id = $alert->get_alert_type_id;
my $event = $alert->get_event;
my $event_id = $alert->get_event_id;
my $subject = $alert->get_subject;
my $message = $alert->get_message;
my $timestamp = $alert->get_timestamp($format);
my @alerted = $alert->get_alerted;

DESCRIPTION

This class offers an interface to alerts created when an event evaluates truly the rules defined for a Bric::Util::AlertType object. It provides basic accessors to the properties of an individual alert, including a list of Bric::Util::Alerted objects representing the users who were sent the alert, when they were sent it, and when they acknolwedged the alert. See Bric::Util::Alerted for more information.

INTERFACE

Constructors

my $c = Bric::Util::Alert->new
my $c = Bric::Util::Alert->new($init)

Instantiates a Bric::Util::Alert object. An anonymous hash of initial values may be passed. The required initialization keys are:

The alert will be saved to the database upon creation and cannot be changed in any way after it has been created. Only Bric::Util::Alerted objects, which represent the users to whom the alert was sent, may have their acknowledged properties set. See Bric::Util::Alerted for its interface.

Generally this method will not be called directly, but by the Bric::Util::AlertType->send_alerts() method, which will be called by Bric::Util::Event->new(). Use lookup() and list() to retrieve pre-existing alerts.

Throws:

Side Effects: NONE.

Notes: NONE.

my $c = Bric::Util::Alert->lookup({ id => $id })

Looks up and instantiates a new Bric::Util::Alert object based on the Bric::Util::Alert object ID passed. If $id is not found in the database, lookup() returns undef.

Throws:

Side Effects: If $id is found, populates the new Bric::Util::Alert object with data from the database before returning it.

Notes: NONE.

my (@alerts || $alerts_aref) = Bric::Util::Alert->list($params)

Returns a list or anonymous array of Bric::Util::Alert objects based on the search parameters passed via an anonymous hash. The supported lookup keys are:

The last two lookup keys, time_start and time_end, must be used together, as they represent a range of dates between which to retrieve Bric::Util::Alert objects. Set no_ack to true to have list() return only unacknowledged alerts.

Any combination of these keys may be used, although the most common may be event_id or a combination of alert_type_id and no_ack.

Throws:

Side Effects: Populates each Bric::Util::Alert object with data from the database before returning them all.

Notes: NONE.

Destructors

$p->DESTROY

Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Class Methods

my (@alert_ids || $alert_ids_aref) = Bric::Util::Alert->list_ids($params)

Returns a list or anonymous array of Bric::Util::Alert object IDs based on the search parameters passed via an anonymous hash. The supported lookup keys are the same as those for list().

Throws:

Side Effects: NONE.

Notes: NONE.

$meths = Bric::Util::Alert->my_meths
(@meths || $meths_aref) = Bric::Util::Alert->my_meths(TRUE)

Returns an anonymous hash of instrospection data for this object. If called with a true argument, it will return an ordered list or anonymous array of intrspection data. The format for each introspection item introspection is as follows:

Each hash key is the name of a property or attribute of the object. The value for a hash key is another anonymous hash containing the following keys:

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

Public Instance Methods

my $id = $alert->get_id

Returns the ID of the Bric::Util::Alert object.

Throws:

Side Effects: NONE.

Notes: If the Bric::Util::Alert object has been instantiated via the new() constructor and has not yet been saved, the object will not yet have an ID, so this method call will return undef.

my $at = $alert->get_alert_type

Returns the Bric::Util::AlertType object defining this Alert.

Throws:

Side Effects: NONE.

Notes: NONE.

my $at_id = $alert->get_alert_type_id

Returns the ID of the Bric::Util::AlertType object defining this Alert.

Throws:

Side Effects: NONE.

Notes: NONE.

my $event = $alert->get_event

Returns the Bric::Util::Event object for which this alert was sent.

Throws:

Side Effects: NONE.

Notes: NONE.

my $eid = $alert->get_event_id

Returns the id of the Bric::Util::Event object for which this alert was sent.

Throws:

Side Effects: NONE.

Notes: NONE.

my $subect = $alert->get_subject
my $subject = $alert->get_name

Returns the text inserted into the subject line of this alert (where it's appropriate to do so, e.g., email). This subject is different from that defined by the Bric::Util::AlertType object on which this event is based in that any variables included in the Bric::Util::AlertType object's subject will be interpolated with their event-specific values. See Bric::Util::AlertType::set_subject() for more information.

Throws:

Side Effects: NONE.

Notes: NONE.

my $message = $alert->get_message

Returns the message sent in this alert. This message is different from the one defined by the Bric::Util::AlertType object on which this event is based in that any variables included in the Bric::Util::AlertType object's message will be interpolated with their event-specific values. See Bric::Util::AlertType::set_message() for more information.

Throws:

Side Effects: NONE.

Notes: NONE.

my $timestamp = $alert->get_timestamp($format)

Returns the time the alert was created. This differs from the times the alert was actually sent to various users by various means. That time can be retreived from individual Bric::Util::Alerted objects. get_timestmp() will take as an argument a strftime format string and return the time in that format. If not provided, the format returned will default to the ISO 8601 timedate format, in the users local time zone.

Throws:

Side Effects: NONE.

Notes: NONE.

my (@alerted || $alerted_aref) = $alert->get_alerted
foreach my $alerted ($alert->get_alerted) {
    print "Name:    ", $alerted->get_name, "\n";
    print "Message: ", $alerted->get_message, "\n";
    $alerted->acknowledge;
}

Returns a list of Bric::Util::Alerted objects representing the users who were sent this alert, how they were sent the alert, and when. The Bric::Util::Alerted object is also used to acknowledge individual users' alerts. See Bric::Util::Alerted for its interface.

Throws:

Side Effects: NONE.

Notes: NONE.

$self = $p->save

No-op.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

PRIVATE

Private Class Methods

NONE.

Private Instance Methods

NONE.

Private Functions

my $alerts_aref = &$get_em( $pkg, $params )
my $alert_ids_aref = &$get_em( $pkg, $params, 1 )

Function used by lookup() and list() to return a list of Bric::Util::Alert objects or, if called with an optional third argument, returns a list of Bric::Util::Alert object IDs (used by list_ids()).

Throws:

Side Effects: NONE.

Notes: NONE.

my $string = &$replace($string, $attr, $obj, $user)

This function is used by the regular expression in new() to add elements to messages based on simple variables in the Bric::Util::AlertType subject and message fields.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

my $bool = &$send_em($self, $at, $event)

Sends individual alerts to their recipients, and creates new Bric::Util::Alerted objects for each one of them.

Throws: NONE.

Side Effects: NONE.

Notes: NONE.

NOTES

NONE.

AUTHOR

David Wheeler <david@wheeler.net>

SEE ALSO

Bric, Bric::Util::AlertType, Bric::Util::EventType, Bric::Util::Event

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 453:

=back doesn't take any parameters, but you said =back 4

Around line 609:

Expected '=item *'

Around line 611:

Expected '=item *'

Around line 613:

Expected '=item *'

Around line 615:

Expected '=item *'

Around line 617:

Expected '=item *'

Around line 619:

Expected '=item *'

Around line 621:

Expected '=item *'

Around line 1135:

=back doesn't take any parameters, but you said =back 4

Around line 1365:

You forgot a '=back' before '=head1'