Perforce Chronicle 2012.2/486814
API Documentation
|
Provides a context facility to inform widgets (which can be asynchronously loaded/operated) of arbitrary data. More...
Public Member Functions | |
clearContext () | |
Clear the context. | |
getEncodedValues () | |
Provide the context in encoded form, suitable for placing in HTML. | |
getValues ($key=null) | |
Provide the values from the context, or if specified, a named value within. | |
init () | |
Initialize by making ourself available to the controller and cleaning out any cached initial dispatch values. | |
setEncodedValues ($encoded) | |
Set the context from its encoded form. | |
setValue ($key, $value=null) | |
Set a value in the context. | |
setValues ($values) | |
Set a number of values in the context at once. | |
Static Protected Attributes | |
static | $_context = array() |
static | $_initialDispatch = true |
Flag indicating whether the current invocation is the initial invocation (as opposed to a forward, redirect, or other action manipulation). |
Provides a context facility to inform widgets (which can be asynchronously loaded/operated) of arbitrary data.
A 'data' controller can use this facility to convey information to widgets like so: $this->widgetContext->setValue('foo', 'bar');
A 'widget' controller can use this facility to use information provided like so: $context = $this->widgetContext->getValues(); if (array_key_exists('foo', $context) { ... } or if ($this->widgetContext->getValues('foo')) { ... }
The widget views and supporting javascript maintain the context across requests to support async creation/configuration/reload.
P4Cms_Controller_Action_Helper_WidgetContext::clearContext | ( | ) |
Clear the context.
{
static::$_context = array();
return $this;
}
P4Cms_Controller_Action_Helper_WidgetContext::getEncodedValues | ( | ) |
Provide the context in encoded form, suitable for placing in HTML.
{ $encoded = ''; $values = $this->getValues(); if (count($values)) { $encoded = Zend_Json::encode($values); } return $encoded; }
P4Cms_Controller_Action_Helper_WidgetContext::getValues | ( | $ | key = null | ) |
Provide the values from the context, or if specified, a named value within.
string | $key | Optional key to retrieve from context. |
{ if (isset($key)) { return array_key_exists($key, static::$_context) ? static::$_context[$key] : null; } return static::$_context; }
P4Cms_Controller_Action_Helper_WidgetContext::init | ( | ) |
Initialize by making ourself available to the controller and cleaning out any cached initial dispatch values.
{ // make this action helper available to the controller $this->getActionController()->widgetContext = $this; // clear context for initial dispatch if (static::$_initialDispatch) { static::$_initialDispatch = false; $this->clearContext(); } }
P4Cms_Controller_Action_Helper_WidgetContext::setEncodedValues | ( | $ | encoded | ) |
Set the context from its encoded form.
string | $encoded | A JSON-encoded context. |
{ if (isset($encoded) and strlen($encoded)) { $values = Zend_Json::decode($encoded); if ($values) { $this->setValues($values); } } return $this; }
P4Cms_Controller_Action_Helper_WidgetContext::setValue | ( | $ | key, |
$ | value = null |
||
) |
Set a value in the context.
string | $key | The key to set in the context. |
mixed | $value | The (optional) value to set. If null, the value will be removed from the context. |
{ if (!isset($value)) { unset(static::$_context[$key]); return $this; } static::$_context[$key] = $value; return $this; }
P4Cms_Controller_Action_Helper_WidgetContext::setValues | ( | $ | values | ) |
Set a number of values in the context at once.
array | $values | The key/value pairs to set in the context. |
{ foreach ($values as $key => $value) { $this->setValue($key, $value); } return $this; }
P4Cms_Controller_Action_Helper_WidgetContext::$_context = array() [static, protected] |
P4Cms_Controller_Action_Helper_WidgetContext::$_initialDispatch = true [static, protected] |
Flag indicating whether the current invocation is the initial invocation (as opposed to a forward, redirect, or other action manipulation).
This is useful to ensure a fresh context.