mRFC 0029: MidgardCollector
- Revision history
- Background
- Implementation details
- Data retrieving
- Data overwriting
- Methods
- Examples
Revision history
- 2006-05-18 Created by Piotr Pokora
- 2006-05-18 Added use case examples by Piotr Pokora
- 2006-06-14 Constraint specifications and returned data changes by Piotr Pokora
Background
The main idea of MidgardCollector type is code , resources and data reusability for all data values which are not objects itself and as part of any object could be retrieved from Midgard database without any need to retrieve full objects' records. MidgardCollector is special limited resource data handler and is optimized for performance and data accessibility. The most important approach is to reuse the same functionality for Midgard features like style engine, objects' parameters and object's attachments.
However MidgardCollector should be usable for any Midgard type defined for Midgard application.
Implementation details
MidgardCollector should be implemented as MidgardQueryBuilder wrapper with extended constraints management and extended caching possibilities. Following Midgard objects parameters' convention , MidgardCollector should use 3 constraints to query records drom database:
- domain
- property name and its value to limit selected records
- name
- property name ( and optionally its value ) to limit selected records
- property name which value should be returned as part of a result
- value
- property name which value should be returned as part of a result
Additionally another type should be settable as a parent of the type already initialized for MidgardCollector. In such case type initialized for MidgardCollector should have defined reserved database storage columns not accesible by application. Column names should be prefixed with 'midgard_' namespace like word.
Data retrieving
MidgardCollector should be initialized only for one particular type. This type's property names should be set as domain , name and value constraints.
Returned type should be an hash array with collector's name assigned as key and value as key's value. Additionally guid of an record should be assigned as another array key.
name -
|-value -> variable
|-guid -> variable
These hash array should be always set as returned resultset and number of returned records should be limited by domain's value and optionally by name's value. Additionally MidgardQueryBuilder methods like limit or add_constraint or add_order could be used to limit or to order selected records. Parent type assigned to MidgardCollector should be also used to limit selected records , limiting returned results by its type name and guid.
Returned array should be available during the whole application's runtime unless explicitly destroyed by application. If and when returned object should be destroyed depends on application's implementation and its not part of this mRFC.
Data overwriting
MidgardCollector should be able to overwrite data in existing array by destroying already existing key value pair and replacing it with new name and value. Such overwrite should be done with existing collector's instance , without any need to create new instance of object.
Methods
MidgardCollector should have implemented methods which allow:
- Set domain and its value
- Set name its value
- Get resultset by domain
- Get resultset by domain and name
- Get resultset limited to parent type
- Destroy name and value
- Destroy the whole collection
- Overwrite value for existing name
Examples
Style elements
Select all style elements' values and render one of them:
$mc = new midgard_collector("midgard_element");
$mc->add_domain("style", $_MIDGARD->page);
$mc->add_name("name");
$mc->add_value("value");
$mc->execute();
$style_engine->render($mc->resultset['ROOT']);
Parameters
Select paremeters by domain, update parameter and collector.
$mc = new midgard_collector("midgard_parameter");
$mc->add_domain("domain", "midcom");
$mc->add_name("name");
$mc->add_value("value");
$mc->add_parent_type("midgard_topic");
$mc->add_parent_guid("fkj34h68d3f1js0du347fh4j4df");
$mc->execute();
$component = $mc->resultset['component'];
/* update parameter */
$topic = new midgard_topic("fkj34h68d3f1js0du347fh4j4df");
$topic->paramater("midcom", "component", "net.nehmer.static");
$mc->add("component", "net.nehmer.static");
$component = $mc->resultset['component'];
Attachments
Select only image/jpg attachments.
$mc = new midgard_collector("midgard_blob");
$mc->add_domain("mimetype", "image/jpg");
$mc->add_name("name");
$mc->add_value("content");
$mc->add_parent_type("midgard_article");
$mc->add_parent_guid("fkj34h68d3f1js0du347fh4j4df");
$mc->execute();
$retval = $mc->resultset;
