diff options
author | Romain d'Alverny <rda@mageia.org> | 2011-05-04 13:26:54 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2011-05-04 13:26:54 +0000 |
commit | d08c07b68d0e88d863f597fe5e9ed72d84229ab7 (patch) | |
tree | 30b86dbcb4af35e87f2a76c637a214583022a0db /Report/Box.php | |
parent | 25cbfbccf63d176683a3da50913679cab311e21c (diff) | |
download | dashboard-d08c07b68d0e88d863f597fe5e9ed72d84229ab7.tar dashboard-d08c07b68d0e88d863f597fe5e9ed72d84229ab7.tar.gz dashboard-d08c07b68d0e88d863f597fe5e9ed72d84229ab7.tar.bz2 dashboard-d08c07b68d0e88d863f597fe5e9ed72d84229ab7.tar.xz dashboard-d08c07b68d0e88d863f597fe5e9ed72d84229ab7.zip |
initial import
Diffstat (limited to 'Report/Box.php')
-rw-r--r-- | Report/Box.php | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/Report/Box.php b/Report/Box.php new file mode 100644 index 0000000..79408a0 --- /dev/null +++ b/Report/Box.php @@ -0,0 +1,235 @@ +<?php +/** + * Abstract box class for reports. + * + * PHP version 5 + * + * @category Dashboard + * @package Buildsystem + * @author Romain d'Alverny <rda@mageia.org> + * @license MIT License, see LICENSE.txt + * @link http://svnweb.mageia.org/svn/soft/dashboard/ +*/ + +/** +*/ +abstract class Report_Box +{ + /** + */ + var $title = null; + + /** + */ + var $_new_values = null; + + /** + */ + var $working = false; + + /** + */ + function __construct() + { + $this->_labels = array_merge(array('?' => '%s %s'), + $this->_get_var_definitions()); + } + + /** + */ + final public function run_report() + { + $path = realpath(dirname(__FILE__)); + $files = glob(sprintf('%s/Box/*.php', $path)); + + foreach ($files as $f) { + if (substr(basename($f), 0, 7) != 'ignore_') + include $f; + } + + $reports = array(); + foreach (get_declared_classes() as $class) { + if (is_subclass_of($class, 'Report_Box')) { + echo $class, "\n"; + $c = new $class; + $reports[] = $c->render(); + } + } + + file_put_contents('report.html', Report_HTML::render($reports)); + } + + /** + * lowercase keys! + */ + final public function update() + { + $this->_get_new_values(); + $this->_db_save($this->_new_values); + } + + /** + */ + function render () + { + $this->load(); + + // associate key/values with string labels + // compute global statuts + // push + $status = count($this->_new_values); + $status_max = count($this->_new_values); + $links = $this->_get_links(); + $values = array(); + + $this->_tmp_labels = $this->_labels; + if (is_null($this->_new_values)) + $this->_new_values = array(); + + foreach ($this->_tmp_labels as $k => $v) { + //foreach ($this->_new_values as $k => $v) { + if ($k == '?') + continue; + + $v = $this->_render_value_gen($k); + + $status -= $v['s']; + $values[] = $v; + } + + if (count($this->_tmp_labels) > 0) { + foreach ($this->_tmp_labels as $k => $v) { + if ($k == '?') + continue; + + $values[] = $this->_render_value_gen($k); + } + } + + echo $status / $status_max; + + return array( + 'title' => $this->title, + 'status' => $status_max > 0 ? round($status / $status_max, 2) : 0, + 'values' => $values, + 'links' => $links + ); + } + + /** + */ + final private function _render_value_gen($k = null) + { + if (array_key_exists($k, $this->_tmp_labels)) { + + if ($this->_tmp_labels[$k] == ':render') { + $this->_cur_val = isset($this->_new_values[$k]) ? $this->_new_values[$k] : null; + $v = call_user_func(array($this, '_render_value_' . $k)); + unset($this->_cur_val); + } else { + $v = $this->_render_value_default($k, $this->_tmp_labels[$k]); + } + } else { + $v = $this->_render_value_default($k); + } + unset($this->_tmp_labels[$k]); + + return $v; + } + + /** + */ + final private function _render_value_default($k = null, $format = null) + { + $score = 0; + $class = 'unk'; + $weight = 1; + $test_case = null; + + if (is_null($format)) { + $format = '%s %s'; + } elseif (!is_string($format)) { + $test_case = $format['t']; + $format = $format['l']; + $weight = isset($format['w']) ? $format['w'] : $weight; + } + + $v = isset($this->_new_values[$k]) ? $this->_new_values[$k] : null; + if (!is_null($v)) { + if (!is_null($test_case)) { + $test_case = sprintf('$evalres = ($v %s);', $test_case); + eval($test_case); + + $class = $evalres === true ? 'ok' : 'failed'; + } else { + $class = 'ok'; + } + } else { + $class = 'unk'; + } + + if ($class == 'failed') + $score = -1; + elseif ($class == 'ok') + $score = 1; + + $score *= $weight; + + return array( + 't' => sprintf($format, $v, $k), + 'c' => $class, + 's' => $score + ); + } + + /** + */ + final public function load() + { + // go in table TABLE, load all most recent key/values + // + // TODO(rda) + $this->_get_new_values(); + $this->_values = array(); + } + + /** + */ + final private function _db_save($vals) + { + echo "Saving:\n"; + echo get_class($this),"\n"; + print_r($vals); + } + + /** + */ + final private function _get_new_values() + { + $values = null; + $methods = array(); + foreach (get_class_methods($this) as $m) { + if (substr($m, 0, 7) == '_fetch_') { + $methods[] = $m; + } + } + if (count($methods) == 0) { + echo '> Nothing to fetch.', "\n"; + } else { + $values = array(); + foreach ($methods as $m) { + echo sprintf("> Calling [%s]", $m), "\n"; + $values = array_merge($values, $this->$m()); + } + } + + $this->_new_values = $values; + } + + /** + */ + function _get_links() + { + return null; + } +}
\ No newline at end of file |