Perforce Chronicle 2012.2/486814
API Documentation
|
Encapsulates information about widget types. More...
Public Member Functions | |
getControllerClassName () | |
Get the widget controller class name. | |
getDefaults () | |
Get the default options for this widget type. | |
getIconUrl () | |
Get the URI to the widget type icon file. | |
getModule () | |
Get an instance of the module that provides this widget. | |
getModulePackageName () | |
Get the package name of the module that provides this widget. | |
getRouteParams () | |
Get the widget module/controller/action route parameters to invoke this widget. | |
hasIcon () | |
Determine if there is an icon for this widget type. | |
isValid () | |
Determine if this widget type is valid (e.g. | |
Static Public Member Functions | |
static | addType ($type) |
Programatically add a type to the list of types. | |
static | clearCache () |
Clear the types cache. | |
static | exists ($id) |
Determine if a given widget type exists. | |
static | fetch ($id) |
Get the requested widget type. | |
static | fetchAll () |
Get all of the valid widget types that are available across all modules. | |
Static Protected Member Functions | |
static | _typesFromPackage ($module) |
Extract the widget types from the given module. | |
Static Protected Attributes | |
static | $_types = null |
Encapsulates information about widget types.
Widgets are just configurable action controllers.
static P4Cms_Widget_Type::_typesFromPackage | ( | $ | module | ) | [static, protected] |
Extract the widget types from the given module.
P4Cms_Module | $module | the module to get types from. |
{ $info = $module->getPackageInfo(); // if no widgets, early exit. if (!isset($info['widgets']) || !is_array($info['widgets'])) { return array(); } // turn widget info into type instances. $types = array(); foreach ($info['widgets'] as $typeId => $typeInfo) { // qualify type id with module name. $typeId = $module->getRouteFormattedName() . "/" . $typeId; // add module route param to type info. $typeInfo['module'] = $module->getRouteFormattedName(); $type = new static; $type->setId($typeId); $type->setValues($typeInfo); $types[$typeId] = $type; } return $types; }
static P4Cms_Widget_Type::addType | ( | $ | type | ) | [static] |
Programatically add a type to the list of types.
Note: there is no persistent storage of these types - they survive only for the duration of the process (or until they are explicitly cleared).
P4Cms_Widget_Type | $type | the widget type to add. |
InvalidArgumentException | if the given type is invalid. |
{ if (!$type instanceof P4Cms_Widget_Type) { throw new InvalidArgumentException( "Cannot add widget type. Type is not a valid widget type instance." ); } $types = static::fetchAll(); $types[$type->getId()] = $type; static::$_types = $types; }
static P4Cms_Widget_Type::clearCache | ( | ) | [static] |
Clear the types cache.
{ static::$_types = null; }
static P4Cms_Widget_Type::exists | ( | $ | id | ) | [static] |
Determine if a given widget type exists.
string | $id | the id of the widget type to check. |
{ try { static::fetch($id); } catch (P4Cms_Model_NotFoundException $e) { return false; } return true; }
static P4Cms_Widget_Type::fetch | ( | $ | id | ) | [static] |
Get the requested widget type.
string | $id | the id of the widget type to get. |
{ $types = static::fetchAll(); if (!isset($types[$id])) { // unable to find the requested type. throw new P4Cms_Model_NotFoundException( 'Cannot fetch widget type. The requested type does not exist.' ); } return $types[$id]; }
static P4Cms_Widget_Type::fetchAll | ( | ) | [static] |
Get all of the valid widget types that are available across all modules.
{ // only collect types once. if (static::$_types instanceof P4Cms_Model_Iterator) { return static::$_types; } $types = new P4Cms_Model_Iterator; foreach (P4Cms_Module::fetchAllEnabled() as $module) { foreach (static::_typesFromPackage($module) as $type) { $types[$type->getId()] = $type; } } // keep it! static::$_types = $types; return $types; }
P4Cms_Widget_Type::getControllerClassName | ( | ) |
Get the widget controller class name.
{ // convert controller from route to class name format. $dispatcher = new Zend_Controller_Dispatcher_Standard; $controller = $this->getValue('controller'); $controller = $dispatcher->formatControllerName($controller); return $this->getModulePackageName() . "_" . $controller; }
P4Cms_Widget_Type::getDefaults | ( | ) |
Get the default options for this widget type.
{ $defaults = $this->_getValue('defaults'); return is_array($defaults) ? $defaults : array(); }
P4Cms_Widget_Type::getIconUrl | ( | ) |
Get the URI to the widget type icon file.
P4Cms_Widget_Exception | if there is no icon. |
{ if (!$this->hasIcon()) { throw new P4Cms_Package_Exception( "Cannot get icon URI. This widget type has no icon." ); } $icon = $this->_getValue('icon'); return (P4Cms_Uri::isRelativeUri($icon)) ? $this->getModule()->getBaseUrl() . '/' . $icon : $icon; }
P4Cms_Widget_Type::getModule | ( | ) |
Get an instance of the module that provides this widget.
{ return P4Cms_Module::fetch($this->getValue('module')); }
P4Cms_Widget_Type::getModulePackageName | ( | ) |
Get the package name of the module that provides this widget.
{ // convert module from route to class name format. $dispatcher = new Zend_Controller_Dispatcher_Standard; return $dispatcher->formatModuleName($this->getValue('module')); }
P4Cms_Widget_Type::getRouteParams | ( | ) |
P4Cms_Widget_Type::hasIcon | ( | ) |
Determine if there is an icon for this widget type.
{ $icon = $this->_getValue('icon'); return isset($icon) && is_string($icon); }
P4Cms_Widget_Type::isValid | ( | ) |
Determine if this widget type is valid (e.g.
does the controller class exist?).
{ // ensure type has an id. if (!strlen($this->getId())) { return false; } // ensure controller class is valid. $controller = $this->getControllerClassName(); if (!class_exists($controller) || !is_subclass_of($controller, 'P4Cms_Widget_ControllerAbstract') ) { return false; } return true; }
P4Cms_Widget_Type::$_types = null [static, protected] |