Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- // request goes to submit tribes...
- // idea is to have one function call that does everything...
- $feedback_after_submission_service = new FeedbackAfterSubmission($tribe_ids);
- $scenario_data = $feedback_after_submission_service->getScenario($tribe_ids);
- // Possible workflow
- Step 1: Find out which scenarios are true
- Step 2: Randomly choose a scenario
- Step 3: For randomly chosen scenario, filter all_data from the sql queries
- Step 4: Return scenario validity per tribe + all_data to front-end
- Step 5: In AJAX response, send response to React
- Step 6: Store Data in React State
- Step 7: Container View determines which scenario to display
- */
- // example functions in the service class
- class FeedbackAfterSubmissionService
- {
- const SCENARIO_1 = 'scenario_1';
- const SCENARIO_1_VALIDATOR = 'scenario_1_validator';
- public function __construct (
- array $tribe_ids
- )
- {
- $this->tribe_ids = $tribe_ids;
- $this->scenario_validators = [
- $this->scenario_1 => $this->scenario_1_validator
- ]
- $this->valid_scenarios = [];
- }
- // this is the main function that gets called by the calling class
- public function getScenario ()
- {
- $valid_scenarios = $this->validateScenarios($tribe_ids);
- $chosen_scenario = $this->getRandomlyChosenScenario(array_keys($valid_scenarios));
- $scenario_data_per_tribe_id = $this->getScenarioDataPerTribeId(
- array_values($valid_scenarios)
- );
- return [
- 'chosen_scenario' => $chosen_scenario,
- 'scenario_data_per_tribe_id' => $scenario_data_per_tribe_id,
- ]
- }
- private function getRandomlyChoosenScenario($valid_scenarios)
- {
- $random_index = rand(0, sizeof($valid_scenarios) - 1);
- return $valid_scenarios[$random_index];
- }
- private function validateScenarios ()
- {
- foreach($this->scenario_validators as $scenario => $scenario_validator) {
- $valid_tribe_ids_for_scenario = $scenario_validator();
- if (sizeof($valid_tribe_ids_for_scenario) > 0) {
- $valid_scenarios[$scenario] = $valid_tribe_ids_for_scenario;
- }
- }
- }
- private function validateScenario1 ()
- {
- $valid_scenarios = [];
- foreach($this->tribe_ids as $tribe_id) {
- // conditional
- }
- return $valid_scenarios;
- }
- }
Add Comment
Please, Sign In to add comment