Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public function applyBonus($id) {
  2. //TODO(): Check if bonus exists
  3.  
  4. $bonus = Bonus::find($id);
  5. //TODO():: Check if bonus has elements
  6.  
  7. foreach($bonus->elements as $element) {
  8. //TODO():: Check if element has constraints
  9.  
  10. foreach($element->constraints as $constraint) {
  11. if (number_format($constraint->probability * 100, 0) >= rand(1, 100)) {
  12. //Constraint has effect
  13. //Check if user passes this constraint
  14.  
  15. switch ($constraint->relation) {
  16. case '<':
  17.  
  18. if(Auth::user()->attribute($constraint->attribute_code) < $constraint->value) {
  19. //User passes constraint, move on to the next constrain
  20. continue;
  21. } else {
  22. //User didn't pass the constraint, move on to the next element
  23. break;
  24. }
  25.  
  26. break;
  27. case '<=':
  28.  
  29. if(Auth::user()->attribute($constraint->attribute_code) <= $constraint->value) {
  30. continue;
  31. } else {
  32. break;
  33. }
  34.  
  35.  
  36. break;
  37. case '=':
  38.  
  39. if(Auth::user()->attribute($constraint->attribute_code) = $constraint->value) {
  40. continue;
  41. } else {
  42. break;
  43. }
  44.  
  45. break;
  46. case '>=':
  47.  
  48. if(Auth::user()->attribute($constraint->attribute_code) >= $constraint->value) {
  49. continue;
  50. } else {
  51. break;
  52. }
  53.  
  54. break;
  55. case '>':
  56.  
  57. if(Auth::user()->attribute($constraint->attribute_code) > $constraint->value) {
  58. continue;
  59. } else {
  60. break;
  61. }
  62.  
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement