Guest User

Untitled

a guest
Oct 15th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. class Validation extends Fuel\Core\Validation{
  4.  
  5. public static function _validation_unique($val, $options)
  6. {
  7. list($table, $field) = explode('.', $options);
  8.  
  9. $result = DB::select(strtolower($field))
  10. ->where($field, '=', Str::lower($val))
  11. ->from($table)->execute('default');
  12.  
  13. Validation::active()->set_message('unique', ':label must be unique.');
  14.  
  15. return ! ($result->count() > 0);
  16. }
  17.  
  18. public static function _validation_billing_address($val)
  19. {
  20. if(empty($val['inactive']))
  21. {
  22.  
  23. if(empty($val['add1']))
  24. {
  25. Validation::active()->set_message('billing_address', 'The field Address is required for :label');
  26. return false;
  27. }
  28.  
  29. if(empty($val['city']))
  30. {
  31. Validation::active()->set_message('billing_address', 'The field City is required for :label');
  32. return false;
  33. }
  34.  
  35. if(empty($val['code']))
  36. {
  37. Validation::active()->set_message('billing_address', 'The field Postcode is required for :label');
  38. return false;
  39. }
  40.  
  41. if(empty($val['country']))
  42. {
  43. Validation::active()->set_message('billing_address', 'The field Country is required for :label');
  44. return false;
  45. }
  46. }
  47.  
  48. return true;
  49. }
  50.  
  51. public static function _validation_currency($val)
  52. {
  53. if(!empty($val))
  54. {
  55. if(!is_numeric($val) && !preg_match('/\b\d{1,3}(?:,?\d{3})*(?:\.\d{2})?\b/', $val))
  56. {
  57. Validation::active()->set_message('currency', 'The field :label currency format is invalid');
  58. return false;
  59. }
  60. }
  61.  
  62. return true;
  63. }
  64.  
  65. public static function _validation_location($val)
  66. {
  67. if(empty($val['add1']))
  68. {
  69. Validation::active()->set_message('location', 'The Address field is required for :label');
  70. return false;
  71. }
  72.  
  73. if(empty($val['city']))
  74. {
  75. Validation::active()->set_message('location', 'The Town / City field is required for :label');
  76. return false;
  77. }
  78.  
  79. if(empty($val['code']))
  80. {
  81. Validation::active()->set_message('location', 'The Postal / Zip code field is required for :label');
  82. return false;
  83. }
  84.  
  85. if(empty($val['country']))
  86. {
  87. Validation::active()->set_message('location', 'The Country field is required for :label');
  88. return false;
  89. }
  90.  
  91. return true;
  92. }
  93. }
Add Comment
Please, Sign In to add comment