Bric::Util::Alert(3)

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

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2006-03-18 01:26:34 +0100 (Sat, 18 Mar 2006) $

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:

    *   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.

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:

    *   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 $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:

    id  Alert ID. May use "ANY" for a list of possible values.

    alert_type_id
        A Bric::Util::AlertType ID. May use "ANY" for a list of possible values.

    event_id
        A Bric::Util::Event ID. May use "ANY" for a list of possible values.

    subject
    name
        An alert subject. "name" is an alias for "subject". May use "ANY" for a list of possible values.

    message
        An alert message. May use "ANY" for a list of possible values.

    timestamp
        An alert timestamp. May use "ANY" for a list of possible values.

    time_start
    time_end
        These two parameters, when used, must be used together to specify a range of dates between which to retrieve Bric::Util::Alert objects.

    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

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:

    *   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
(@meths || $meths_aref) = Bric::Util::Alert->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::Alert->my_meths(0, TRUE)
    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 "id", 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

my $id = $alert->get_id
    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 "save"d, 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:

    *   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.

my $at_id = $alert->get_alert_type_id
    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.

my $event = $alert->get_event
    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.

my $eid = $alert->get_event_id
    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.

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:

    *   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.

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:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

    *   Access denied: READ access for field 'message' required.

    *   No AUTOLOAD method.

    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_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.

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:

    *   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.

$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:

    *   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.

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, $user)
    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@justatheory.com>

SEE ALSO
Bric, Bric::Util::AlertType, Bric::Util::EventType, Bric::Util::Event