Bric::Util::Alerted(3)

NAME
Bric::Util::Alerted - Interface to Alerts as they are sent to individual users.

VERSION
$LastChangedRevision$

DATE
$LastChangedDate: 2004-06-04 12:21:12 -0700 (Fri, 04 Jun 2004) $

SYNOPSIS
  use Bric::Util::Alerted;

  # Constructors.
  my $alerted = Bric::Util::Alerted->lookup({ id => 1 });
  my @alerteds = Bric::Util::Alerted->list($params);

  # Class Methods.
  my @alerted_ids = Bric::Util::Alerted->list_ids($params);
  my $bool = Bric::Util::Alerted->ack_by_id(@alerted_ids);

  # Instance Methods.
  my $id = $alerted->get_id;
  my $at_id = $alerted->get_alert_id;
  my $alert = $alerted->get_alert;
  my $uid = $alerted->get_user_id;
  my $user = $alerted->get_user;
  my @sent = $alerted->get_sent;

  $alerted = $alered->acknowledge;
  my $ack_time = $alerted->get_ack_time($format);

DESCRIPTION
This class is the interface to individual user Alerts. While Bric::Util::Alert objects are created once for a given event, many different users may receive those alerts. Bric::Util::Alerted provides access to those user-specific instances of a particular alert. All methods by which a user is alerted are covered by a single Bric::Util::Alerted object for that Bric::Util::Alert alert, and when a user acknowledges an alert, all methods by which it was sent are acknowledged.

INTERFACE

  Constructors

my $c = Bric::Util::Alerted->lookup({ id => $id })
    Looks up and instantiates a new Bric::Util::Alerted object based on the Bric::Util::Alerted object ID passed. If $id is not found in the database, lookup() returns undef.

    Throws:

    *   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: If $id is found, populates the new Bric::Util::Alerted object with data from the database before returning it.

    Notes: NONE.

my (@alerteds || $alerteds_aref) = Bric::Util::Alerted->list($params)
    Returns a list or anonymous array of Bric::Util::Alerted objects based on the search parameters passed via an anonymous hash. The supported lookup keys are:

    *   alert_id

    *   user_id

    *   ack_time - May pass in as an anonymous array of two values, the first the minimum acknowledged time, the second the maximum acknowledged time. If the first array item is undefined, then the second will be considered the date that ack_time must be less than. If the second array item is undefined, then the first will be considered the date that ack_time must be greater than. If the value passed in is undefined, then the query will specify 'IS NULL'.

    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::Alerted objects.

    Any combination of these keys may be used, although the most common may be alert_id or user_id.

    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::Alerted 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 (@alrtd_ids || $alrtd_ids_aref) = Bric::Util::Alerted->list_ids($params)
    Returns a list or anonymous array of Bric::Util::Alerted 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::Alerted->my_meths
(@meths || $meths_aref) = Bric::Util::Alerted->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::Alerted->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.

my $bool = Bric::Util::Alerted->ack_by_id(@alerted_ids)
    If a whole bunch of alerteds need to be acknowledged at once, use this method and simply pass in all of their IDs, rather than instantiating each one and acknowledging it in turn. This will dramatically cut down on the overhead, as ack_by_id() will execute fewer queries.

    Throws:

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to execute SQL statement.

    Side Effects: NONE.

    Notes: NONE.

  Public Instance Methods

my $id = $alerted->get_id
    Returns the ID of the Bric::Util::Alerted 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::Alerted 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 $user = $alerted->get_user
    Returns the Bric::Biz::Person::User object representing the user to whom the alert was sent.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Too many Bric::Biz::Person::User 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: Uses Bric::Biz::Person::User->lookup() internally.

    Notes: NONE.

my $uid = $alerted->get_user_id
    Returns the Bric::Biz::Person::User object ID representing the user to whom the alert was sent.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $alert = $alerted->get_alert
    Returns the Bric::Util::Alert object representing the alert for which this Bric::Util::Alerted object was created.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

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

    Notes: NONE.

my $aid = $alerted->get_alert_id
    Returns the id of the Bric::Util::Alert object representing the alert for which this Bric::Util::Alerted object was created.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $subject = $alerted->get_subject
my $subject = $alerted->get_name
    Returns the subject of the alert for which this recipient was notified.

    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 $msg = $alerted->get_message
    Returns the message of the alert for which this recipient was notified.

    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 = $alerted->get_timestamp($format)
    Returns the time at which the alert was sent to the user. Pass in a strftime formatting string to get the time formatted by that format; otherwise, the time will be formatted in the format splecified for the 'Date/Time Format' preference.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to unpack date.

    *   Unable to format date.

    Side Effects: NONE.

    Notes: NONE.

my $ack_time = $alerted->get_ack_time($format)
    Returns the time at which the alert has been acknowledged by the user to whom it was sent. Pass in a strftime formatting string to get the time formatted by that format; otherwise, the time will be formatted in the format splecified for the 'Date/Time Format' preference. Returns undef if the alert has not yet been acknowledged. Call acknowledge() to acknowledge the alert.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to unpack date.

    *   Unable to format date.

    Side Effects: NONE.

    Notes: NONE.

$self = $alerted->acknowledge
    Acknowledges the alert. Call this method when the user who was sent the alert acknowledges receipt of the alert. The ack_time property will then be filled enumerated. This is the only method that updates the Bric::Util::Alerted object, and can only be called once. If the Bric::Util::Alerted object has already been acknowledged, this method will return undef; otherwise it will return $self.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    *   Unable to connect to database.

    *   Unable to prepare SQL statement.

    *   Unable to execute SQL statement.

    Side Effects: NONE.

    Notes: NONE.

my (@sent || $sent_aref) = $alerted->get_sent
    Returns a list or anonymous array of Bric::Util::Alerted::Parts::Sent objects. These objects describe how the user was alerted and at what time. See Bric::Util::Alerted::Parts::Sent for its interface.

    Throws:

    *   Bric::_get() - Problems retrieving fields.

    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 $addr = &$new($pkg, $init)
    Instantiates a new object. Used in place of new() by &$get_em(), since new isn't implemented for this class.

    Throws:

    *   Incorrect number of args to Bric::_set().

    *   Bric::set() - Problems setting fields.

    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