*/ /** * Klasa stProgressBar * * @package stProgressBarPlugin * @subpackage libs */ class stProgressBar { var $action = ''; var $module = ''; var $steps = 0; var $context = null; var $pb_id = ''; var $msg = ''; var $params = array(); public function __construct( $module='', $action = '',$steps = false) { sfLoader::loadHelpers(array('Partial', 'Javascript', 'Tag')); $this->action = $action; $this->module = $module; $this->pb_id = $module.'_'.$action; $this->context = sfContext::getInstance(); $this->retriveParams(); if ($steps===false) { $this->getSteps();} else { $this->setSteps($steps); } } public function setParam($param, $value) { $this->params[$param] = $value; $this->updateParams(); } public function getParam($param, $default = null) { return (isset($this->params[$param]))?$this->params[$param]:$default; } private function updateParams() { $this->context->getUser()->setAttribute($this->pb_id, $this->params ,'soteshop/stProgressBarPlugin'); } private function retriveParams() { $this->params = $this->context->getUser()->getAttribute($this->pb_id, array() ,'soteshop/stProgressBarPlugin'); } private function getSteps() { $this->steps = ((isset($this->params['steps']))?$this->params['steps']:0); } private function setSteps($steps = 0) { $this->steps = $this->params['steps'] = $steps; $this->updateParams(); } public function setMsg($msg = null) { $this->msg = $msg; } public function showProgressBar($step =0, $init = false) { $i18n = sfContext::getInstance()->getI18N(); sfContext::getInstance()->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); $process = 100.0; if ($this->steps>0 && ($step<=$this->steps)) { $process = $step*100.0/$this->steps; } $progress_bar = st_get_partial('stProgressBar/progressBar',array('name'=>$this->pb_id, 'complete'=>number_format($process,2), 'msg'=>$this->msg)); // $update_script = ''; $update_script = ''; if ($init) { $content = content_tag('div',$progress_bar,array('id'=>'stProgressBar-'.$this->pb_id, 'class' => 'progress-bar')).content_tag('div','',array('id'=>'stProgressBar-'.$this->pb_id.'-msg')).$update_script; } else { $content = $progress_bar.$update_script; } if ($step>=$this->steps) { return $progress_bar; } return $content; } }