* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_Filler'); /** * Simple datasource filler: Ungap * * @version 0.1.1 * @package WB * @subpackage db */ class WBDatasource_Filler_Ungap extends WBDatasource_Filler { /** * fillers's parameter list * * Concrete classes fill these with default paremeter * @var array */ protected $parameter = array( 'column' => '', 'step' => 1.0, 'fill' => '__EMPTY' ); /** * Last value * @var float */ private $last = 0; /** * Start handler * * Things to do at first item * * @param array $item * @return void */ public function onStart(&$item) { $this->last = floatval($item[$this->parameter['column']]); } /** * actually decorate list item * * @param array $item * @return bool true to continue */ public function mergeItem2List($item, &$list) { $new = floatval($item[$this->parameter['column']]); $gap = $new - $this->last; $step = $this->parameter['step']; $fill = $this->parameter['fill']; switch ($fill) { case '__EMPTY'; $fill = ''; break; case '__NULL'; $fill = null; break; case '__ZERO'; $fill = 0; break; } // no fill needed if ($gap <= $step) { $list = array($item); $this->last = $new; return true; } // fill up gaps $list = array(); $proto = $item; foreach ($proto as $k => &$v) { $v = $fill; } for ($i = $this->last + $step; $i < $new; $i += $step) { $proto[$this->parameter['column']] = $i; $list[] = $proto; } $list[] = $item; $this->last = $new; return true; } }