12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Ppb\Service;
- use Ppb\Db\Table;
- class PaymentGatewaysSettings extends AbstractService
- {
-
- public function __construct()
- {
- parent::__construct();
- $this->setTable(
- new Table\PaymentGatewaysSettings());
- }
-
- 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;
- }
- }
|