我从db中检索行集 而不是取决于显示格式 (米,馅饼,酒吧我正在使用高图) 我应该管理它。 我最终得到了
class Model_StatRealtime implements Model_StatsTypeInterface
{
protected $_rows;
protected $_translator;
public function __construct(Model_Rowset_View $rows)
{
$this->_rows = $rows;
$this->_translator = Zend_Registry::get('Zend_Translate');
}
public function getStatType()
{
return $this->_rows->getStat()->getRealtimeType();
}
public function getStatTitle()
{
return $this->_rows->getStat()->getTitle();
}
public function count()
{
return $this->_rows->count();
}
public function getData()
{
$data = array();
if(method_exists($this,$this->getStatType() )){
return $this->{$this->getStatType()}();
}
return $data;
}
protected function meter()
{
$data = array();
if($this->_rows->count() > 0){
foreach($this->_rows as $row){
$data[$this->getStatTitle()][] = (int)$row->value;
}
}
else{
$data[$this->getStatTitle()][] = 0;
}
return $data;
}
protected function pie()
{
$data = array();
if($this->_rows->count() > 0){
foreach($this->_rows as $row){
if($row->value > 0){
$data[$this->getStatTitle()][] = array(ucfirst($this->_translator->translate($row['field'])), round($row['value']));
}
}
}
else{
$data[$this->getStatTitle()][] = array(0);
}
return $data;
}
protected function bar()
{
$data = array();
if($this->_rows->count() > 0){
foreach($this->_rows as $row){
if($row->value > 0){
$data[$this->getStatTitle()][] = array(
'name'=>ucfirst($this->_translator->translate($row['field'])),
'data'=>array((int)$row['value'])
);
}
}
}
else{
$data[$this->getStatTitle()][] = array(0);
}
return $data;
}
}
我想知道是否有更好的方法。
使用
$模型 - >的getData()