* @license PHP License * @package WB * @subpackage eventHandler */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Table'); /** * WBEvent_Handler_Table_Loader * * @version 0.2.0 * @package Wombat * @subpackage eventHandler */ class WBEvent_Handler_Table_Loader extends WBEvent_Handler_Table { /** * Handler Config * * - table name of table to update * - key primary key of row to update * - keyindex data index where to achieve the primary key from * - target name of event's data array to fill with table values * - prefix merge loaded data with event data using prefix * * @var array */ protected $config = array( 'table' => '', 'key' => '', 'keyindex' => 'id', 'target' => '', 'prefix' => '' ); /** * Load Data from Table * * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $key = $this->get4ConfigOrData($e, 'key', true); $this->startTable(); $data = $this->table->get($this->config['table'], $key); if (1 != count($data)) { return false; } $data = $data[0]; // store in target if (!empty($this->config['target'])) { $e->set($this->config['target'], $data); return true; } // merge with event data foreach ($data as $k => $v) { if (!empty($this->config['prefix'])) { $k = $this->config['prefix'] . $k; } $e->set($k, $v); } return true; } }