* @license PHP License * @package WB * @subpackage eventHandler */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Table'); /** * WBEvent_Handler_Table_Saver * * @version 0.1.0 * @package Wombat * @subpackage eventHandler */ class WBEvent_Handler_Table_Saver 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 * - field list of columes to copy data from event * - static additionals static values * * @var array */ protected $config = array( 'table' => '', 'key' => '__new', 'keyindex' => '', 'field' => array(), 'static' => array(), 'dbconfig' => '' ); /** * List of Required Configuration Parmaters * * @var array */ protected $configRequired = array('table'); /** * Save Record in Table * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { $this->verifyConfig(); $key = $this->get4ConfigOrData($e, 'key', true); $save = array(); foreach ($this->config['field'] as $k) { $save[$k] = $e->get($k, ''); } foreach ($this->config['static'] as $k => $v) { $save[$k] = $v; } // nothing to save if (empty($save)) { return true; } $this->startTable(); $id = $this->table->save($this->config['table'], $key, $save); $e->set('id', $id); return true; } }