Bric::Util::Event(3)

NAME
Bric::Util::Event - Interface to Bricolage Events

VERSION
$LastChangedRevision$

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

SYNOPSIS
  # Constructors.
  my $event = Bric::Util::Event->new($init);
  my $event = Bric::Util::Event->lookup({id => $id});
  my @events = Bric::Util::Event->list(params)

  # Class Methods.
  my @eids = Bric::Util::Event->list_ids($params)

  # Instance Methods.
  my $id = $event->get_id;
  my $et = $event->get_event_type;
  my $et_id = $event->get_event_type_id;
  my $user = $event->get_user;
  my $user_id = $event->get_user_id;
  my $obj = $event->get_obj;
  my $obj_id = $event->get_obj_id;
  my $time = $event->get_timestamp;
  my $key_name = $event->get_key_name; # Same as returned by $et.
  my $name = $event->get_name;         # Same as returned by $et.
  my $desc = $event->get_description;  # Same as returned by $et.
  my $class = $event->get_class;       # Same as returned by $et.

DESCRIPTION
Bric::Util::Event provides an interface to individual Bricolage events. It is used primarily to create a list of events relative to a particular Bricolage object. Events can only be de logged for a pre-specified list of event types as defined by Bric::Util::EventType. In fact, I recommend that you use the log_event() method on an Bric::Util::EventType object to log individual events, rather than creating them here with the new() method. Either way, the event will be logged and all necessary alerts defined via the Bric::Util::AlertType class will be sent.

While the primary purpose of this class is to create lists of events, I have provided a number of methods to make it as flexible an API as possible. These include the ability to automatically instantiate the object for which an event was logged, or the Bric::Biz::Person::User object representing the user who triggered the event.

INTERFACE

  Constructors

my $event = Bric::Util::Event->new($init)
    Instantiates and saves a Bric::Util::Event object. Returns the new event object on success and undef on failure. An anonymous hash of initial values must be passed with the following keys:

    *   et - A Bric::Util::EventType object, which defines what type of event to log. If you happen to have already instantiated a Bric::Util::EventType object, use that object rather than its ID to avoid creating a second instantiation of the same object inernally.

    *   et_id - A Bric::Util::EventType object ID. May be passed instead of et. A Bric::Util::EventType object ID will be instantiated internally.

    *   name - A Bric::Util::EventType object name. May be passed instead of et or et_id. A Bric::Util::EventType object ID will be instantiated internally.

    *   obj - The object for which the event will be logged.

    *   user - The Bric::Biz::Person::User object representing the user who triggered the event.

    *   attr - An anonymous hash representing the attributes required to log the event. All must have values or they'll throw an error.

    *   timestamp - The event's time. Optional.

    Throws:

    *   No Bric::Util::EventType object, ID, or name passed to new().

    *   Too many Bric::Util::EventType 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.

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

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

    *   Bric::Util::Event::new() expects an object of type $class.

    *   No Bric::Biz::Person::User object passed to Bric::Util::Event::new().

    Side Effects: Creates the new event and saves it to the database.

    Notes: Use new() only to create a completely new event object. It will automatically be saved before returning the new event object. Use lookup() or list() to fetch pre-existing event objects.

    In the future, attributes may not need to be passed for all attribute logging. That is, if the attributes can be collected direct from the object of this event via accessors, they need not be passed in via this anonymous hash. The accessors must be named 'get_' plus the name of the attribute to be fetched (such as 'get_slug') in order for the method-call approach to collecting atrributes to work. But this is not yet implemented.

my $event = Bric::Util::Event->lookup({id => $id})
    Looks up and instantiates a new Bric::Util::Event object based on the Bric::Util::Event object ID. If the existing object is not found in the database, lookup() returns undef. If the ID or name is found more than once, lookup() returns zero (0). This should not happen.

    Throws:

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

    Notes: NONE.

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

    *   event_type_id

    *   user_id

    *   class_id

    *   class

    *   key_name

    *   name

    *   description

    *   obj_id

    *   timestamp

    If timestamp is passed as a scalar, events that occurred at that exact time will be returned. If it is passed as an anonymous hash, the first two values will be assumed to represent a range of dates between which to retrieve Bric::Util::Event objects. Any combination of the above keys may be used, although the most common may be a combination of class_id and obj_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::Event object with data from the database before returning them all.

    Notes: NONE.

$meths = Bric::Util::Event->my_meths
(@meths || $meths_aref) = Bric::Util::Event->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Util::Grp::Event->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.

  Destructors

$p->DESTROY
    Dummy method to prevent wasting time trying to AUTOLOAD DESTROY.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

  Public Class Methods

my (@eids || $eids_aref) = Bric::Biz::Person->list_ids($params)
    Functionally identical to list(), but returns Bric::Util::Event object IDs rather than objects. See list() for a description of its interface.

    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.

  Public Instance Methods

my $id = $event->get_id
    Returns the event object ID.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $et = $event->get_event_type
    Returns the event type object defining the event.

    Throws:

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

    *   Too many Bric::Util::EventType 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.

    *   Incorrect number of args to _set.

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

    Side Effects: NONE.

    Notes: NONE.

my $et_id = $event->get_event_type_id
    Returns the ID of the event type object defining the event.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $u = $event->get_user
    Returns the Bric::Biz::Person::User object representing the person who triggered the event.

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

    Notes: NONE.

my $uid = $event->get_user_id
    Returns the ID of the Bric::Biz::Person::User object representing the person who triggered the event.

    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 $obj = $event->get_obj
    Returns the object for which this event was logged. The class of the object may be fetched from $event->get_class.

    Throws:

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

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

    *   Incorrect number of args to _set.

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

    Side Effects: NONE.

    Notes: NONE.

my $obj_id = $event->get_obj_id
    Returns the ID of the object for which this event was logged. The class of the object may be fetched from $event->get_class.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $timestamp = $event->get_timestamp
    Returns the time at which the event was triggered.

    Throws:

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

    *   Unable to unpack date.

    *   Unable to format date.

    Side Effects: NONE.

    Notes: NONE.

my $key_name = $event->get_key_name
    Returns the event key name. Same as the key name specified for the event type defining this event.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $name = $event->get_name
    Returns the event name. Same as the name specified for the event type defining this event.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $description = $event->get_description
    Returns the event description. Same as the name specified for the event type defining this event.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $class = $event->get_class
    Returns name of the class of object for which the event was logged.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: NONE.

    Notes: NONE.

my $attr_href = $event->get_attr
    Returns an anonymous hash of the attributes of the event.

    Throws:

    *   Bad AUTOLOAD method format.

    *   Cannot AUTOLOAD private methods.

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

    *   No AUTOLOAD method.

    Side Effects: Uses Bric::Util::Attribute::Event internally.

    Notes: NONE.

$self = $event->has_alerts
    Returns true if alerts are associated with the event, and false if no alerts are associated with the event.

    Throws:

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

    Side Effects: NONE.

    Notes: NONE.

$self = $event->save;
    Dummy method for those who try to call save() without realizing that saving is automatic. Returns $self, but otherwise does noththing.

    Throws: NONE.

    Side Effects: NONE.

    Notes: NONE.

PRIVATE

  Private Class Methods
NONE.

  Private Instance Methods
NONE.

  Private Functions

my $events_aref = &$get_em( $pkg, $search_href )
my $events_ids_aref = &$get_em( $pkg, $search_href, 1 )
    Function used by lookup() and list() to return a list of Bric::Biz::Person objects or, if called with an optional third argument, returns a listof Bric::Biz::Person 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.

&$save($self)
    Saves the contents of an event.

    Throws:

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

    Side Effects: NONE.

    Notes: NONE.

&$save_attr($event_id, $et, $attr)
    Saves the attributes of an event.

    Throws:

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

    Side Effects: NONE.

    Notes: NONE.

&$get_et($self)
    Returns the Bric::Util::EventType object identifying the type of this Bric::Util::Event object.

    Throws:

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

    *   Too many Bric::Util::EventType 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.

    *   Incorrect number of args to _set.

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

    Side Effects: NONE.

    Notes: Uses Bric::Util::EventType->lookup() internally and caches the object.

NOTES
NONE.

AUTHOR
David Wheeler <david@wheeler.net>

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