Skip to content

Commit

Permalink
Eliminate array_merge when calculating examAttempts.
Browse files Browse the repository at this point in the history
Part 1 of a performance overhaul.
  • Loading branch information
Jonhasacat committed Jun 6, 2024
1 parent 6167fb0 commit 7d95f4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
26 changes: 12 additions & 14 deletions app/Http/Controllers/MgtController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,26 @@ public function getController(Request $request, $cid = null)
$c1AssignmentDate = $moodle->getUserEnrolmentTimestamp($uid, config('exams.C1.enrolId'));

$examAttempts = [
'Basic ATC/S1 Exam' => array_merge([
'Basic ATC/S1 Exam' => [
'examInfo' => config('exams.BASIC'),
'assignDate' => $basicAssignmentDate ?
Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false
], ['attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)]),
'S2 Rating (TWR) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)],
'S2 Rating (TWR) Controller Exam' => [
'examInfo' => config('exams.S2'),
'assignDate' => $s2AssignmentDate ?
Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false
], ['attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)]),
'S3 Rating (DEP/APP) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)],
'S3 Rating (DEP/APP) Controller Exam' => [
'examInfo' => config('exams.S3'),
'assignDate' => $s3AssignmentDate ?
Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false
],
['attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)]),
'C1 Rating (CTR) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)],
'C1 Rating (CTR) Controller Exam' => [
'examInfo' => config('exams.C1'),
'assignDate' => $c1AssignmentDate ?
Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false
],
['attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)]),
Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)],
];

$assignedRoles = RoleHelperV2::assignedRoles($cid);
Expand Down
26 changes: 12 additions & 14 deletions app/Http/Controllers/MyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,26 @@ public function getProfile(Request $request) {
config('exams.C1.enrolId'));

$examAttempts = [
'Basic ATC/S1 Exam' => array_merge([
'Basic ATC/S1 Exam' => [
'examInfo' => config('exams.BASIC'),
'assignDate' => $basicAssignmentDate ?
Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false
], ['attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)]),
'S2 Rating (TWR) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)],
'S2 Rating (TWR) Controller Exam' => [
'examInfo' => config('exams.S2'),
'assignDate' => $s2AssignmentDate ?
Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false
], ['attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)]),
'S3 Rating (DEP/APP) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)],
'S3 Rating (DEP/APP) Controller Exam' => [
'examInfo' => config('exams.S3'),
'assignDate' => $s3AssignmentDate ?
Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false
],
['attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)]),
'C1 Rating (CTR) Controller Exam' => array_merge([
Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)],
'C1 Rating (CTR) Controller Exam' => [
'examInfo' => config('exams.C1'),
'assignDate' => $c1AssignmentDate ?
Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false
],
['attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)]),
Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false,
'attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)],
];

return view('my.profile',
Expand Down

0 comments on commit 7d95f4f

Please sign in to comment.