0 ) { try { parent::__construct( 'tagente_estado', ['id_agente_modulo' => $id_agent_module] ); } catch (\Exception $e) { throw new \Exception( __METHOD__.' error: Status not found for module '.$id_agent_module ); } } else { // Create empty skel. parent::__construct('tagente_estado'); } } /** * Saves current definition to database. * * @return mixed Affected rows of false in case of error. * @throws \Exception On error. */ public function save() { if ($this->fields['id_agente_modulo'] > 0) { // Update. $updates = $this->fields; $rs = \db_process_sql_update( 'tagente_estado', $updates, ['id_agente_modulo' => $this->fields['id_agente_modulo']] ); if ($rs === false) { global $config; throw new \Exception( __METHOD__.' error: '.$config['dbconnection']->error ); } } else { // Creation. $updates = $this->fields; // Clean null fields. foreach ($updates as $k => $v) { if ($v === null) { unset($updates[$k]); } } $rs = \db_process_sql_insert( 'tagente_estado', $updates ); if ($rs === false) { global $config; throw new \Exception( __METHOD__.' error: '.$config['dbconnection']->error ); } $this->fields['id_agente_modulo'] = $rs; } return true; } }