PaymentGatewaysSettings.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ gV0fhW3tAm1JDU2OcaLsvebgVrs3+rpIUzgeNrwyL2zrjNe5F4amnF2xUX7SmtkZkn0l9qv/xu9Ekagx1/6w+w==
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * custom fields data table service class
  14. *
  15. * IMPORTANT:
  16. * search serialized custom fields:
  17. * select * from probid_custom_fields_data where value REGEXP '"x"|"y"|"z"';
  18. * (maybe we will serialize all saved data)
  19. */
  20. namespace Ppb\Service;
  21. use Ppb\Db\Table;
  22. class PaymentGatewaysSettings extends AbstractService
  23. {
  24. /**
  25. *
  26. * class constructor
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. $this->setTable(
  32. new Table\PaymentGatewaysSettings());
  33. }
  34. /**
  35. *
  36. * save a row in the payment gateways settings table
  37. *
  38. * @param array $post
  39. * @return $this
  40. * @throws \InvalidArgumentException
  41. */
  42. public function save(array $post)
  43. {
  44. $row = null;
  45. if (empty($post['gateway_id'])) {
  46. throw new \InvalidArgumentException("The 'gateway_id' key is required when saving a payment gateways settings row.");
  47. }
  48. $data = $this->_prepareSaveData($post);
  49. if (array_key_exists('id', $data)) {
  50. $row = $this->findBy('id', $data['id']);
  51. unset($data['id']);
  52. }
  53. else {
  54. $select = $this->getTable()->select()
  55. ->where('name = ?', $data['name'])
  56. ->where('gateway_id = ?', $data['gateway_id']);
  57. if (isset($data['user_id'])) {
  58. $select->where('user_id = ?', $data['user_id']);
  59. }
  60. else {
  61. $select->where('user_id IS NULL');
  62. }
  63. $row = $this->getTable()->fetchRow($select);
  64. }
  65. if (count($row) > 0) {
  66. $this->_table->update($data, "id='{$row['id']}'");
  67. }
  68. else {
  69. $this->_table->insert($data);
  70. }
  71. return $this;
  72. }
  73. }