Datamanager 2 Data Type base class.

As with all subclasses, the actual initialization is done in the initialize() function, not in the constructor, to allow for error handling.

Type configuration:

  • Now uses class members, which should use initializers (var $name = 'default_value';) for configuration defaults.
  • The schema configuration ('type_config') is merged using the semantics $type->$key = $value;
package midcom.helper.datamanager2

 Methods

_on_configuring (array $config)

This function, is called before the configuration keys are merged into the types configuration.

Parameters

$config

arrayThe configuration passed to the type.

_on_initialize ()

This event handler is called after construction, so passing references to $this to the outside is safe at this point.

Returns

booleanIndicating success, false will abort the type construction sequence.

_on_validate ()

Type-specific validation callback, this is executed before any custom validation rules which apply through the customization interface.

In case validation fails, you should assign an (already translated) error message to the validation_error public member.

Returns

booleanIndicating value validity.

can_do (string $privilege)

Checks whether the current user has the given privilege on the storage backend.

The storage backend is responsible for the actual execution of this operation, so this is merely a shortcut.

Parameters

$privilege

stringThe privilege to check against.

Returns

booleantrue if the user has the permission, false otherwise.

convert_from_csv (string $source)

Constructs the object based on its CSV representation (which is already decoded in terms of escaping.)

Parameters

$source

stringThe CSV representation that has to be parsed.

convert_from_storage (mixed $source)

Converts from storage format to "operational" format, which might include more information then the pure storage format.

Depending on the $serialized_storage member, the framework will automatically deal with deserialization of the information.

Parameters

$source

mixedThe storage data structure.

convert_to_csv ()

Transforms the current object's state into a CSV string representation.

Escaping and other encoding is done by the caller, you just return the string.

Returns

mixedThe data to store into the object, or null on failure.

convert_to_email ()

Transforms the current object's state into a email-friendly string representation.

Escaping and other encoding is done by the caller, you just return the string.

If this method is not overwritten, convert_to_csv will be used instead.

Returns

mixedThe data to store into the object, or null on failure.

convert_to_html ()

Transforms the current object's state into HTML representation.

This is used for displaying type contents in an automatic fashion.

Returns

mixedThe rendered content.

convert_to_raw ()

Transforms the current objects' state into 'raw' representation.

Usually the convert_to_storage -method returns suitable value, but in some datatypes (like privilege, blobs-based ones and tags), convert_to_storage does database IO directly and returns less useful data.

see \convert_to_storage

Returns

mixedThe rendered content.

convert_to_storage ()

Converts from "operational" format to from storage format.

Depending on the $serialized_storage member, the framework will automatically deal with deserialization of the information.

Returns

mixedThe data to store into the object, or null on failure.

get_external_config (string $key)

Gets an external configuration option referenced by its key.

Besides other parts in the datamanager framework, nobody should ever have to touch this information.

Parameters

$key

stringThe key by which this configuration option is referenced.

Returns

mixedThe configuration value, which is null if the key wasn't found.

initialize (string $name, array $config, \midcom_helper_datamanager2_storage $storage, \midcom_helper_datamanager2_datamanager $datamanager)

Initializes and configures the type.

Parameters

$name

stringThe name of the field to which this type is bound.

$config

arrayThe configuration data which should be used to customize the type.

$storage

\midcom_helper_datamanager2_storage&$storage A reference to the storage object to use.

$datamanager

\midcom_helper_datamanager2_datamanagerThe current DM2 instance

Returns

booleanIndicating success. If this is false, the type will be unusable.

initialize_option_callback ()

Prepares the option callback

Returns

\midcom_helper_datamanager2_callback_interfaceThe prepared callback object

set_external_config (string $key, mixed $value)

Sets an external configuration option.

Besides other parts in the datamanager framework, nobody should ever have to touch this information.

Parameters

$key

stringThe key by which this configuration option is referenced.

$value

mixedThe configuration value.

set_storage (\midcom_helper_datamanager2_storage $storage)

Small helper which sets the current storage object to a new one.

The object is used by-reference.

Parameters

$storage

\midcom_helper_datamanager2_storage&$storage A reference to the storage object to use.

translate (string $string)

This is a shortcut to the translate_schema_string function.
see \midcom_helper_datamanager2_schema::translate_schema_string()

Parameters

$string

stringThe string to be translated.

Returns

stringThe translated string.

validate ()

Main validation interface, currently only calls the main type callback, but this can be extended later by a configurable callback into the component.

Returns

booleanIndicating value validity.

 Properties

 

string $name

The name field holds the name of the field the datatype is encapsulating.

This maps to the schema's field name. You should never have to change them.

 

boolean $serialized_storage

Set this to true during one of the startup callbacks if you need to have the datastorage (de)serialized automatically during I/O operations.
 

\midcom_helper_datamanager2_storage $storage

A reference to the storage object that this type is using.

Use this for attachment management. The variable may be null until actual processing starts. It may also change during the lifetime of a type. You should therefore be careful.

access protected
 

string $validation_error

This field contains the reason for the failed validation.

The string can be safely assumed to be localized, and is only valid if a validation has failed previously. This field will be cleared prior to a new validation attempt. You may use simple inline HTML in these errors.

 

\midcom_helper_datamanager2_datamanager $_datamanager

Reference to the datamanager instance this type belongs to
 

Array $_external_config

This variable contains configuration data which is not directly related to the operation of the type, but required for the operation of external tools like the storage manager.

The type should never touch this variable, which is controlled by a corresponding getter/setter pair.

see \set_external_config()
see \get_external_config()