Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function applyBonus($id) {
- //TODO(): Check if bonus exists
- $bonus = Bonus::find($id);
- //TODO():: Check if bonus has elements
- foreach($bonus->elements as $element) {
- //TODO():: Check if element has constraints
- foreach($element->constraints as $constraint) {
- if (number_format($constraint->probability * 100, 0) >= rand(1, 100)) {
- //Constraint has effect
- //Check if user passes this constraint
- switch ($constraint->relation) {
- case '<':
- if(Auth::user()->attribute($constraint->attribute_code) < $constraint->value) {
- //User passes constraint, move on to the next constrain
- continue;
- } else {
- //User didn't pass the constraint, move on to the next element
- break;
- }
- break;
- case '<=':
- if(Auth::user()->attribute($constraint->attribute_code) <= $constraint->value) {
- continue;
- } else {
- break;
- }
- break;
- case '=':
- if(Auth::user()->attribute($constraint->attribute_code) = $constraint->value) {
- continue;
- } else {
- break;
- }
- break;
- case '>=':
- if(Auth::user()->attribute($constraint->attribute_code) >= $constraint->value) {
- continue;
- } else {
- break;
- }
- break;
- case '>':
- if(Auth::user()->attribute($constraint->attribute_code) > $constraint->value) {
- continue;
- } else {
- break;
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement