pkg('Contrib') - storage and retrieval of contributor data
# create new contributor object
my $contrib = pkg('Contrib')->new( prefix => 'Mr.',
first => 'Matthew',
middle => 'Charles',
last => 'Vella',
email => 'mvella@thepirtgroup.com',
phone => '111-222-3333',
bio => 'This is my bio.',
url => 'http://www.myurlhere.com' );
# add contributor types (lets pretend contrib_type 1 is 'Writer' and
# type 3 is 'Photographer')
$contrib->contrib_type_ids(1,3);
# save this contributor to the database
$contrib->save();
# now that it is saved we can get its id
my $contrib_id = $contrib->contrib_id();
# find this contributor by id
my @contribs = pkg('Contrib')->find( contrib_id => $contrib_id );
# list contributor type ids (will return 1,3)
@contrib_type_ids = $contribs[0]->contrib_type_ids();
# list contrib type names (will return 'Writer', 'Photographer');
@contrib_type_names = $contribs[0]->contrib_type_names();
# change contributor contrib type ids, effectively removing writer type (1)
$contribs[0]->contrib_type_ids(3);
# save contributor, making changes permanent
$contribs[0]->save();
# delete contributor
$contribs[0]->delete();
This class handles the storage and retrieval of contributor data to/from the database. Contributor type ids come from Krang::AdminPrefs (??), but are associated to contributors here.
new()new() suports the following name-value arguments:
contrib_id()save() is called the first time.
prefix()first()middle()last()suffix()email()phone()bio()url()full_name()full_name takes the form of: prefix() first() middle() last(), suffix()
image()selected_contrib_type()contrib_type_ids()contrib_type_names()save()Contributor names much be unique. Specifically, no two contributors many have the same
first, middle, and last name. If you attempt to save a duplicate contributor
$contrib->save() will throw an exception or type Krang::Contrib::DuplicateName.
This exception provides a contrib_id of the existing contributor who already has this name.
delete() || Krang::Media->delete($contrib_id)find($param)field(s) to order search by, defaults to last,first. Can pass in list.
order_desc - results will be in ascending order unless this is set to 1 (making them descending).
limit - limits result to number passed in here, else no limit.
offset - offset results by this number, else no offset.
ids_only - return only contrib_ids, not objects if this is set true.
count - return only a count if this is set to true. Cannot be used with ids_only.
$contrib->serialize_xml(writer => $writer, set => $set)$contrib = Krang::Contrib->deserialize_xml(xml => $xml, set => $set, no_update => 0)If an incoming contributor has the same first, middle and last name as
an existing contributor then deserialize_xml() will update the
contributor object rather than create a new one.