man Bric::Util::Alert () - Interface to Bricolage Alerts

NAME

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

VERSION

$LastChangedRevision$

DATE

$LastChangedDate: 2004-08-12 17:13:34 -0700 (Thu, 12 Aug 2004) $

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

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

*
at - A Bric::Util::AlertType object defining the type of alert this is.
*
event - A Bric::Util::Event object representing the event for which this alert is created.
*
obj - The Bricolage object for which the event was triggered. Its properties and attributes will be used to replace variables in the alert subject and message.
*
user - The Bric::Biz::Person::User object representing the user who triggered the event and hence this alert. Its properties and attributes will be used to replace variables in the alert subject and message. 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:
*
Bric::Util::Alert::new() requires a Bricolage object, a Bric::Biz::Person::User object, a Bric::Util::AlertType object, and a Bric::Util::Event object.
*
Unable to connect to database.
*
Unable to prepare SQL statement.
*
Unable to execute SQL statement.
*
Unable to select row.
*
Incorrect number of args to _set.
*
Bric::_set() - Problems setting fields.
*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field required.
*
Access denied: WRITE access for field required.
*
No AUTOLOAD method.
*
Unable to send mail.
*
Unable to send instant message. Side Effects: NONE. Notes: NONE. Looks up and instantiates a new Bric::Util::Alert object based on the Bric::Util::Alert object ID passed. If CW$id is not found in the database, lookup() returns undef. Throws:
*
Too many Bric::Util::Alert objects found.
*
Unable to prepare SQL statement.
*
Unable to connect to database.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: If CW$id is found, populates the new Bric::Util::Alert object with data from the database before returning it. Notes: NONE. 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:
*
alert_type_id
*
event_id
*
subject
*
message
*
timestamp
*
no_ack
*
time_start and time_end 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:
*
Unable to connect to database.
*
Unable to prepare SQL statement.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. 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

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:

*
Unable to connect to database.
*
Unable to prepare SQL statement.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: NONE. Notes: NONE.
$meths = Bric::Util::Alert->my_meths
Returns an anonymous hash of introspection data for this object. If called with a true argument, it will return an ordered list or anonymous array of introspection data. If a second true argument is passed instead of a first, then a list or anonymous array of introspection data will be returned for properties that uniquely identify an object (excluding CWid, which is assumed). 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:
name
The name of the property or attribute. Is the same as the hash key when an anonymous hash is returned.
disp
The display name of the property or attribute.
get_meth
A reference to the method that will retrieve the value of the property or attribute.
get_args
An anonymous array of arguments to pass to a call to get_meth in order to retrieve the value of the property or attribute.
set_meth
A reference to the method that will set the value of the property or attribute.
set_args
An anonymous array of arguments to pass to a call to set_meth in order to set the value of the property or attribute.
type
The type of value the property or attribute contains. There are only three types:
short
date
blob
len
If the value is a 'short' value, this hash key contains the length of the field.
search
The property is searchable via the list() and list_ids() methods.
req
The property or attribute is required.
props
An anonymous hash of properties used to display the property or attribute. Possible keys include:
type
The display field type. Possible values are
text
textarea
password
hidden
radio
checkbox
select
length
The Length, in letters, to display a text or password field.
maxlength
The maximum length of the property or value - usually defined by the SQL DDL.
rows
The number of rows to format in a textarea field.
cols
The number of columns to format in a textarea field.
vals
An anonymous hash of key/value pairs reprsenting the values and display names to use in a select list. Throws: NONE. Side Effects: NONE. Notes: NONE.

Public Instance Methods

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

*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field 'id' required.
*
No AUTOLOAD method. Side Effects: NONE. Notes: If the Bric::Util::Alert object has been instantiated via the new() constructor and has not yet been CWsaved, the object will not yet have an ID, so this method call will return undef. Returns the Bric::Util::AlertType object defining this Alert. Throws:
*
Bric::_get() - Problems retrieving fields.
*
Too many Bric::Util::AlertType objects found.
*
Unable to prepare SQL statement.
*
Unable to connect to database.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: NONE. Notes: NONE. Returns the ID of the Bric::Util::AlertType object defining this Alert. Throws:
*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field 'alert_type_id' required.
*
No AUTOLOAD method. Side Effects: NONE. Notes: NONE. Returns the Bric::Util::Event object for which this alert was sent. Throws:
*
Bric::_get() - Problems retrieving fields.
*
Too many Bric::Util::Event objects found.
*
Unable to prepare SQL statement.
*
Unable to connect to database.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: NONE. Notes: NONE. Returns the id of the Bric::Util::Event object for which this alert was sent. Throws:
*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field 'event_id' required.
*
No AUTOLOAD method. Side Effects: NONE. Notes: NONE. 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:
*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field 'message' required.
*
No AUTOLOAD method.
*
Problems retrieving fields. Side Effects: NONE. Notes: NONE. 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:
*
Bad AUTOLOAD method format.
*
Cannot AUTOLOAD private methods.
*
Access denied: READ access for field 'message' required.
*
No AUTOLOAD method. Side Effects: NONE. Notes: NONE. 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_timestamp() 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:
*
Bric::_get() - Problems retrieving fields.
*
Unable to unpack date.
*
Unable to format date. Side Effects: NONE. Notes: NONE.
  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:
*
Bric::_get() - Problems retrieving fields.
*
Too many Bric::Util::Alerted objects found.
*
Unable to prepare SQL statement.
*
Unable to connect to database.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: NONE. Notes: NONE. No-op. Throws: NONE. Side Effects: NONE. Notes: NONE.

PRIVATE

Private Class Methods

NONE.

Private Instance Methods

NONE.

Private Functions

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:

*
Unable to prepare SQL statement.
*
Unable to connect to database.
*
Unable to select column into arrayref.
*
Unable to execute SQL statement.
*
Unable to bind to columns to statement handle.
*
Unable to fetch row from statement handle. Side Effects: NONE. Notes: NONE. 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. 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