Developers > Kernel Documentation > Data Handling > Object.pm

Object.pm


ExSite::Object

Generic, multi-purpse CMS objects are data objects that an end-user can be expected to create, edit, delete, and display in reports of one kind or another. This class defines a useful set of core behaviours for objects that fit this description.

This class can be inherited by specialized objects that can override the core beheviours to specify custom forms, reports, data handling, etc.

Attributes

Each Object has two important attributes, type and id. In the generic Object, these are taken to be a table name and record ID, and are used as an ``address'' to look up the data, and also as raw material for composing a name (label) for the object. The type can be treated as a pseudo-class, since two objects of different types will have slightly different behaviours, as specified by the lower-level database record handling tools.

Each Object has a data attribute, consisting of the actual database record that the Object represents. This data is only loaded when needed. You can pass an actual datahash in when instantiating the record, if you have already loaded it another way.


Methods

new(%opt)

Instantiate a new object; the type and id can be passed in the %opt hash.

setup($type,$id)

Transform the object so that it represents a different record.

type()

Returns the object's type (by default, it's table).

id($id)

Returns the object's ID. An object normally only has an ID if it was fetched from the database. An object that has data, but no ID, is a working object that must be saved for it to be asigned an ID.

name()

Returns a human-friendly description of the object.

ok()

Returns true if the object's type and ID are defined.

key()

Returns the name of the key in the objects datahash that looks up the objects ID.

get($attr)

Returns the value of the named attribute (eg. type, id, data, ...); if no attribute name is given, returns the Object's datahash.

getdata($key)

Returns the value of the named key in the object's datahash.

setdata($key,$val)

Sets the value of the named key in the object's datahash. Only sets the value in the object; to make this change permanent, the object must be saved.

showdata($key)

Formats the value of the named key in the object's datahash as HTML. Also performs access-control checks to ensure the user is permitted to view the data.

dirty()

Returns true (1) if the object's data has been modified and is out of sync with the saved data. Returns false (0) if the object matches the saved data.

show()

Formats the entire Object as an HTML report.

load($data)

Fetches the Object's data. If $data is passed, it is used as the object's datahash; otherwise, the data is fetched from the database.

insert(%data)

Creates a new record, using %data. If no data is passed, the Object's datahash is used.

update(%data)

Updates an existing record, using %data. If no data is passed, the Object's datahash is used.

save()

Writes the objects datahash out to the database, using either the insert() or update() method, as appropriate.

delete()

Moves the record represented by the Object to the trash.

copy()

Creates a new record that is a copy of the record represented by the Object (except for the record ID).

make()

Generates an HTML form that allows the user to enter data for a new object/record.

edit()

Generates an HTML form that allows the user to edit the data of the current Object.

do_make()

Process the form generated by make().

do_edit()

Process the form generated by edit().

Topics