setTable( new Table\PaymentGatewaysSettings()); } /** * * save a row in the payment gateways settings table * * @param array $post * @return $this * @throws \InvalidArgumentException */ public function save(array $post) { $row = null; if (empty($post['gateway_id'])) { throw new \InvalidArgumentException("The 'gateway_id' key is required when saving a payment gateways settings row."); } $data = $this->_prepareSaveData($post); if (array_key_exists('id', $data)) { $row = $this->findBy('id', $data['id']); unset($data['id']); } else { $select = $this->getTable()->select() ->where('name = ?', $data['name']) ->where('gateway_id = ?', $data['gateway_id']); if (isset($data['user_id'])) { $select->where('user_id = ?', $data['user_id']); } else { $select->where('user_id IS NULL'); } $row = $this->getTable()->fetchRow($select); } if (count($row) > 0) { $this->_table->update($data, "id='{$row['id']}'"); } else { $this->_table->insert($data); } return $this; } }