Guest User

Untitled

a guest
Oct 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /**
  2.  
  3. // request goes to submit tribes...
  4.  
  5. // idea is to have one function call that does everything...
  6. $feedback_after_submission_service = new FeedbackAfterSubmission($tribe_ids);
  7. $scenario_data = $feedback_after_submission_service->getScenario($tribe_ids);
  8.  
  9. // Possible workflow
  10. Step 1: Find out which scenarios are true
  11. Step 2: Randomly choose a scenario
  12. Step 3: For randomly chosen scenario, filter all_data from the sql queries
  13. Step 4: Return scenario validity per tribe + all_data to front-end
  14. Step 5: In AJAX response, send response to React
  15. Step 6: Store Data in React State
  16. Step 7: Container View determines which scenario to display
  17. */
  18.  
  19. // example functions in the service class
  20. class FeedbackAfterSubmissionService
  21. {
  22. const SCENARIO_1 = 'scenario_1';
  23. const SCENARIO_1_VALIDATOR = 'scenario_1_validator';
  24.  
  25. public function __construct (
  26. array $tribe_ids
  27. )
  28. {
  29. $this->tribe_ids = $tribe_ids;
  30.  
  31. $this->scenario_validators = [
  32. $this->scenario_1 => $this->scenario_1_validator
  33. ]
  34.  
  35. $this->valid_scenarios = [];
  36. }
  37.  
  38. // this is the main function that gets called by the calling class
  39. public function getScenario ()
  40. {
  41. $valid_scenarios = $this->validateScenarios($tribe_ids);
  42. $chosen_scenario = $this->getRandomlyChosenScenario(array_keys($valid_scenarios));
  43. $scenario_data_per_tribe_id = $this->getScenarioDataPerTribeId(
  44. array_values($valid_scenarios)
  45. );
  46.  
  47. return [
  48. 'chosen_scenario' => $chosen_scenario,
  49. 'scenario_data_per_tribe_id' => $scenario_data_per_tribe_id,
  50. ]
  51. }
  52.  
  53. private function getRandomlyChoosenScenario($valid_scenarios)
  54. {
  55. $random_index = rand(0, sizeof($valid_scenarios) - 1);
  56. return $valid_scenarios[$random_index];
  57. }
  58.  
  59. private function validateScenarios ()
  60. {
  61. foreach($this->scenario_validators as $scenario => $scenario_validator) {
  62. $valid_tribe_ids_for_scenario = $scenario_validator();
  63.  
  64. if (sizeof($valid_tribe_ids_for_scenario) > 0) {
  65. $valid_scenarios[$scenario] = $valid_tribe_ids_for_scenario;
  66. }
  67. }
  68. }
  69.  
  70. private function validateScenario1 ()
  71. {
  72. $valid_scenarios = [];
  73. foreach($this->tribe_ids as $tribe_id) {
  74. // conditional
  75. }
  76.  
  77. return $valid_scenarios;
  78. }
  79. }
Add Comment
Please, Sign In to add comment