Class midcom_helper_metadata

Description

This class is an interface to the metadata of MidCOM objects. It is not to be instantiated directly, as a cache is in place to avoid duplicate metadata objects for the same Midgard Object. So, basically, each of these objects is a singleton.

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.)

All metadata is identified by their string-based keys, the original MIDCOM_META_* constants are mapped to these new keys. This has been done to allow for easier extension.

Metadata Key Reference

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

  • timestamp schedule_start: The time upon which the object should be made visible. 0 for no restriction.
  • timestamp schedule_end: The time upon which the object should be made invisible. 0 for no restriction.
  • boolean nav_noentry: Set this to true if you do not want this object to appear in the navigation without it being completely hidden.
  • boolean hide: Set this to true to hide the object on-site, overriding scheduling.
  • string keywords: The keywords for this object, should be used for META HTML headers.
  • string description: A short description for this object, should be used for META HTML headers.
  • string robots: Search engine crawler instructions, one of '' (unset), 'noindex', 'index', 'follow' and 'nofollow'. See the corresponding META HTML header.
  • timestamp published: The publication time of the object, read-only.
  • MidgardPerson publisher: The person that published the object (i.e. author), read-only except on articles and pages.
  • timestamp created: The creation time of the object, read-only unless an article is edited.
  • MidgardPerson creator: The person that created the object, read-only.
  • timestamp edited: The last-modified time of the object, read-only.
  • MidgardPerson editor: The person that modified the object, read-only.
  • timestamp approved: The time of approval of the object, or 0 if not approved. Set automatically through approve/unapprove.
  • MidgardPerson approver: The person that approved/unapproved the object. Set automatically through approve/unapprove.
Example Usage, Metadata Retrieval

  1.  <?php
  2.  $nap new midcom_helper_nav();
  3.  $node $nap->get_node($nap->get_current_node());
  4.  
  5.  echo "Visible : " $meta->is_visible("</br>";
  6.  echo "Approved : " $meta->is_approved("</br>";
  7.  echo "Keywords: " $meta->get('keywords'"</br>";
  8.  ?>

Example Usage, Approval

  1.  <?php
  2.  $article new midcom_db_article($my_article_created_id);
  3.  
  4.  $meta =midcom_helper_metadata::retrieve($article);
  5.  $article->approve();
  6.  ?>

Located in /midcom.core/midcom/helper/metadata.php (line 72)


	
			
Variable Summary
string $guid
MidgardObject $object
Method Summary
static boolean is_locked (mixed &$object)
void approve ()
boolean can_unlock ()
mixed get (string $key)
midcom_helper_datamanager2 &get_datamanager ()
void get_languages ()
boolean is_approved ()
boolean is_visible ()
boolean lock ([int $timeout = null], [String $user = null])
void on_update ([string $key = false])
void set (string $key, mixed $value)
void set_multiple (Array $properties)
void unapprove ()
boolean unlock ([boolean $soft_unlock = false])
void _set_property (string $key, mixed $value)
Variables
string $guid = '' (line 88)

The guid of the object, it is cached for fast access to avoid repeated database queries.

  • var: GUID
MidgardObject $object = null (line 80)

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

Methods
static method is_locked (line 798)

Check if the requested object is locked

  • return: True if the object is locked, false if it isn't
  • access: public
static boolean is_locked (mixed &$object)
  • mixed &$object: MgdSchema object
approve (line 593)

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.

void approve ()
can_unlock (line 875)

Check whether current user can unlock the object

  • return: indicating privileges
  • todo: enable specifying user ?
boolean can_unlock ()
get (line 159)

This function will return a single metadata key from the object. Its 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.

  • return: The key's value.
  • see: midcom_helper_metdata::_retrieve_value()
mixed get (string $key)
  • string $key: The key to retrieve
get_datamanager (line 180)

Return a Datamanager instance for the current object.

This is returned by reference, which must be honored, as usual.

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.

midcom_helper_datamanager2 &get_datamanager ()
get_languages (line 753)
void get_languages ()
is_approved (line 529)

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

  • return: Indicating approval state.
boolean is_approved ()
is_object_visible_onsite (line 576)

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.

  • return: Indicating visibility.
boolean is_object_visible_onsite ()
is_visible (line 547)

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

This does not check approval, use is_approved for that.

boolean is_visible ()
load_datamanager (line 193)

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

void load_datamanager ()
lock (line 833)

Set the object lock

  • return: Indicating success
  • access: public
boolean lock ([int $timeout = null], [String $user = null])
  • int $timeout: Length of the lock timeout
  • String $user: GUID of the midgard_person object
on_update (line 366)

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.

void on_update ([string $key = false])
  • string $key: The key that was updated. Leave empty for a complete update by the Datamanager.
release_datamanager (line 233)
void release_datamanager ()
retrieve (line 661)

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.
Important note: The metadata object is returned by reference. You are very much encouraged to honor this reference, otherwise, the internal metadata value cache won't really help.

  • return: A reference to the created metadata object.
midcom_helper_metadata &retrieve (mixed $source)
  • mixed $source: The object to attach to, this may be either a MidgardObject, a GUID or a NAP data structure (node or leaf).
set (line 247)

Frontend for setting a single metadata option

void set (string $key, mixed $value)
  • string $key: The key to set.
  • mixed $value: The value to set.
set_multiple (line 264)

Frontend for setting multiple metadata options

void set_multiple (Array $properties)
  • Array $properties: Array of key => value properties.
unapprove (line 619)

Unapproves the object.

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

void unapprove ()
unlock (line 892)

Unlock the object

  • return: Indicating success
  • access: public
boolean unlock ([boolean $soft_unlock = false])
  • boolean $soft_unlock: If this is true, the changes are not written to disk
_set_property (line 302)

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 generate_error.

void _set_property (string $key, mixed $value)
  • string $key: The key to set.
  • mixed $value: The value to set.

Documentation generated on Fri, 10 Oct 2008 22:04:41 +0300 by phpDocumentor 1.4.2