Name

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

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:

Throws:

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:

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 in reverse chronological order based on the search parameters passed via an anonymous hash. The supported lookup keys are:

id

Event ID. May use ANY for a list of possible values.

event_type_id

Event type ID. May use ANY for a list of possible values.

user_id

User ID for user who may have triggered events. May use ANY for a list of possible values.

class_id

ID of the class of object on which events have been logged. May use ANY for a list of possible values.

class

The package name of a class, the objects of which may have had events logged against them. May use ANY for a list of possible values.

key_name

Event type key name. May use ANY for a list of possible values.

name

Event name. May use ANY for a list of possible values.

description

Event description. May use ANY for a list of possible values.

obj_id

ID of a Bricolage object for which events may have been logged. May use ANY for a list of possible values.

timestamp

Time at which events have been logged.If passed as a scalar, events that occurred at that exact time will be returned. If passed as an anonymous array, the first two values will be assumed to represent a range of dates between which to retrieve Bric::Util::Event objects. May also use ANY for a list of possible values.

value

The value of an event attribute. May use ANY for a list of possible values.

Order

An attribute name to order by.

OrderDirection

The direction in which to order the records, either "ASC" for ascending (the default) or "DESC" for descending. This value is applied to the property specified by the Order parameter. Defaults to ascending.

Limit

A maximum number of objects to return. If not specified, all objects that match the query will be returned.

Offset

The number of objects to skip before listing the remaining objcts or the number of objects specified by Limit.

Throws:

Side Effects: NONE.

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:

Side Effects: NONE.

Notes: NONE.

Public Instance Methods

my $id = $event->get_id

Returns the event object ID.

Throws:

Side Effects: NONE.

Notes: NONE.

my $et = $event->get_event_type

Returns the event type object defining the event.

Throws:

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:

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:

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:

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:

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:

Side Effects: NONE.

Notes: NONE.

my $timestamp = $event->get_timestamp

Returns the time at which the event was triggered.

Throws:

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:

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:

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:

Side Effects: NONE.

Notes: NONE.

my $class = $event->get_class

Returns name of the class of object for which the event was logged.

Throws:

Side Effects: NONE.

Notes: NONE.

my $attr_href = $event->get_attr

Returns an anonymous hash of the attributes of the event.

Throws:

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:

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:

Side Effects: NONE.

Notes: NONE.

&$save($self)

Saves the contents of an event.

Throws:

Side Effects: NONE.

Notes: NONE.

&$save_attr($event_id, $et, $attr)

Saves the attributes of an event.

Throws:

Side Effects: NONE.

Notes: NONE.

&$get_et($self)

Returns the Bric::Util::EventType object identifying the type of this Bric::Util::Event object.

Throws:

Side Effects: NONE.

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

Notes

NONE.

Author

David Wheeler <david@justatheory.com>

See Also

Bric, Bric::Util::EventType, Bric::Util::AlertType, Bric::Util::Alert