* @license PHP License * @package WB * @subpackage eventHandler */ WBClass::load('WBEvent_Handler' , 'WBEvent_Handler_Table'); /** * WBEvent_Handler_Table_Saver * * @version 0.2.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(), ); /** * Update Column(s) in Table * * Update one or more column in one table for one row using primary key * Hence primary key is required, as well as column(s) and table name. * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { if (empty($this->config['field'])) { WBClass::load('WBException_Config'); throw new WBException_Config('List of fields must not be empty!', 1, __CLASS__); return false; } $key = $this->getKey4Config($e); $save = array(); foreach ($this->config['field'] as $k) { $save[$k] = $e->get($k, ''); } foreach ($this->config['static'] as $k => $v) { $save[$k] = $v; } $id = $this->table->save($this->config['table'], $key, $save); $e->set('id', $id); return true; } }