24 protected $CsvToArray;
27 protected $DbLoanCreator;
30 protected $test_credentials =
'1234';
33 protected $confirmed =
false;
36 protected $num_records = 0;
39 protected $csv_line_count = 0;
45 protected $schema_template = 8;
48 protected $detail_template = [];
51 protected $csv_data = [];
54 protected $success_counts = [];
57 protected $errors = [];
69 ->Set(
'Mapper', $mapper)
70 ->Set(
'CsvToArray', $csv_obj)
71 ->Set(
'DbLoanCreator', $db_obj);
81 while ($this->line !==
'q') {
99 protected function Set($prop, $object) {
101 $this->{$prop} = $object;
112 $handle = fopen (
"php://stdin",
"r");
113 $this->line = trim(fgets($handle));
128 echo
"One moment, generating loan data . . . " . PHP_EOL;
134 This program will now generate {$this->num_records} loan records. 135 Enter y to continue, n to cancel:" . PHP_EOL;
140 Enter q to quit at any time. 141 Enter the number of loan records you would like to generate:" . PHP_EOL;
153 if ($this->line ===
'q') {
154 return "Exiting program . . ." . PHP_EOL;
159 $this->num_records = $this->line;
164 if ($this->line ===
'n') {
165 $this->num_records = 0;
169 $this->confirmed = $this->line ===
'y';
181 return empty($this->line);
190 return $this->num_records > 0;
199 return $this->confirmed ===
true;
211 ->SetDetailTemplate()
225 $this->csv_line_count++;
229 if (isset($data[
'errors']) && (count($data[
'errors']) > 0)) {
235 $this->csv_data[] = $data[
'data'];
248 if ($this->csv_line_count > $this->num_records - 1) {
273 $data = $this->
DbLoanCreator->getList(
'lnappschemadetail',
'loanid', $this->schema_template);
275 $this->detail_template = $data[
'data'];
297 foreach ($this->csv_data as $index => $row) {
305 ->InsertUserLoan($loan_id, $user_id, $row)
306 ->InsertChallengeResponses($user_id);
309 if ($count >= $this->num_records) {
341 $map = $this->Mapper->MasterSchemaMap($row);
347 return $data[
'data'][
'loanid'];
357 $map = $this->Mapper->CreateDetailTemplateMap($loan_id, $this->detail_template);
380 $map_user = $this->Mapper->MapUserLoan($user_id, $loan_id, $row, $data);
395 $rand_resp = $this->Mapper->MapRandomQuestionResponses($user_id, $this->test_credentials);
411 $user_map = $this->Mapper->MapUserData($row, $this->test_credentials);
429 if (isset($data[
'data']) && isset($data[
'data'][
'userid'])) {
430 return $data[
'data'][
'userid'];
442 $plural = ($this->num_records == 1)?
'record' :
'records';
445 Done creating {$this->num_records} loan $plural." .
448 To test users, select returning non member at the loan app 449 screen and log in. All passwords and security questions are 450 answered with '{$this->test_credentials}.'" .
456 When you are done testing, run 'php cleanup-test-records.php' 457 to remove all test records. Type 'q' to exit." .
473 if (count($this->success_counts) > 0) {
474 foreach ($this->success_counts as $table => $count) {
476 $plural = ($count == 1)?
'record' :
'records';
477 $msg .=
"$count $plural inserted for table $table." . PHP_EOL;
493 foreach ($this->errors as $table => $error_arr) {
494 foreach ($error_arr as $str) {
496 $msg .=
"Error for table $table : $str" . PHP_EOL;
510 $this->num_records = 0;
511 $this->confirmed =
false;
523 if (count($response) == 0) {
528 ->UpdateSuccessCounts($response)
529 ->UpdateResponseErrors($response);
541 if ((isset($response[
'success']) && count($response[
'success']) > 0)) {
542 foreach ($response[
'success'] as $table => $count) {
544 if (isset($this->success_counts[$table])) {
545 $this->success_counts[$table] += $response[
'success'][$table];
549 $this->success_counts[$table] = $response[
'success'][$table];
564 if ((isset($response[
'errors']) && count($response[
'errors']) > 0)) {
565 foreach ($response[
'errors'] as $table => $error_arr) {
583 if (! isset($this->errors[$table])) {
584 $this->errors[$table] = [];
587 foreach ($error_arr as $err) {
588 $this->errors[$table][] = $err;
600 return count($this->errors) > 0;
CreateSchemaRecords($row)
UpdateResponses($response=[])
GetLastRecord($table, $keyfield)
InsertChallengeResponses($user_id)
AddNewErrors($table, $error_arr)
CreateDetailSchema($loan_id)
__construct(CsvToArray $csv_obj, DbLoanCreator $db_obj, LoanGeneratorMapper $mapper)
UpdateSuccessCounts($response=[])
InsertUserLoan($loan_id, $user_id, $row)
UpdateResponseErrors($response=[])
GetList($table, $keyfield, $value)