. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * * @copyright 2008-2009, KnowledgeTree Inc. * @license GNU General Public License version 3 * @author KnowledgeTree Team * @package Installer * @version Version 0.1 */ class stepAction { /** * Step class name * * @author KnowledgeTree Team * @access protected * @var string */ protected $stepName = ''; /** * Step names for classes * * @author KnowledgeTree Team * @access protected * @var array */ protected $stepClassNames = array(); /** * Flag if step needs confirmation * * @author KnowledgeTree Team * @access protected * @var boolean */ protected $displayConfirm = false; /** * Reference to session object * * @author KnowledgeTree Team * @access protected * @var object Session */ protected $session = null; /** * Reference to current step object * * @author KnowledgeTree Team * @access protected * @var object class Step */ protected $action = null; /** * Constructs step action object * * @author KnowledgeTree Team * @access public * @param string class name of the current step */ public function __construct($step) { $this->stepName = $step; } /** * Main control to handle the steps actions * * @author KnowledgeTree Team * @param none * @access public * @return string */ public function doAction() { if($this->stepName != '') { $this->action = $this->createStep(); if(!$this->action) { die("{$this->stepName} : Class Files Missing : Create Step"); } $response = $this->action->doStep(); if($this->action->storeInSession()) { // Check if class values need to be stored in session $this->_loadStepToSession($this->stepName); // Send class to session } if ($response == 'error') { $this->_handleErrors(); // Send Errors to session } else { $this->_clearErrors($this->stepName); // Send Errors to session } return $response; } else { die("{$this->stepName} : Class Files Missing : Do Action"); } } /** * Instantiate a step. * * @author KnowledgeTree Team * @param none * @access public * @return object Step */ public function createStep() { $step_class = $this->makeCamelCase($this->stepName); return new $step_class(); } /** * Converts string to camel case * * @author KnowledgeTree Team * @param string * @access public * @return string */ public function makeCamelCase($str) { $upper=ucwords($str); $str=str_replace('_', '', $upper); return $str; } /** * Converts string to human readable heading * * @author KnowledgeTree Team * @param string * @access public * @return string */ public function makeHeading($str) { $str = str_replace('_', ' ', $str); $str = ucwords($str); return $str; } /** * Sets steps class names in string format * * @author KnowledgeTree Team * @param array * @access public * @return void */ public function setSteps($stepClassNames) { $this->stepClassNames = $stepClassNames; } /** * Sets steps in human readable string format * * @author KnowledgeTree Team * @param array * @access public * @return void */ public function setStepNames($step_names) { $this->step_names = $step_names; } /** * Returns a message to display at the top of template * * @author KnowledgeTree Team * @param none * @access public * @return string */ public function getTop() { return ''.$this->getCurrentStepName().''; } /** * Returns current step name * * @author KnowledgeTree Team * @param none * @access public * @return string */ public function getCurrentStepName() { return $this->step_names[$this->stepName]; } /** * Returns left menu * * @author KnowledgeTree Team * @param none * @access public * @return string */ public function getLeftMenu() { $menu = '
'; return $menu; } /** * Returns confirmation page flag * * @author KnowledgeTree Team * @param none * @access public * @return boolean */ public function displayConfirm() { // TODO:No other way I can think of doing this return $this->displayConfirm; } /** * Sets confirmation page flag * * @author KnowledgeTree Team * @param boolean * @access public * @return void */ public function setDisplayConfirm($displayConfirm) { $this->displayConfirm = $displayConfirm; } /** * Sets session object * * @author KnowledgeTree Team * @param object Session * @access public * @return void */ public function loadSession($ses) { $this->session = $ses; } /** * Returns session object * * @author KnowledgeTree Team * @param object Session * @access public * @return object */ public function getSession() { return $this->session; } /** * Returns step tenplate content * * @author KnowledgeTree Team * @param none * @access public * @return string */ public function paintAction() { $left = $this->getLeftMenu(); $top = $this->getTop(); $step_errors = $this->action->getErrors(); // Get errors if($this->displayConfirm()) // Check if theres a confirm step $template = "templates/{$this->stepName}_confirm.tpl"; else $template = "templates/{$this->stepName}.tpl"; $step_tpl = new Template($template); $step_tpl->set("errors", $step_errors); // Set template errors $step_vars = $this->action->getStepVars(); // Get template variables foreach ($step_vars as $key => $value) { // Set template variables $step_tpl->set($key, $value); // Load values to session if($this->action->storeInSession()) { // Check if class values need to be stored in session $this->_loadValueToSession($this->stepName, $key, $value); } } $content = $step_tpl->fetch(); $tpl = new Template("templates/wizard.tpl"); $tpl->set('content', $content); $tpl->set('left', $left); echo $tpl->fetch(); } /** * Load class to session * * @author KnowledgeTree Team * @param string $class name of class * @param array $v array of values * @param boolean $overwrite whether or not to overwrite existing * @access private * @return void */ private function _loadStepToSession($class, $v = array(), $overwrite = false) { if($this->session != null) { if($overwrite) { $this->session->set($class , $v); } else { if(!$this->session->is_set($class)) $this->session->set($class , $v); } } else { die("Where is the session?"); } } /** * Load class value to session * * @author KnowledgeTree Team * @param string $class name of class * @param string $k key value * @param string $v value to store * @param boolean $overwrite whether or not to overwrite existing * @access private * @return void */ private function _loadValueToSession($class, $k, $v, $overwrite = false) { if($this->session != null) { $this->session->setClass($class, $k, $v); } else { die("Where is the session ?"); } } /** * Load all class errors value to session * * @author KnowledgeTree Team * @param none * @access private * @return void */ private function _handleErrors() {// TODO: handle multiple errors $step_errors = $this->action->getErrors(); // Get errors foreach ($step_errors as $key => $value) { $this->_loadErrorToSession($this->stepName, $key, $value); // Load values session } } /** * Remove all class errors value to session * * @author KnowledgeTree Team * @param none * @access private * @return void */ private function _clearErrors($class) { if($this->session) { $this->session->clearErrors($class); } } /** * Load class error value to session * * @author KnowledgeTree Team * @param string $class name of class * @param string $k key value * @param string $v value to store * @param boolean $overwrite whether or not to overwrite existing * @access private * @return void */ private function _loadErrorToSession($class, $k, $v, $overwrite = false) { $k = "errors"; if($this->session != null) { $this->session->setClassError($class, $k, $v); } else { die("Where is the session ?"); } } } ?>