\midcom_helper_metadata

This class is an interface to the metadata of MidCOM objects.

It will use an internal mechanism to cache repeated accesses to the same metadata key during its lifetime. (Invalidating this cache will be possible though.)

Metadata Key Reference

See the schema in /midcom/config/metadata_default.inc

Example Usage, Metadata Retrieval

<?php $nap = new midcom_helper_nav(); $node = $nap->get_node($nap->get_current_node());

$meta = midcom_helper_metadata::retrieve($node[MIDCOM_NAV_GUID]); echo "Visible : " . $meta->is_visible() . "
"; echo "Approved : " . $meta->is_approved() . "
"; echo "Keywords: " . $meta->get('keywords') . "
";

Example Usage, Approval

<?php $article = new midcom_db_article($my_article_created_id);

$meta = midcom_helper_metadata::retrieve($article); $meta->approve();

Summary

Methods
Properties
Constants
__construct()
get()
__get()
__isset()
get_datamanager()
release_datamanager()
set()
__set()
set_multiple()
is_approved()
is_visible()
is_object_visible_onsite()
approve()
force_approve()
unapprove()
retrieve()
is_locked()
lock()
can_unlock()
unlock()
$__object
$schedulestart
$scheduleend
$navnoentry
$hide
$keywords
$description
$robots
$published
$publisher
$created
$creator
$revised
$revisor
$approved
$approver
No constants found
No protected methods found
No protected properties found
N/A
load_datamanager()
find_schemaname()
_set_property()
on_update()
_retrieve_value()
$__metadata
$_cache
$_schemadb_path
$_datamanager
N/A

Properties

$__object

$__object : \midcom_core_dbaobject

Object to which we are attached to. This object can be accessed from the outside, where necessary.

Type

\midcom_core_dbaobject

$schedulestart

$schedulestart : integer

The time upon which the object should be made visible. 0 for no restriction.

Type

integer

$scheduleend

$scheduleend : integer

The time upon which the object should be made invisible. 0 for no restriction.

Type

integer

$navnoentry

$navnoentry : boolean

Set this to true if you do not want this object to appear in the navigation without it being completely hidden.

Type

boolean

$hide

$hide : boolean

Set this to true to hide the object on-site, overriding scheduling.

Type

boolean

$keywords

$keywords : string

The keywords for this object, should be used for META HTML headers.

Type

string

$description

$description : string

A short description for this object, should be used for META HTML headers.

Type

string

$robots

$robots : string

Search engine crawler instructions, one of '' (unset), 'noindex', 'index', 'follow' and 'nofollow'. See the corresponding META HTML header.

Type

string

$published

$published : integer

The publication time of the object, read-only.

Type

integer

$publisher

$publisher : string

The person that published the object (i.e. author), read-only except on articles and pages.

Type

string

$created

$created : integer

The creation time of the object, read-only unless an article is edited.

Type

integer

$creator

$creator : string

The person that created the object, read-only.

Type

string

$revised

$revised : integer

The last-modified time of the object, read-only.

Type

integer

$revisor

$revisor : string

The person that modified the object, read-only.

Type

string

$approved

$approved : integer

The time of approval of the object, or 0 if not approved. Set automatically through approve/unapprove.

Type

integer

$approver

$approver : string

The person that approved/unapproved the object. Set automatically through approve/unapprove.

Type

string

$__metadata

$__metadata : \midgard\portable\api\metadata

Metadata object of the current object

Type

\midgard\portable\api\metadata

$_cache

$_cache : Array

Holds the values already read from the database.

Type

Array

$_schemadb_path

$_schemadb_path : string

The schema database URL to use for this instance.

Type

string

Methods

__construct()

__construct(\midcom_core_dbaobject  $object, string  $schemadb) 

This will construct a new metadata object for an existing content object.

You must never use this constructor directly, it is considered private in this respect. Instead, use the retrieve method, which may be called as a class method.

You may use objects derived from any MidgardObject will do as well as long as the parameter call is available normally.

Parameters

\midcom_core_dbaobject $object

The MidgardObject to attach to.

string $schemadb

The URL of the schemadb to use.

get()

get(string  $key) : mixed

Return a single metadata key from the object. The return type depends on the metadata key that is requested (see the class introduction).

You will not get the data from the datamanager using this calls, but the only slightly post-processed metadata values. See _retrieve_value for post processing.

Parameters

string $key

The key to retrieve

Returns

mixed —

The key's value.

__get()

__get(  $key) 

Parameters

$key

__isset()

__isset(  $key) 

Parameters

$key

get_datamanager()

get_datamanager() : \midcom\datamanager\datamanager

Return a Datamanager instance for the current object.

Also, whenever the containing datamanager stores its data, you must call the on_update() method of this class. This is very important or backwards compatibility will be broken.

Returns

\midcom\datamanager\datamanager

A initialized Datamanager instance for the selected object.

release_datamanager()

release_datamanager() 

set()

set(string  $key, mixed  $value) 

Frontend for setting a single metadata option

Parameters

string $key

The key to set.

mixed $value

The value to set.

__set()

__set(  $key,   $value) 

Parameters

$key
$value

set_multiple()

set_multiple(array  $properties) 

Frontend for setting multiple metadata options

Parameters

array $properties

Array of key => value properties.

is_approved()

is_approved() : boolean

Checks whether the object has been approved since its last editing.

Returns

boolean —

Indicating approval state.

is_visible()

is_visible() : boolean

Checks the object's visibility regarding scheduling and the hide flag.

This does not check approval, use is_approved for that.

Returns

boolean —

Indicating visibility state.

is_object_visible_onsite()

is_object_visible_onsite() : boolean

This is a helper function which indicates whether a given object may be shown onsite taking approval, scheduling and visibility settings into account. The important point here is that it also checks the global configuration defaults, so that this is basically the same base on which NAP decides whether to show an item or not.

Returns

boolean —

Indicating visibility.

approve()

approve() 

Approves the object.

This sets the approved timestamp to the current time and the approver person GUID to the GUID of the person currently authenticated.

force_approve()

force_approve() 

Approve, if object is already approved update and approve.

This is to get the approval timestamp to current time in all cases

unapprove()

unapprove() 

Unapproves the object.

This resets the approved timestamp and sets the approver person GUID to the GUID of the person currently authenticated.

retrieve()

retrieve(mixed  $source) : \midcom_helper_metadata

Returns a metadata object for a given content object.

You may bass any one of the following arguments to the function:

  • Any class derived from MidgardObject, you must only ensure, that the parameter and guid member functions stays available.
  • Any valid GUID
  • Any NAP object structure, the content object is deduced from MIDCOM_NAV_GUID in this case.

Parameters

mixed $source

The object to attach to, this may be either a MidgardObject, a GUID or a NAP data structure (node or leaf).

Returns

\midcom_helper_metadata

The created metadata object.

is_locked()

is_locked() : boolean

Check if the requested object is locked

Returns

boolean —

True if the object is locked, false if it isn't

lock()

lock() : boolean

Set the object lock

Returns

boolean —

Indicating success

can_unlock()

can_unlock() : boolean

Check whether current user can unlock the object

Returns

boolean —

indicating privileges

unlock()

unlock() : boolean

Unlock the object

Returns

boolean —

Indicating success

load_datamanager()

load_datamanager() 

Loads the datamanager for this instance. This will patch the schema in case we are dealing with an article.

find_schemaname()

find_schemaname(\midcom\datamanager\schemadb  $schemadb, \midcom_core_dbaobject  $object) : string

Determine the schema to use for a particular object

Parameters

\midcom\datamanager\schemadb $schemadb

The schema DB

\midcom_core_dbaobject $object

the object to work on

Returns

string —

The schema name

_set_property()

_set_property(string  $key, mixed  $value) 

Directly set a metadata option.

The passed value will be stored using the follow transformations:

  • Storing into the approver field will automatically recognize Person Objects and simple IDs and transform them into a GUID.
  • created can only be set with articles.
  • creator, editor and edited cannot be set.

Any error will trigger midcom_error.

Parameters

string $key

The key to set.

mixed $value

The value to set.

on_update()

on_update(string  $key = false) 

This is the update event handler for the Metadata system. It must be called whenever metadata changes to synchronize the various backwards-compatibility values in place throughout the system.

Parameters

string $key

The key that was updated. Leave empty for a complete update by the Datamanager.

_retrieve_value()

_retrieve_value(string  $key) 

Retrieves a given metadata key, postprocesses it where necessary and stores it into the local cache.

  • Person references (both guid and id) get resolved into the corresponding Person object.
  • created, creator, edited and editor are taken from the corresponding MidgardObject fields.
  • Parameters are accessed using $object->get_parameter directly

Note, that we hide any errors from not existent properties explicitly, as a few of the MidCOM objects do not support all of the predefined meta data fields, PHP will default to "0" in these cases. For Person IDs, this "0" is rewritten to "1" to use the MidgardAdministrator account instead.

Parameters

string $key

The key to retrieve.