Source for file Generator.php
Documentation is available at Generator.php
* Copyright (c) 2005-2008, Laurent Laville <pear@laurent-laville.org>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the authors nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @package HTML_Progress2
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2005-2008 Laurent Laville
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://pear.php.net/package/HTML_Progress2
* @since File available since Release 2.0.0RC1
require_once 'HTML/QuickForm/Controller.php';
require_once 'HTML/QuickForm/Action/Submit.php';
require_once 'HTML/QuickForm/Action/Jump.php';
require_once 'HTML/QuickForm/Action/Display.php';
require_once 'HTML/QuickForm/Action/Direct.php';
require_once 'HTML/Progress2.php';
require_once 'HTML/Progress2/Generator/pages.php';
* The HTML_Progress2_Generator class provides an easy way to build
* progress bar, show a preview, and save php/css code for a later reuse.
* @package HTML_Progress2
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2005-2008 Laurent Laville
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version Release: @package_version@
* @link http://pear.php.net/package/HTML_Progress2
* @since Class available since Release 2.0.0RC1
* The progress object renders into this generator.
* All default wizard pages definition
* All default wizard controller actions definition
'preview' => 'ActionPreview',
'display' => 'ActionDisplay',
'process' => 'ActionProcess',
* @param string $controllerName (optional) Name of generator wizard (QuickForm)
* @param array $attributes (optional) List of renderer options
* @param array $errorPrefs (optional) Hash of parameters
* to configure error handler
* @since version 2.0.0 (2005-10-01)
$this->__construct($controllerName, $attributes, $errorPrefs);
* Constructor (ZE2) Summary
* o Creates a standard progress bar generator wizard.
* $generator = new HTML_Progress2_Generator();
* o Creates a progress bar generator wizard with
* customized actions: progress bar preview, form rendering, buttons manager
* $controllerName = 'myPrivateGenerator';
* 'preview' => name of a HTML_QuickForm_Action instance
* (default 'ActionPreview',
* see 'HTML/Progress2/Generator/Preview.php')
* 'display' => name of a HTML_QuickForm_Action_Display instance
* (default 'ActionDisplay',
* see 'HTML/Progress2/Generator/Default.php')
* 'process' => name of a HTML_QuickForm_Action instance
* (default 'ActionProcess',
* see 'HTML/Progress2/Generator/Process.php')
* $generator = new HTML_Progress2_Generator($controllerName, $attributes);
* @param string $controllerName (optional) Name of generator wizard (QuickForm)
* @param array $attributes (optional) List of renderer options
* @param array $errorPrefs (optional) Hash of parameters
* to configure error handler
* @since version 2.0.0 (2005-10-01)
* @throws HTML_PROGRESS2_ERROR_INVALID_INPUT
function __construct($controllerName = 'ProgressGenerator',
array ('var' => '$controllerName',
array ('var' => '$attributes',
// build a new modal controller
parent ::HTML_QuickForm_Controller ($controllerName, true );
// add all wizard default pages
// add all wizard default actions
// set ProgressBar default values on first run
$sess = & $this->container ();
if (count($sess['defaults']) == 0 ) {
$this->setDefaults (array (
'progresssize' => array ('left' => 10 , 'top' => 25 ,
'position' => 'relative',
'borderpainted' => false ,
'borderclass' => 'progressBorder%s',
'borderstyle' => array ('style' => 'solid', 'width' => 0 ,
'cellvalue' => array ('min' => 0 , 'max' => 100 , 'inc' => 1 ),
'cellsize' => array ('width' => 15 , 'height' => 20 ,
'spacing' => 2 , 'count' => 10 ),
'cellcolor' => array ('active' => '#006600',
'cellfont' => array ('family' => 'Courier, Verdana',
'size' => 8 , 'color' => '#000000'),
'stringpainted' => false ,
'stringclass' => 'progressTextLabel%s',
'stringvalue' => 'something to display',
'stringsize' => array ('left' => 5 , 'top' => 5 ),
'stringfont' => array ('family' => 'Verdana, Tahoma, Arial',
'size' => 11 , 'color' => '#000000'),
'stringweight' => 'normal',
'phpcss' => array ('P' => true )
* Returns a unique instance of the given progress generator wizard.
* @param string $controllerName (optional) Name of generator wizard (QuickForm)
* @param array $attributes (optional) List of renderer options
* @param array $errorPrefs (optional) Hash of parameters
* to configure error handler
* @return object HTML_Progress2_Generator
* @since version 2.1.0 (2006-08-12)
function &singleton($controllerName = 'ProgressGenerator',
if (!isset ($generator)) {
* Adds all pages of wizard at once
* @param mixed $pages Wizard pages definition array or null if used defaults
* @since version 2.1.0 (2006-08-12)
foreach ($pages as $page) {
* Add a specific page to wizard or each page one by one
* @param array $page a single Wizard page definition
* @since version 2.1.0 (2006-08-12)
$className = $page['@']['class'];
$pageName = $page['@']['name'];
$qfcPage = & new $className($pageName);
parent ::addPage ($qfcPage);
// adds additional action
foreach ($page as $action => $attr) {
if ($action == '#' || $action == '@') {
$qfcPage->addAction ($action, new $attr['@']['class']);
// adds common action on each page
$this->addAction($pageName, new HTML_QuickForm_Action_Direct ());
* Adds common actions for the frontend wizard
* @param mixed $actions (optional) Identify for each action a class handler
* @since version 2.1.0 (2006-08-12)
if (isset ($actions) && is_array($actions)) {
$ActionPreview = $this->_act['preview'];
include_once 'HTML/Progress2/Generator/Preview.php';
$ActionPreview = 'ActionPreview';
$this->addAction('apply', new $ActionPreview());
$ActionDisplay = $this->_act['display'];
include_once 'HTML/Progress2/Generator/Default.php';
$ActionDisplay = 'ActionDisplay';
$this->addAction('display', new $ActionDisplay());
// adds basic actions (abort, commit, reset)
$ActionProcess = $this->_act['process'];
include_once 'HTML/Progress2/Generator/Process.php';
$ActionProcess = 'ActionProcess';
$this->addAction('cancel', new $ActionProcess());
$this->addAction('process', new $ActionProcess());
// adds dump class action (if necessary)
$ActionDump = $this->_act['dump'];
include_once 'HTML/Progress2/Generator/Dump.php';
$ActionDump = 'ActionDump';
* Registers a handler for a specific action.
* @param string $actionName name of the action
* @param object &$action the handler for the action
* @since version 2.1.0 (2006-08-12)
$this->_act[$actionName] = get_class($action);
parent ::addAction ($actionName, $action);
* Returns whether or not a file is in the include path.
* @param string $file filename to test
* @return boolean true if the file is in the include path.
* @since version 2.1.0 (2006-08-12)
* Creates a progress bar with options choosen on all wizard tabs.
* @since version 2.0.0 (2005-10-01)
$this->_progress->setIdent ('PB1');
$this->_progress->setBorderPainted ($structure['borderpainted']);
$this->_progress->setAnimSpeed ($structure['animspeed']);
$this->_progress->setOrientation ($structure['orientation']);
$this->_progress->setFillWay ($structure['fillway']);
$this->_progress->setCellAttributes ($structure['cell']);
$this->_progress->setCellCount ($structure['cellcount']);
$this->_progress->setBorderAttributes ($structure['border']);
if ($structure['stringpainted']) {
$labelID = $structure['string']['name'];
unset ($structure['string']['name']);
$this->_progress->setLabelAttributes ($labelID, $structure['string']);
$this->_progress->setProgressAttributes ($structure['progress']);
$this->_progress->setMinimum ($structure['minimum']);
$this->_progress->setMaximum ($structure['maximum']);
$this->_progress->setIncrement ($structure['increment']);
* Creates a progress bar structure
* with options choosen on all wizard tabs.
* @since version 2.0.0 (2005-10-01)
* @see HTML_Progress2::toArray()
$progress = $this->exportValues ();
$structure['animspeed'] = intval($progress['rAnimSpeed']);
$structure['borderpainted'] = ($progress['borderpainted'] == '1');
$structure['stringpainted'] = ($progress['stringpainted'] == '1');
/* Page 1: Progress attributes ****************************************/
if (strlen(trim($progress['progresssize']['bgcolor'])) > 0 ) {
$structure['progress']['background-color']
= $progress['progresssize']['bgcolor'];
if (strlen(trim($progress['progresssize']['width'])) > 0 ) {
$structure['progress']['width'] = $progress['progresssize']['width'];
if (strlen(trim($progress['progresssize']['height'])) > 0 ) {
$structure['progress']['height'] = $progress['progresssize']['height'];
if (strlen(trim($progress['progresssize']['left'])) > 0 ) {
$structure['progress']['left'] = $progress['progresssize']['left'];
if (strlen(trim($progress['progresssize']['top'])) > 0 ) {
$structure['progress']['top'] = $progress['progresssize']['top'];
$structure['progress']['auto-size'] = ($progress['autosize'] == '1');
$structure['orientation']
= ($progress['shape'] == '1') ?
$structure['fillway'] = $progress['way'];
/* Page 2: Cell attributes ********************************************/
$structure['cell']['id'] = $progress['cellid'];
$structure['cell']['class'] = $progress['cellclass'];
if (strlen(trim($progress['cellvalue']['min'])) > 0 ) {
$structure['minimum'] = intval($progress['cellvalue']['min']);
if (strlen(trim($progress['cellvalue']['max'])) > 0 ) {
$structure['maximum'] = intval($progress['cellvalue']['max']);
if (strlen(trim($progress['cellvalue']['inc'])) > 0 ) {
$structure['increment'] = intval($progress['cellvalue']['inc']);
if (strlen(trim($progress['cellsize']['width'])) > 0 ) {
$structure['cell']['width'] = $progress['cellsize']['width'];
if (strlen(trim($progress['cellsize']['height'])) > 0 ) {
$structure['cell']['height'] = $progress['cellsize']['height'];
if (strlen(trim($progress['cellsize']['spacing'])) > 0 ) {
$structure['cell']['spacing'] = $progress['cellsize']['spacing'];
if (strlen(trim($progress['cellsize']['count'])) > 0 ) {
$structure['cellcount'] = intval($progress['cellsize']['count']);
if (strlen(trim($progress['cellcolor']['active'])) > 0 ) {
$structure['cell']['active-color'] = $progress['cellcolor']['active'];
if (strlen(trim($progress['cellcolor']['inactive'])) > 0 ) {
$structure['cell']['inactive-color']
= $progress['cellcolor']['inactive'];
if (strlen(trim($progress['cellcolor']['bgcolor'])) > 0 ) {
$structure['cell']['background-color']
= $progress['cellcolor']['bgcolor'];
if (strlen(trim($progress['cellfont']['family'])) > 0 ) {
$structure['cell']['font-family'] = $progress['cellfont']['family'];
if (strlen(trim($progress['cellfont']['size'])) > 0 ) {
$structure['cell']['font-size'] = $progress['cellfont']['size'];
if (strlen(trim($progress['cellfont']['color'])) > 0 ) {
$structure['cell']['color'] = $progress['cellfont']['color'];
/* Page 3: Border attributes ******************************************/
$structure['border']['class'] = $progress['borderclass'];
if (strlen(trim($progress['borderstyle']['width'])) > 0 ) {
$structure['border']['width'] = $progress['borderstyle']['width'];
if (strlen(trim($progress['borderstyle']['style'])) > 0 ) {
$structure['border']['style'] = $progress['borderstyle']['style'];
if (strlen(trim($progress['borderstyle']['color'])) > 0 ) {
$structure['border']['color'] = $progress['borderstyle']['color'];
/* Page 4: Label attributes *******************************************/
$structure['string']['name'] = $progress['stringid'];
$structure['string']['class'] = $progress['stringclass'];
$structure['string']['value'] = $progress['stringvalue'];
if (strlen(trim($progress['stringsize']['width'])) > 0 ) {
$structure['string']['width'] = $progress['stringsize']['width'];
if (strlen(trim($progress['stringsize']['height'])) > 0 ) {
$structure['string']['height'] = $progress['stringsize']['height'];
if (strlen(trim($progress['stringsize']['left'])) > 0 ) {
$structure['string']['left'] = $progress['stringsize']['left'];
if (strlen(trim($progress['stringsize']['top'])) > 0 ) {
$structure['string']['top'] = $progress['stringsize']['top'];
if (strlen(trim($progress['stringsize']['bgcolor'])) > 0 ) {
$structure['string']['background-color']
= $progress['stringsize']['bgcolor'];
$structure['string']['align'] = $progress['stringalign'];
if (strlen(trim($progress['stringvalign'])) > 0 ) {
$structure['string']['valign'] = $progress['stringvalign'];
if (strlen(trim($progress['stringfont']['family'])) > 0 ) {
$structure['string']['font-family'] = $progress['stringfont']['family'];
if (strlen(trim($progress['stringfont']['size'])) > 0 ) {
$structure['string']['font-size'] = $progress['stringfont']['size'];
if (strlen(trim($progress['stringfont']['color'])) > 0 ) {
$structure['string']['color'] = $progress['stringfont']['color'];
$structure['string']['font-weight'] = $progress['stringweight'];
Documentation generated on Sun, 11 Dec 2011 13:00:11 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|