PaymentMethods.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ ZOTkwQJimfcxGWFLFVorDN6BPim4TowHxuLl3y3q9ZE=
  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.2
  11. */
  12. /**
  13. * listing payment methods validator class
  14. */
  15. namespace Ppb\Validate;
  16. use Cube\Validate\AbstractValidate,
  17. Cube\Controller\Front;
  18. class PaymentMethods extends AbstractValidate
  19. {
  20. protected $_message = "You must select at least one method of payment.";
  21. protected $_keys = array(
  22. 'direct_payment', 'offline_payment'
  23. );
  24. /**
  25. *
  26. * set request keys array
  27. *
  28. * @param array $keys
  29. */
  30. public function setKeys($keys)
  31. {
  32. $this->_keys = $keys;
  33. }
  34. /**
  35. * get request keys array
  36. *
  37. * @return array
  38. */
  39. public function getKeys()
  40. {
  41. return $this->_keys;
  42. }
  43. /**
  44. *
  45. * checks at least one method of payment has been selected
  46. *
  47. * @return bool return true if the validation is successful
  48. */
  49. public function isValid()
  50. {
  51. $request = Front::getInstance()->getRequest();
  52. $values = array();
  53. foreach ($this->_keys as $key) {
  54. $array = $request->getParam($key);
  55. if (is_array($array)) {
  56. $values = array_merge($values, $request->getParam($key));
  57. }
  58. else if (is_string($array)) {
  59. $values[] = $array;
  60. }
  61. }
  62. $values = array_filter($values);
  63. if (count($values) > 0) {
  64. return true;
  65. }
  66. return false;
  67. }
  68. }