Datamanager 2 Data Manager core class.

This class controls all type I/O operations, including entering and exiting editing operations and creation support. It brings Types, Schemas and Storage objects together.

package midcom.helper.datamanager2

 Methods

__construct (array $schemadb)

The constructor loads the schema database to use but does nothing else so far.
see \midcom_helper_datamanager2_schema::load_database()

Parameters

$schemadb

array&$schemadb A list of midcom_helper_datamanager2_schema instances, indexed by their schema name. This member is taken by reference.

_schema_field_is_broken (string $name)

Very basic schema sanity checking, raises messages as needed

Parameters

$name

stringfield name

Returns

booleanindicating b0rkedness

autoset_storage (mixed $object, boolean $strict)

This function is a shortcut that combines set_schema and set_storage together.

The schema name is looked up in the parameter 'midcom.helper.datamanager2/schema_name', if it is not found, the first schema from the schema database is used implicitly.

see \set_schema()
see \set_storage()

Parameters

$object

mixed&$object A reference to either a MidCOM DBA class or a subclass of midcom_helper_datamanager2_storage.

$strict

booleanWhether we should strictly use only the schema given by object params

Returns

booleanIndicating success.

display_view (boolean $skip_empty)

This function displays a quick view of the record, using some simple div based layout, which can be formatted using CSS.

Be aware that this is only geared for simple administration interfaces, it will provide no editing capabilities (like AJAX) etc. If you want that to work, you need a formmanger instance instead.

Parameters

$skip_empty

booleanShould empty fields be rendered or not

get_content_csv ()

Little helper function returning an associative array of all field values converted to CSV using their default convert_to_csv option.

Returns

ArrayAll field values in their CSV representation indexed by their name.

get_content_email ()

Little helper function returning an associative array of all field values converted to email-friendly format using their default convert_to_email option.

Returns

ArrayAll field values in their CSV representation indexed by their name.

get_content_html ()

Little helper function returning an associative array of all field values converted to HTML using their default convert_to_html option.

Returns

ArrayAll field values in their HTML representation indexed by their name.

get_content_raw ()

Little helper function returning an associative array of all field values converted to their raw storage representation.

.

Returns

ArrayAll field values in their raw storage representation indexed by their name.

get_content_xml ()

Little helper function returning an associative array of all field values converted to XML using their default convert_to_csv or convert_to_raw options.

Returns

ArrayAll field values in their XML representation indexed by their name.

recreate ()

This function will cycle through all fields of the loaded schema, and run a "recreate" method for the type, if it has one.

This can be used for regenerating all images or converted files of a given object when for instance schema changes.

Returns

boolean

save ()

This function will save the current state of all types to disk.

A full validation cycle is done beforehand, if any validation fails, the function aborts and sets the $validation_errors member variable accordingly.

Returns

booleanIndicating success

set_schema (string $name)

This function activates the given schema.

This will drop all existing types and create a new set of them which are in the default state at this point.

This will reset the existing schema and type listing. If a storage object exists, the change of the schema will be propagated implicitly, as it will reference the schema member of ours.

Parameters

$name

stringThe name of the schema to use, omit this to use the default schema.

Returns

booleanIndicating success.

set_storage (mixed $object)

This function sets the system to use a specific storage object.

You can pass either a MidCOM DBA object or a fully initialized storage subclass. The former is automatically wrapped in a midcom storage object. If you pass your own storage object, ensure that it uses the same schema as this class. Ideally, you should use references for this.

This call will fail if there is no schema set. All types will be set and initialized to the new storage object. Thus, it is possible to call set_storage repeatedly thus switching an existing DM instance over to a new storage object as long as you work with the same schema.

Parameters

$object

mixed&$object A reference to either a MidCOM DBA class or a subclass of midcom_helper_datamanager2_storage.

Returns

booleanIndicating success.

validate ()

Validate the current object state.

It will populate $validation_errors accordingly.

Returns

booleanIndicating validation success.

_load_type ($name)

Parameters

$name

_load_types ()

This function will create all type objects for the current schema.

It will load class files where necessary (using require_once), and then create a set of instances based on the schema.

Returns

booleanIndicating success

 Properties

 

\midcom_helper_datamanager2_formmanager $formmanager

Reference to the form manager instance which is currently in use.

Usually, it is created and referenced here by the controller class during initialization.

 

\midcom_helper_datamanager2_schema $schema

This variable holds the schema currently in use, it has been created from the array stored in the $_schemadb member.

This object can be modified as long as the types are not initialized. If you change the schema afterwards, the changes will not propagate to any dependant object until you reinitialize the class.

 

string $schema_name

The id (array index) of the current schema
 

\midcom_helper_datamanager2_storage $storage

This is the storage implementation which is used for operation on the types.

It encapsulates the storage target.

 

Array $types

This is a listing of all types that have been loaded from the storage object.

You may manipulate these types and their values at will, and then store them back to the database using the functions available in this class.

 

Array $validation_errors

This variable contains an Array of all validation errors that have occurred during saving.

As outlined in the type, these messages my have inline-html in it and it is assumed to be localized.

The errors are indexed by field name.

see \midcom_helper_datamanager2_type::$validation_error
 

Array $_schemadb

The schema database to use for operation.

This variable will always contain a parsed representation of the schema, so that one can swiftly switch between individual schemas of the Database. This is a list of midcom_helper_datamanager2_schema instances, indexed by their name.