NAME

Bric::Biz::Keyword - A general class to manage keywords.

VERSION

$Revision: 1.15.4.4 $

DATE

$Date: 2003/08/14 22:04:06 $

SYNOPSIS

use Bric::Biz::Keyword;

# Create a new keyword object.
my $key = new Bric::Biz::Keyword($init);

# Lookup an existing keyword.
my $key = new Bric::Biz::Keyword($key_id);

# Create a list of keyword objects.
my $key = list Bric::Biz::Keyword($param);

# Get/set the keyword name.
$name    = $key->get_name();
$success = $key->set_name($name);

# Get/set the screen (display) name.
$screen  = $key->get_screen_name();
$success = $key->set_screen_name($screen);

# Mark this keyword inactive
$success = $key->delete();

# Save this asset to the database.
$success = $key->save();

# Link a keyword with a story (or media object or category)
$key->associate($story);

# Break the link between a keyword and a story (or media object or category)a
$key->dissociate($story);

DESCRIPTION

The Keyword module allows assets to be characterized by a set of topical keywords. These keywords can be used to group assets or during a search on a particular topic.

INTERFACE

Constructors

$obj = Bric::Biz::Keyword->new(\%init);

Creates a new keyword and keyword object. Keys for %init are:

name

The name of this keyword - required.

screen_name

The way this name should be displayed on screen (ie name='George', screen name='George Washington'). If not specified name will be used for screen_name.

sort_name

The word used to sort keywords. If not specified then name will be used for sort_name.

Throws: NONE

Side Effects: NONE

Notes: NONE

$obj = Bric::Biz::Keyword->lookup({ id => $key_id });
$obj = Bric::Biz::Keyword->lookup({ name => "key name" });

Retrieves a single existing keyword from the database. Takes either a keyword ID or the keyword name.

Throws:

Side Effects: NONE

Notes: NONE

@objs = list Bric::Biz::Keyword($param);

Searches for keywords returning matches ordered by sort_name. The possible keys to $param are the following;

name

Search for keywords by name. Matched with LIKE.

screen_name

Search for keywords by screen name. Matched with LIKE.

sort_name

Search for keywords by sort name. Matched with LIKE.

active

Search for keywords by active flag. If you don't set this flag then active => 1 is implicitely used.

synonyms

Returns all the synonyms for the given keyword or keyword ID. Cannot be legally combined with the object param.

object

Returns all keywords for a given object - may be a Bric::Biz::Category, Bric::Biz::Asse::Business::Media or a Bric::Biz::Asse::Business::Story object. Cannot be legally combined with the synonyms param.

Throws:

Side Effects: NONE

Notes: NONE

$success = $key->delete;

Marks a keyword inactive in the database. Equivalent to calling set_active(0).

Throws: NONE

Side Effects: NONE

Notes: NONE

Public Class Methods

$meths = Bric::Biz::Keyword->my_meths
(@meths || $meths_aref) = Bric::Biz::Keyword->my_meths(TRUE)
my (@meths || $meths_aref) = Bric::Biz::Keyword->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

$key->associate($obj)

Associates a keyword with an object. The object must by of a type that supports keywords - currently Bric::Biz::Asset::Business::Story, Bric::Biz::Asset:::Business::Media and Bric::Biz::Category. This call commits the change directly to the database. There is no need to call save() afterward.

Returns 0 if $key is already associated with $obj, 1 if a new relationship was created.

Throws:

Side Effects: NONE

Notes: Cannot be called on an unsaved keyword. Call save() first.

$key->dissociate($obj)

Dissociates a keyword from an object. The object must by of a type that supports keywords - currently Bric::Biz::Asset::Business::Story, Bric::Biz::Asset:::Business::Media and Bric::Biz::Category. This call commits the change directly to the database. There is no need to call save() afterward.

Returns 0 if $key is not associated with $obj, 1 if the relationship was successfully removed.

Throws:

Unsupported object type : $ref.

Side Effects: NONE

Notes: Cannot be called on an unsaved keyword. Call save() first.

$name = $key->get_name();

Returns the name of this keyword

Throws: NONE

Side Effects: NONE

Notes: NONE

$name = $key->set_name($name);

Sets the name of this keyword

Throws: NONE

Side Effects: NONE

Notes: NONE

$name = $key->get_screen_name();

Returns the screen name of this keyword. The screen name is how the synonym should be displayed on screen (i.e. name='george' screen_name='Washington, George')

Throws: NONE

Side Effects: NONE

Notes: NONE

$name = $key->set_screen_name($name);

Sets the screen name of this keyword.

Throws: NONE

Side Effects: NONE

Notes: NONE

$state = $key->get_state();

Deprecated alias for get_active().

Throws: NONE

Side Effects: NONE

Notes: NONE

$state = $key->set_state();

Deprecated alias for set_active().

Throws: NONE

Side Effects: NONE

Notes: NONE

$success = $key->save;

Save the keyword to the database.

Throws:

"Unable to save";

Side Effects:

Will give default values to screen_name and sort_name if they are not set.

Notes: NONE

Private Methods

Private Class Methods

NONE

Private Instance Methods

$keywords = _select_keywords($where, $bind)
@keywords = _select_keywords($where, $bind)

Selects keywords from the database given an SQL where clause and a ref to an array of bind parameters. Returns fully constructed Bric::Biz::Keyword objects.

$self->_update_keyword()

Updates the keyword object in the database.

$self->_insert_keyword()

Inserts the new keyword object into the database.

($table, $field) = _get_db_data_for_object($obj)

Returns the correct relationship table and field name for a given supported object. For example, for a story object it returns ("story_keyword", "story_id").

Throws:

Unsupported object type : $ref.

Side Effects: NONE

Notes: NONE

NOTES

NONE

AUTHOR

"Garth Webb" <garth@perijove.com> Bricolage Engineering

Sam Tregar <stregar@about-inc.com>

SEE ALSO

Bric