Source for file Element.php
Documentation is available at Element.php
* A Framework for Creating and Using Complex Web Elements
* The purpose of this framework is to provide a library of high-level objects
* to facilitate common HTML coding tasks, such as menus, tables, and forms.
* The intent is to reduce repetitive HTML coding as much as possible, replacing
* it with a combination of configuration files and style sheets with
* standardized naming conventions.
* This framework is built on and requires the
* {@link http://framework.zend.com/ Zend Framework}.
* @author Lyle Frost <lfrost@cnz.com>
* @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
* @license http://www.citadelnetwork.com/license/cnzframework New BSD License
* @version $Id: Element.php 27 2007-07-19 18:47:54Z lfrost $
Zend_Loader::loadClass('Zend_Config');
Zend_Loader::loadClass('Zend_Config_Ini');
* This is an abstract base class for all high-level HTML display elements. Its
* primary function is to generate the configuration section names and style
* names in a standardized way.
* The configuration section name is generated as
* Html<i>Type</i>[-<i>name</i>]
* where type is third field of class name and name is the element name passed
* to the constructor. For example, Cnz_Html_Form_Checkbox with a name of pay
* would yield HtmlFormPay.
* The style name is generated as
* <i>type</i>[<i>Subtype</i>][-<i>name</i>][-<i>suffix</i>]
* This design allows for a single default configuration section and/or style,
* with the ability to override the defaults for special elements.
* Some elements will have special style suffixes (e.g., hilighted table rows).
* For example, a highlighted table row with the custom name <kbd>team</kbd>
* would have the following returned by <kbd>genStyles()</kbd>.
* table table-team table-hilight table-team-hilight
* Subtypes are only used for situations where the same HTML tag has different
* structural roles in the same complex element. For example, a form will use
* a div block to format the label for a field as well as the field itself, but
* different styling will normally be desired for these. For example, a form
* label with the custom name pay would have the following returned by
* <kbd>genStyles()</kbd>.
* formLabel formLabel-pay
* This allows the definition of default styles with overrides for named tables
* and special cases. Remember that the order of the style names in the class
* attribute is irrelevant. The order in the style sheet is what matters. The
* more specific styles should occur below the more general styles.
* HTML id values can also be generated with <kbd>genId()</kbd>. This is
* <i>type</i>[-<i>name</i>]
const CONFIG_PREFIX = 'Html';
const STYLE_SEPARATOR = '-';
private $baseStyleName = NULL;
/* Getters/Setters ===================================================*/
/** @return string Name */
/* Abstract Methods ==================================================*/
* @param string $style Value for outermost style attribute
public abstract function display($style = NULL);
/* Methods ===========================================================*/
* string name Element name
* Cnz_Element master Master element
* string filename Configuration filename
* boolean config Has custom configuration
* boolean style Has custom style
* @param array $options Associative array of common options.
if (isset ($options['name'])) $this->name = strtolower($options['name']);
if (isset ($options['master'])) $this->master = $options['master'];
else $this->master = $options['master'] = $this;
if (isset ($options['filename'])) $this->configFile = $_SERVER['DOCUMENT_ROOT'] . '/../cfg/' . $options['filename'];
if (isset ($options['config'])) $this->customConfigFlag = (boolean) $options['config'];
if (isset ($options['style'])) $this->customStyleFlag = (boolean) $options['style'];
// Generate the configuration section and style names.
$type = $this->extractBaseName();
$this->baseStyleName = $type;
* Extracts the third field of the class name.
* @return string Third field of the class name.
private function extractBaseName()
$subType = strstr($type, 'Html_');
if ($end > 0) $subType = substr($subType, 0, $end);
* Generates the id attribute value.
* @return string Value for use with HTML id attribute
protected function genId($number = NULL)
$baseStyleName = $this->baseStyleName;
$s .= self::STYLE_SEPARATOR . $this->master->getName();
$s .= self::STYLE_SEPARATOR . $this->name;
$s .= self::STYLE_SEPARATOR . $number;
* Generates the class attribute value.
* @param string $subtype Style name subtype
* @param string $suffix Style name suffix
* @return string List of styles for use with HTML class attribute
protected function genStyles($subtype = NULL, $suffix = NULL)
$baseStyleName = $this->baseStyleName;
$styleName = $this->baseStyleName . ucfirst(strtolower($subtype)) . self::STYLE_SEPARATOR . $this->master->getName();
$styleName = $this->baseStyleName . self::STYLE_SEPARATOR . $this->master->getName();
if (!empty($styleName)) $s .= ' ' . $styleName;
$s .= ' ' . $baseStyleName . self::STYLE_SEPARATOR . $suffix;
if ($this->customStyleFlag) $s .= ' ' . $styleName . self::STYLE_SEPARATOR . $suffix;
|