#!/usr/bin/php * @version 1.0 * @since 01 Dec 2014 10:27:35 */ /******************************************************************** * CONFIG ********************************************************************/ define('_CLI', true); require realpath(dirname(__FILE__) . '/../app/_config.inc.php'); require_once 'models/Account.inc.php'; require_once 'models/User.inc.php'; require_once 'models/Survey.inc.php'; require_once 'models/Question.inc.php'; require_once 'models/Participant.inc.php'; require_once 'models/Response.inc.php'; $app->setParam(array( 'log_screen_priority' => LOG_INFO, 'log_file_priority' => LOG_NOTICE, 'error_reporting' => E_ALL, )); /******************************************************************** * MAIN ********************************************************************/ $num_accounts = 2; $num_surveys_per_account = 3; // $num_questions_per_survey = 5; $num_participants_per_survey = 3; for ($a=1; $a <= $num_accounts; $a++) { // Create account. $accounts[$a]['account_id'] = Account::insert(Account::merge(array( 'organization' => "My Org $a", 'status' => 'pending', 'available_credit' => '5.00', 'recharge_amount' => '10.00', ))); // Create primary user. $users[$a]['user_id'] = User::insert(User::merge(array( 'account_id' => $accounts[$a]['account_id'], 'username' => "bob$a", 'first_name' => "Bob $a", 'last_name' => "Jones", 'user_type' => 'primary', 'status' => 'email confirmed', ))); $acl->addRequestObject('user_id:' . $users[$a]['user_id'], ('1' == $users[$a]['user_id'] ? 'internal:engineering' : 'general')); printf("Created user %s in account %s\n", $users[$a]['user_id'], $accounts[$a]['account_id']); for ($s=1; $s <= $num_surveys_per_account; $s++) { $s_c = ((($a * $num_surveys_per_account) - $num_surveys_per_account) + $s); // Create survey. $surveys[$s_c]['survey_id'] = Survey::insert(Survey::merge(array( 'account_id' => $accounts[$a]['account_id'], 'survey_name' => "Test Survey $s_c" , 'begin_datetime' => date('Y-m-d', time() + 1000 * $s_c), 'end_datetime' => date('Y-m-d', time() + 432000), 'status' => 'queued', 'virtual_number' => "+100000$s_c", ))); printf("Created survey %s\n", $surveys[$s_c]['survey_id']); $num_questions_per_survey = mt_rand(3, 15); for ($q=1; $q <= $num_questions_per_survey; $q++) { $q_c = ((($s_c * $num_questions_per_survey) - $num_questions_per_survey) + $q); // Create questions. $q_json = json_decode(file_get_contents("http://www.randomtext.me/api/gibberish/p-1/5-10")); $q_text = str_replace(".", "?", trim(strip_tags($q_json->text_out))); if ($q % 2 == 0) { $q_text .= " A) Yes B) No"; } else if ($q % 3 == 0) { $q_text .= " A] Chocolate B] Strawberry C] Mint D] Bacon"; } $questions[$q_c]['question_id'] = Question::insert(Question::merge(array( 'account_id' => $accounts[$a]['account_id'], 'survey_id' => $surveys[$s_c]['survey_id'], 'rank' => $q_c, 'question_text' => $q_text, ))); printf("Created question %s\n", $questions[$q_c]['question_id']); } for ($p=1; $p <= $num_participants_per_survey; $p++) { $p_c = ((($s_c * $num_participants_per_survey) - $num_participants_per_survey) + $p); // Create participant. $participants[$p_c]['participant_id'] = Participant::insert(Participant::merge(array( 'account_id' => $accounts[$a]['account_id'], 'survey_id' => $surveys[$s_c]['survey_id'], 'phone' => "+2000000$p_c", 'status' => 'active', 'source' => 'imported', ))); Survey::addParticipant($participants[$p_c]['participant_id'], $surveys[$s_c]['survey_id'], 'active'); printf("Created participant %s\n", $participants[$p_c]['participant_id']); // Each participant responds to all questions in survey. for ($r=1; $r <= $num_questions_per_survey; $r++) { $r_c = ((($s_c * $num_questions_per_survey) - $num_questions_per_survey) + $r); if ($r % 2 == 0) { $q_text .= " A) Yes B) No"; $r_options = array("A"=>"Yes","B"=>"No"); $r_keys = array_keys($r_options); $r_text = $r_keys[mt_rand(0, sizeof($r_options) - 1)]; } else if ($r % 3 == 0) { $r_options = array("A"=>"Chocolate","B"=>"Strawberry","C"=>"Mint","D"=>"Bacon"); $r_keys = array_keys($r_options); $r_text = $r_keys[mt_rand(0, sizeof($r_options) - 1)]; } else { $r_json = json_decode(file_get_contents("http://www.randomtext.me/api/gibberish/p-1/1-12")); $r_text = str_replace(".", "", trim(strip_tags($r_json->text_out))); } // Create response. $responses[$r_c]['response_id'] = Response::insert(Response::merge(array( 'account_id' => $accounts[$a]['account_id'], 'participant_id' => $participants[$p_c]['participant_id'], 'question_id' => $questions[$r_c]['question_id'], 'response' => $r_text, 'added_datetime' => date('Y-m-d H:i:s', time() - mt_rand(0, 2678400)), ))); printf("Created response %s for participant %s to question %s in survey %s\n", $r_c, $participants[$p_c]['participant_id'], $questions[$r_c]['question_id'], $surveys[$s_c]['survey_id']); } } } }