Newsletterdeveloper's documentation

dbo Class Reference
[DBO Core API]

Base DBO class. More...

List of all members.

Basic DBO properties and methods

 $id
 [int|null] DBO ID (same as in DB).
 $def
 [dbo_def] DBO definition object.
 __construct ($no_session=false)
 Constructor.
 remove ()
 Mark DBO for removal on next commit.
 changed ()
 Check if DBO attributes differ from stored state.
 dump ($level=2, $prefix= '')
 Dump DBO data.
static get ()
 Get single DBO from DB by ID or SQL query.
static query ()
 Get multiple DBOs from DB using SQL query.

Advanced DBO methods

 attr_get ($name)
 Get current value of attribute.
 attr_set ($name, $value)
 Set attribute.
 attr_init ($name, $value)
 Initialize attribute.
 attr_reset ($name)
 Reset attribute to its original value.
 attr_isset ($name)
 Check if current value of attribute differs from its origianl value.
 attr_add_message ($name, $message)
 Associate error message with particular attribute.
 attr_get_messages ($name)
 Get array of messages associated with given attribute.
 add_message ($message)
 Associate message with whole entity.
 get_messages ()
 Get array of messages associated with whole entity.
 has_messages ()
 Check if entity, its attributes or bags have associated any messages with it.
 reset_messages ()
 Remove all messages.
 attr_check (dbo_attr_def $def)
 Check single attribute value.
 attr_check_custom (dbo_attr_def $def, $value)
 Override this method to implement custom attribute validity checks.
 check ()
 Check validity of attributes and bag constraints.
 hook ($name)
 Hook for various situations.


Detailed Description

Base DBO class.

This class implements basic DBO functionality:


Constructor & Destructor Documentation

dbo::__construct ( no_session = false  ) 

Constructor.

Initialize bags, attrs.

Parameters:
no_session [boolean] Whether to put new DBO into session or not.

Reimplemented in news_item, news_subscriber, and news_category.

References dbo_manager::get_session(), and hook().


Member Function Documentation

dbo::add_message ( message  ) 

Associate message with whole entity.

Parameters:
message [string] Message text.

dbo::attr_add_message ( name,
message 
)

Associate error message with particular attribute.

Parameters:
name [string] Attribute name.
message [string] Message text.

dbo::attr_check ( dbo_attr_def def  ) 

Check single attribute value.

Parameters:
def [dbo_attr_def] Attribute definition.
Returns:
[boolean] True if attribute is ok, false if attribute is invalid, null if undecided.

dbo::attr_check_custom ( dbo_attr_def def,
value 
)

Override this method to implement custom attribute validity checks.

Parameters:
def [dbo_attr_def] Attribute definition.
value [mixed] Attribute value.
Returns:
[boolean|null] Return null if undecided, return true if valid, return false if invalid. If you return null, standard attribute validity checks will be performed.

dbo::attr_get ( name  ) 

Get current value of attribute.

Parameters:
name [string] Attribute name.
Returns:
[any] Attribute value.

Referenced by dump().

dbo::attr_get_messages ( name  ) 

Get array of messages associated with given attribute.

Parameters:
name [string] Attribute name.
Returns:
[array(string)] Array of messages.

Referenced by dump().

dbo::attr_init ( name,
value 
)

Initialize attribute.

This will set current and original attribute values.

Parameters:
name [string] Attribute name.
value [any] Attribute value.

dbo::attr_isset ( name  ) 

Check if current value of attribute differs from its origianl value.

Parameters:
name [string] Attribute name.
Returns:
[boolean] True if differs.

Referenced by changed().

dbo::attr_reset ( name  ) 

Reset attribute to its original value.

Parameters:
name [string] Attribute name.

dbo::attr_set ( name,
value 
)

Set attribute.

Parameters:
name [string] Attribute name.
value [mixed] Attribute value.

dbo::changed (  ) 

Check if DBO attributes differ from stored state.

Returns:
[boolean] TRUE if DBO differs from stored state.

References attr_isset().

dbo::check (  ) 

Check validity of attributes and bag constraints.

This method has side effect of setting messages on attributes, whole DBO and bags. You should call reset_messages() before calling this method.

Returns:
[boolean] True if everything is ok.

dbo::dump ( level = 2,
prefix = '' 
)

Dump DBO data.

Parameters:
level [int] Maximum depth of dump (prevents recursion, limits useless output).
prefix [string] For internal use. (dump lines prefix)
Returns:
[string] DBO data string representation.

References attr_get(), attr_get_messages(), and get_messages().

static dbo::get (  )  [static]

Get single DBO from DB by ID or SQL query.

This method can be used to get single object from database. You can call it in following ways:

  • type::get(1) - get object with given ID
  • type::get("WHERE x = ?", 'val') - get object by condition
  • type::get(array('type_id' => 1, '' ...)) - get object from array
Last method of calling is only used internally as an optimization in dbo::_query().

If DBO was already instantiated in active session, instance from the session will be returned. Thus you can never end up with multiple instances of DBO refering to same row in DB in one session.

Returns:
[dbo] DBO.

Reimplemented in news_item, news_subscriber, and news_category.

References $def, and dbo_manager::get_session().

Referenced by query().

dbo::get_messages (  ) 

Get array of messages associated with whole entity.

Returns:
[array(string)] Array of messages.

Referenced by dump().

dbo::has_messages (  ) 

Check if entity, its attributes or bags have associated any messages with it.

Returns:
[boolean] True if some messages exist.

dbo::hook ( name  ) 

Hook for various situations.

Override this method to implement custom actions for following situations:

  • construct - after construction (new or existing DBO)
  • check - before checking all attributes
  • check-attr - check attribute
  • pre-commit - before commit
  • post-commit - after commit
  • remove - on first call to remove()
  • ll-pre-delete - lowlevel db hook, before DELETE
  • ll-post-delete - lowlevel db hook, after DELETE
  • ll-pre-insert - lowlevel db hook, before INSERT
  • ll-post-insert - lowlevel db hook, after INSERT
  • ll-pre-update - lowlevel db hook, before UPDATE
  • ll-post-update - lowlevel db hook, after UPDATE
Parameters:
name [string] Hook name.

Referenced by __construct(), and remove().

static dbo::query (  )  [static]

Get multiple DBOs from DB using SQL query.

This method can be used to query array of objects from database. You can call it in following ways:

  • type::query() - all objects of given type
  • type::query("WHERE x = ?", 'val') - all objects that match condition
Returns:
[array(dbo)] Array of DBOs.

References $def, and get().

dbo::remove (  ) 

Mark DBO for removal on next commit.

This will also mark all DBOs owned by this DBO.

References hook().

dbo::reset_messages (  ) 

Remove all messages.


Member Data Documentation

dbo::$def

[dbo_def] DBO definition object.

Referenced by get(), and query().

dbo::$id

[int|null] DBO ID (same as in DB).

Null for DBOs not yet in DB.


The documentation for this class was generated from the following file:
Documentation for Newsletter, Tue Nov 11 07:50:02 2008.