\org_openpsa_mypage_interface

OpenPSA Personal Summary component

The class uses an event based approach for subclasses to influence the default behavior.

The actual implementation should be enough for most smaller components, as the class's behavior is widely configurable. You should not override any of the base class's interface methods if you can avoid it. If you find that an event handler is missing, please contact the MidCOM development team for some advice.

Quick start

This class does a lot of things automatically for you, described below. If you are not interested in the gory details though, here is a quick list of what you have to know (but don't complain if I have missed anything), and do these things after calling the base class constructor:

  • Inherit the class as {$component}_interface (e.g. net_nehmer_static_interface).
  • Prepare a component manifest for your component, see the class midcom_core_manifest for details.
  • You can change the values of all public members, the defaults should be suitable for most cases.
  • The component's data storage area will contain two keys when the initialized event handler is called: The NAP active id, defaulting to false and stored as active_leaf and the component's default configuration, stored as a midcom_helper_configuration object in the key config.
  • Put your component-wide default configuration into $component_dir/config/config.inc.

Class parameters

The following options can be used to parametrize the component's startup and operation. See the individual member documentation for now.

  • $_nap_class_suffix
  • $_site_class_suffix

Class operation

This class now does an awful lot of work for you, you just need to configure it to have the right names and places to look for. It is designed to fit in the current component wildlife with as little collateral damage as possible, but as always, a 100% transparent implementation is neither wanted nor sensible.

Actually, you should not need to overwrite any event handler for almost all components I currently know of. Ultimately, this is a proxy class to the actual component code. Its main goals are to automate these tasks:

  • Component startup (loading of the right script files and libraries)
  • Default configuration (loading of the various configuration files, see the _load_configuration() method for details)
  • Component data storage initialization
  • Context separation during runtime

Example usage

The average component will require something like this, part one is the component manifest:

'name' => 'net.nehmer.static', 'purecode' => false, 'version' => 1, 'privileges' => Array ( 'read' => MIDCOM_PRIVILEGE_ALLOW, 'write' => [MIDCOM_PRIVILEGE_DENY, MIDCOM_PRIVILEGE_ALLOW] ), 'class_mapping' => ['mgdschema_classname' => 'midcom_classname'],

See the class midcom_core_manifest for further details.

Built on this, we add the following interface class:

class net_nehmer_static_interface extends midcom_baseclasses_components_interface { public function _on_reindex($topic, $config, &$indexer) { $qb = midcom::get()->dbfactory->new_query_builder('midcom_db_article'); $qb->add_constraint('topic', '=', $topic->id); $articles = $qb->execute();

    $datamanager = datamanager::from_schemadb($config->get('schemadb'));

    foreach ($articles as $article) {
        try {
            $datamanager->set_storage($article);
        } catch (midcom_error $e) {
            $e->log();
            continue;
        }

        $document = $indexer->new_document($datamanager);
        $document->topic_guid = $topic->guid;
        $document->topic_url = $node[MIDCOM_NAV_FULLURL];
        $document->read_metadata_from_object($datamanager->storage->object);
        $document->component = $topic->component;
        $indexer->index($document);
    }
}

}

Summary

Methods
Properties
Constants
initialize()
configure()
can_handle()
handle()
show_content()
set_object()
get_node()
get_leaves()
get_current_leaf()
reindex()
get_config_for_topic()
trigger_watch()
_on_watched_operation()
_on_watched_dba_create()
_on_watched_dba_update()
_on_watched_dba_delete()
_on_watched_dba_import()
_on_reindex()
__construct()
__get()
__isset()
set_active_leaf()
add_stylesheet()
get_workflow()
$_context_data
$_component
$_i18n
$_l10n
$_l10n_midcom
$_config
No constants found
No protected methods found
$_nap_class_suffix
$_site_class_suffix
N/A
_check_nap_instance()
$_nap_instance
$_services
N/A

Properties

$_context_data

$_context_data : 

This variable holds the context-specific data during processing.

It is indexed first by context ID and second by a string key. Currently defined keys are:

  • config holds the configuration for this context
  • handler The class handling the request.

Type

$_component

$_component : string

The name of the component, e.g. net.nehmer.static. Should be used whenever the component's name is required instead of hardcoding it.

Type

string

$_i18n

$_i18n : \midcom_services_i18n

A handle to the i18n service.

Type

\midcom_services_i18n

$_l10n

$_l10n : \midcom_services_i18n_l10n

The components' L10n string database.

Type

\midcom_services_i18n_l10n

$_l10n_midcom

$_l10n_midcom : \midcom_services_i18n_l10n

The global MidCOM string database.

Type

\midcom_services_i18n_l10n

$_config

$_config : \midcom_helper_configuration

The current configuration.

Type

\midcom_helper_configuration

$_nap_class_suffix

$_nap_class_suffix : string

Class suffix used when constructing the NAP handler class.

It is appended to the component class prefix, f.x. resulting in net_nehmer_static_navigation (as a default).

Type

string

$_site_class_suffix

$_site_class_suffix : string

Class suffix used when constructing the on-site handler class.

It is appended to the component class prefix, f.x. resulting in net_nehmer_static_viewer (as a default).

Type

string

$_services

$_services : array

Array that holds the already instantiated services

Type

array

Methods

initialize()

initialize(  $component) 

Initializes the component.

Parameters

$component

configure()

configure(mixed  $configuration, integer  $contextid) 

Configures the component for usage. The configuration is merged, and, if necessary, an existing handler object is purged.

Parameters

mixed $configuration

A configuration data list, suitable for merging with a midcom_helper_configuration object.

integer $contextid

The ID of the context we are associated with.

can_handle()

can_handle(\midcom_db_topic  $current_object, \Symfony\Component\HttpFoundation\Request  $request, integer  $contextid) : boolean

Relays the can_handle call to the component, instantiating a new site class. It will execute can_handle of that class, returning its result to MidCOM.

Parameters

\midcom_db_topic $current_object

The topic in question.

\Symfony\Component\HttpFoundation\Request $request
integer $contextid

The id of the context we are operating in.

Returns

boolean —

True, if the component can handle the request, false otherwise.

handle()

handle() : \midcom_response|boolean

Relays the handle call to the component.

Returns

\midcom_response|boolean —

True, if the component successfully handle the request, false otherwise.

show_content()

show_content(integer  $contextid) 

Relays the show content call to the component, invoking output.

Parameters

integer $contextid

The id of the context we are operating in.

set_object()

set_object(\midcom_db_topic  $object) : boolean

Relays the set_object call to the nap instance. Checks if the NAP instance has already been created beforehand.

Parameters

\midcom_db_topic $object

The midcom_db_topic that should be processed.

Returns

boolean —

Indicating success.

get_node()

get_node() : Array

Relays the get_node call to the NAP instance.

Returns

Array —

A NAP compliant NODE structure.

get_leaves()

get_leaves() : Array

Relays the get_leaves call to the NAP instance.

Returns

Array —

An Array of NAP compliant leaf structures.

get_current_leaf()

get_current_leaf() : integer

Returns the currently selected leaf of the request.

Returns

integer —

The active leaf ID out of the component data storage.

reindex()

reindex(\midcom_db_topic  $topic) : boolean

Initiate a reindex run for the given component and topic.

Parameters

\midcom_db_topic $topic

The topic that should be reindexed.

Returns

boolean —

Indicating success.

get_config_for_topic()

get_config_for_topic(\midcom_db_topic  $topic = null) : \midcom_helper_configuration

Get the full configuration set active for a given topic.

If no topic is passed, the system wide default configuration is returned.

Be aware, that this call does not check if the passed topic is actually handled by this component, as it is theoretically possible for components to drop configuration information on other topics as well.

Parameters

\midcom_db_topic $topic

The topic which should be queried, omit to get the systemwide defaults.

Returns

\midcom_helper_configuration

MidCOM configuration object

trigger_watch()

trigger_watch(integer  $operation, \midcom_core_dbaobject  $object) 

Delegate all watched operations, in two phases. First, the general _on_watched_operation handler is called, to allow for handling generic operations. After that, the individual watches are called, to allow for more specific processing.

Parameters

integer $operation

The operation that has occurred.

\midcom_core_dbaobject $object

The object on which the operation occurred. The system will do is_a checks against any registered class restriction on the watch.

_on_watched_operation()

_on_watched_operation(integer  $operation, \midcom_core_dbaobject  $object) 

This function is triggered at the end of the request for each watched operation that has been done during the request.

It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.

Parameters

integer $operation

The operation identifier (one of the MIDCOM_OPERATION constants) which applies.

\midcom_core_dbaobject $object

The object on which the operation has occurred.

_on_watched_dba_create()

_on_watched_dba_create(\midcom_core_dbaobject  $object) 

This function is triggered at the end of the request for each watched create operation that has been done during the request.

It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.

It is called after the generic _on_watched_operation event handler.

Parameters

\midcom_core_dbaobject $object

The object on which the operation has occurred.

_on_watched_dba_update()

_on_watched_dba_update(\midcom_core_dbaobject  $object) 

This function is triggered at the end of the request for each watched update operation that has been done during the request.

It will be called once per operation and unique object, where object uniqueness is determined by the combination of object class and guid. The object has been refreshed before being passed to this event handler.

It is called after the generic _on_watched_operation event handler.

Parameters

\midcom_core_dbaobject $object

The object on which the operation has occurred.

_on_watched_dba_delete()

_on_watched_dba_delete(\midcom_core_dbaobject  $object) 

This function is triggered at the end of the request for each watched delete operation that has been done during the request.

It is called after the generic _on_watched_operation event handler.

Parameters

\midcom_core_dbaobject $object

The object on which the operation has occurred.

_on_watched_dba_import()

_on_watched_dba_import(object  $object) 

This function is triggered at the end of the request for each watched import operation that has been done during the request.

It is called after the generic _on_watched_operation event handler.

Parameters

object $object

The object on which the operation has occurred.

_on_reindex()

_on_reindex(\midcom_db_topic  $topic, \midcom_helper_configuration  $config,   $indexer) : boolean

Reindex the given topic. The complete configuration set is already available in $config. The original index records are already deleted, so you do not need to bother about this.

The default event handler does nothing.

Parameters

\midcom_db_topic $topic

The topic to reindex.

\midcom_helper_configuration $config

The configuration associated with this topic.

$indexer

Returns

boolean —

Indicating success.

__construct()

__construct() 

Initialize all member variables, remember to set $_component before calling this constructor from your derived classes.

__get()

__get(  $field) 

Parameters

$field

__isset()

__isset(  $field) 

Parameters

$field

set_active_leaf()

set_active_leaf(  $leaf_id) 

Parameters

$leaf_id

add_stylesheet()

add_stylesheet(string  $url, string  $media = false) 

Convenience shortcut for adding CSS files

Parameters

string $url

The stylesheet URL

string $media

The media type(s) for the stylesheet, if any

get_workflow()

get_workflow(string  $identifier, array  $options = array()) : \midcom\workflow\dialog

Parameters

string $identifier
array $options

Returns

\midcom\workflow\dialog

_check_nap_instance()

_check_nap_instance() 

Checks, whether an instance of the NAP interface class has already been created and creates it if not.

This check is only done during the set_object calls, which will always be the first calls in a sequence of NAP calls. (For performance reasons.)