Skip to content

Commit

Permalink
Format: Intl readable datetime rewrite usages (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
yookoala authored May 17, 2024
1 parent 1cf75e0 commit 974e078
Show file tree
Hide file tree
Showing 63 changed files with 359 additions and 237 deletions.
7 changes: 5 additions & 2 deletions modules/Activities/activities_attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('gibbonPersonID', $session->get('gibbonPersonID'));

if (isActionAccessible($guid, $connection2, '/modules/Activities/report_attendanceExport.php')) {
$form->addHeaderAction('download', __('Export to Excel'))
->setURL('/modules/Activities/report_attendanceExport.php')
Expand Down Expand Up @@ -213,7 +213,10 @@
$i = 0;
foreach ($activitySessions as $sessionDate => $sessionTimestamp) {
$col = $row->addColumn()->addClass('h-24 px-2 text-center');
$dateLabel = $col->addContent(Format::dateReadable($sessionDate, '%a<br>%b %e'))->addClass('w-10 mx-auto whitespace-nowrap');
$dateLabel = $col->addContent(
Format::dateIntlReadable($sessionDate, 'EEE') . '<br>' .
Format::dateIntlReadable($sessionDate, 'MMM d')
)->addClass('w-10 mx-auto whitespace-nowrap');

if (isset($sessionAttendanceData[$sessionDate]['data'])) {
$col->addWebLink(sprintf($icon, __('Edit'), 'config.png'))
Expand Down
9 changes: 7 additions & 2 deletions modules/Activities/report_attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@
echo "<td style='vertical-align:top; width: 50px; white-space: nowrap;'>";
}

printf("<span title='%s'>%s</span><br/>&nbsp;<br/>", $sessionAttendanceData[$sessionDate]['info'], Format::dateReadable($sessionDate, '%a <br /> %b %e'));
printf("<span title='%s'>%s <br/> %s</span><br/>&nbsp;<br/>",
$sessionAttendanceData[$sessionDate]['info'],
Format::dateIntlReadable($sessionDate, 'EEE'),
Format::dateIntlReadable($sessionDate, 'MMM d')
);
} else {
echo "<td style='color: #bbb; vertical-align:top; width: 50px; white-space: nowrap;'>";
echo Format::dateReadable($sessionDate, '%a <br /> %b %e').'<br/>&nbsp;<br/>';
echo Format::dateIntlReadable($sessionDate, 'EEE').' <br/> '.
Format::dateIntlReadable($sessionDate, 'MMM d').'<br/>&nbsp;<br/>';
}
echo '</td>';
}
Expand Down
10 changes: 5 additions & 5 deletions modules/Admissions/admissions_manage_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@
$url = Url::fromModuleRoute('User Admin', 'family_manage_edit')->withAbsoluteUrl();

return !empty($family)
? Format::link($url->withQueryParams(['gibbonFamilyID' => $family['gibbonFamilyID']]), $family['name'])
? Format::link($url->withQueryParams(['gibbonFamilyID' => $family['gibbonFamilyID']]), $family['name'])
: __('This account is not linked to a family.');
});

$table->addColumn('created', __('Created'))->format(Format::using('dateReadable', 'timestampCreated'));
$table->addColumn('created', __('Created'))->format(Format::using('dateIntlReadable', 'timestampCreated'));

$table->addColumn('active', __('Last Active'))->format(Format::using('relativeTime', 'timestampActive'));

$table->addColumn('ipAddress', __('IP Address'));

echo $table->render([$values]);
Expand All @@ -84,10 +84,10 @@
// FORM
$form = Form::create('admissionsManage', $session->get('absoluteURL').'/modules/Admissions/admissions_manage_editProcess.php');
$form->setFactory(DatabaseFormFactory::create($pdo));

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('gibbonAdmissionsAccountID', $gibbonAdmissionsAccountID);

$row = $form->addRow();
$row->addLabel('email', __('Email'));
$row->addEmail('email')
Expand Down
18 changes: 9 additions & 9 deletions modules/Admissions/applicationFormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@
echo $form->getOutput();
return;
}

if ($public && !empty($account['timestampTokenExpire'])) {
echo Format::alert(__('Welcome back! You are accessing this page through a unique link sent to your email address {email}. Please keep this link secret to protect your personal details. This link will expire {expiry}.', ['email' => '<u>'.$account['email'].'</u>', 'expiry' => Format::relativeTime($account['timestampTokenExpire'])]), 'message');
}
}

$page->return->addReturns(['success1' => __('A new admissions account has been created for {email}', ['email' => $account['email'] ?? ''])]);

$formPayment = $container->get(FormPayment::class);

$criteria = $admissionsApplicationGateway->newQueryCriteria(true)
->sortBy('timestampCreated', 'ASC');

Expand All @@ -120,16 +120,16 @@
$table = DataTable::create('submissions');
$table->setTitle(__('Current Applications'));


$table->addColumn('student', __('Applicant'))->format(function ($values) {
return !empty($values['studentSurname'])
? Format::name('', $values['studentPreferredName'], $values['studentSurname'], 'Student')
: Format::small(__('N/A'));
: Format::small(__('N/A'));

});
$table->addColumn('formName', __('Application Form'));
$table->addColumn('status', __('Status'))->translatable();
$table->addColumn('timestampCreated', __('Date'))->width('20%')->format(Format::using('dateTimeReadable', 'timestampCreated'));
$table->addColumn('timestampCreated', __('Date'))->width('20%')->format(Format::using('dateTimeIntlReadable', 'timestampCreated'));

$table->modifyRows(function ($values, $row) {
if ($values['status'] == 'Incomplete') $row->addClass('warning');
Expand Down Expand Up @@ -182,7 +182,7 @@

if (count($forms) == 0) {
return;
}
}

// FORM
$form = Form::create('admissionsAccount', $session->get('absoluteURL').'/index.php?q=/modules/Admissions/applicationForm.php');
Expand All @@ -191,10 +191,10 @@
$form->setDescription((count($submissions) > 0 ? __('You may continue submitting applications with the form below and they will be linked to your account data.').' ' : '').__('Some information has been pre-filled for you, feel free to change this information as needed.'));

$form->setClass('w-full blank');

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('accessID', $account['accessID'] ?? '');

// Display all available public forms
$firstForm = current($forms);
foreach ($forms as $index => $applicationForm) {
Expand Down
12 changes: 6 additions & 6 deletions modules/Admissions/applicationForm_payFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
// APPLICATION PROCESSING FEE
if ($processPaymentRequired) {
$form = Form::create('action', $session->get('absoluteURL').'/modules/Admissions/applicationForm_payFeeProcess.php');

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('accessID', $accessID);
$form->addHiddenValue('gibbonFormID', $gibbonFormID);
Expand Down Expand Up @@ -132,10 +132,10 @@
$row = $form->addRow();
$row->addLabel('statusLabel', __('Status'));
$row->addTextField('status')->readOnly()->setValue($payment['status'] ?? __('Complete'));

$row = $form->addRow();
$row->addLabel('timestampLabel', __('Date Paid'));
$row->addTextField('timestamp')->readOnly()->setValue(Format::dateTimeReadable($payment['timestamp'] ?? ''));
$row->addTextField('timestamp')->readOnly()->setValue(Format::dateTimeIntlReadable($payment['timestamp'] ?? ''));

$row = $form->addRow();
$row->addLabel('gatewayLabel', __('Payment Gateway'));
Expand All @@ -149,7 +149,7 @@
// APPLICATION SUBMISSION FEE
if ($submitPaymentRequired) {
$form = Form::create('action', $session->get('absoluteURL').'/modules/Admissions/applicationForm_payFeeProcess.php');

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('accessID', $accessID);
$form->addHiddenValue('gibbonFormID', $gibbonFormID);
Expand Down Expand Up @@ -177,10 +177,10 @@
$row = $form->addRow();
$row->addLabel('statusLabel', __('Status'));
$row->addTextField('status')->readOnly()->setValue($payment['status'] ?? __('Complete'));

$row = $form->addRow();
$row->addLabel('timestampLabel', __('Date Paid'));
$row->addTextField('timestamp')->readOnly()->setValue(Format::dateTimeReadable($payment['timestamp'] ?? ''));
$row->addTextField('timestamp')->readOnly()->setValue(Format::dateTimeIntlReadable($payment['timestamp'] ?? ''));

$row = $form->addRow();
$row->addLabel('gatewayLabel', __('Payment Gateway'));
Expand Down
4 changes: 2 additions & 2 deletions modules/Admissions/src/Forms/ApplicationMilestonesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function createForm($urlParams, $milestones)
$dateInfo = '';
if ($checked) {
$user = $this->userGateway->getByID($milestonesData[$milestone]['user'], ['preferredName', 'surname']);
$dateInfo = Format::dateReadable($milestonesData[$milestone]['date']).' '.__('By').' '.Format::name('', $user['preferredName'], $user['surname'], 'Staff', false, true);
$dateInfo = Format::dateIntlReadable($milestonesData[$milestone]['date']).' '.__('By').' '.Format::name('', $user['preferredName'], $user['surname'], 'Staff', false, true);
}

$description = '<div class="milestone flex-1 text-left"><span class="milestoneCheck '.($checked ? '' : 'hidden').'">'.$checkIcon.'</span><span class="milestoneCross '.($checked ? 'hidden' : '').'">'.$crossIcon.'</span><span class="text-base leading-normal">'.__($milestone).'</span></div><div class="flex-1 text-left">'.$dateInfo.'</div>';
$col->addCheckbox("milestones[{$milestone}]")
->setValue('Y')
->checked($checked ? 'Y' : 'N')
->checked($checked ? 'Y' : 'N')
->description($description)
->alignRight()
->setLabelClass('w-full flex items-center')
Expand Down
4 changes: 2 additions & 2 deletions modules/Attendance/attendance.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
'currentDate' => $day['currentDate'],
]);
$content =
'<div class="day text-xs">' . Format::dateReadable($day['currentDate'], '%d') . '</div>' .
'<div class="month text-xxs mt-px">' . Format::dateReadable($day['currentDate'], '%b') . '</div>';
'<div class="day text-xs">' . Format::dateIntlReadable($day['currentDate'], 'dd') . '</div>' .
'<div class="month text-xxs mt-px">' . Format::dateIntlReadable($day['currentDate'], 'MMM') . '</div>';
}

// determine how to display link and content
Expand Down
24 changes: 12 additions & 12 deletions modules/Attendance/attendance_future_byPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
$row = $form->addRow()->addClass('multiple');
$row->addLabel('target', __('Target'));
$row->addSelect('target')->fromArray($targetOptions)->required()->selected($target)->placeholder();

$form->toggleVisibilityByClass('targetActivity')->onSelect('target')->when('Activity');
$form->toggleVisibilityByClass('targetMessenger')->onSelect('target')->when('Messenger');
$form->toggleVisibilityByClass('targetSelect')->onSelect('target')->when('Select');
Expand All @@ -139,7 +139,7 @@
$studentList = $studentGateway->queryStudentsBySchoolYear($studentCriteria, $session->get('gibbonSchoolYearID'));
$studentList = array_reduce($studentList->toArray(), function ($group, $student) use ($gibbonPersonIDList) {
$list = in_array($student['gibbonPersonID'], $gibbonPersonIDList) ? 'destination' : 'source';
$group['students'][$list][$student['gibbonPersonID']] = Format::name($student['title'], $student['preferredName'], $student['surname'], 'Student', true) . ' - ' . $student['formGroup'];
$group['students'][$list][$student['gibbonPersonID']] = Format::name($student['title'], $student['preferredName'], $student['surname'], 'Student', true) . ' - ' . $student['formGroup'];
$group['form'][$student['gibbonPersonID']] = $student['formGroup'];
return $group;
});
Expand All @@ -150,7 +150,7 @@
$select->addSortableAttribute(__('Form Group'), $studentList['form']);
$select->source()->fromArray($studentList['students']['source'] ?? []);
$select->destination()->fromArray($studentList['students']['destination'] ?? []);

if (isActionAccessible($guid, $connection2, '/modules/Attendance/attendance_take_byCourseClass.php')) {
$availableAbsenceTypes = [
'full' => __('Full Day'),
Expand All @@ -171,7 +171,7 @@
$row->addTime('timeStart')
->required()
->setValue($timeStart);

$row = $form->addRow()->addClass('partialDateRow');
$row->addLabel('timeEnd', __('End Time'));
$row->addTime('timeEnd')
Expand Down Expand Up @@ -252,7 +252,7 @@
}
});
$table->addColumn('staff', __('Recorded By'))->format(Format::using('name', ['', 'preferredName', 'surname', 'Staff', false, true]));
$table->addColumn('timestamp', __('On'))->format(Format::using('dateTimeReadable', 'timestampTaken', '%R, %b %d'));
$table->addColumn('timestamp', __('On'))->format(Format::using('dateIntlReadable', 'timestampTaken', 'HH:mm, MMM dd'));

$table->addActionColumn()
->addParam('gibbonPersonID', $gibbonPersonIDList[0] ?? '')
Expand Down Expand Up @@ -322,11 +322,11 @@
$checked = array_reduce($classes, function ($group, $class) use ($targetDate, $effectiveStart, $effectiveEnd) {
$classStart = strtotime($targetDate.' '.$class['timeStart']);
$classEnd = strtotime($targetDate.' '.$class['timeEnd']);
if (($classStart >= $effectiveStart && $classStart < $effectiveEnd)
if (($classStart >= $effectiveStart && $classStart < $effectiveEnd)
|| ($effectiveStart >= $classStart && $effectiveStart < $classEnd)) {
$group[] = $class['gibbonCourseClassID'].'-'.$class['gibbonTTDayRowClassID'];
}

return $group;
}, []);

Expand All @@ -336,7 +336,7 @@
$group[] = $class['gibbonCourseClassID'].'-'.$class['gibbonTTDayRowClassID'];
}
}

return $group;
}, []);

Expand All @@ -347,7 +347,7 @@
->alignLeft()
->checked($checked + $disabled)
->disabled($disabled);

} else {
$col->addContent(Format::small(__('N/A')));
}
Expand Down Expand Up @@ -387,7 +387,7 @@
$row->addLabel('periodSelectContainer', __('Periods Absent'));

$table = $row->addTable('periodSelectContainer')->setClass('standardWidth');
$table->addHeaderRow()->addHeading(Format::dateReadable(Format::dateConvert($date),'%B %e, %Y'));
$table->addHeaderRow()->addHeading(Format::dateIntlReadable(Format::dateConvert($date),'MMMM d, yyyy'));

foreach ($classes as $class) {
$name = $class['columnName'] . ' - ' . $class['courseNameShort'] . '.' . $class['classNameShort'];
Expand All @@ -396,7 +396,7 @@
$classStart = strtotime($targetDate.' '.$class['timeStart']);
$classEnd = strtotime($targetDate.' '.$class['timeEnd']);

$checked = (($classStart >= $effectiveStart && $classStart < $effectiveEnd)
$checked = (($classStart >= $effectiveStart && $classStart < $effectiveEnd)
|| ($effectiveStart >= $classStart && $effectiveStart < $classEnd));

$disabled = false;
Expand All @@ -420,7 +420,7 @@
->checked($checked ? $class['gibbonCourseClassID'] : '');
}
} else {

}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/Attendance/attendance_take_byPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
if (empty($log['timestampTaken'])) return Format::small(__('N/A'));

return $currentDate != substr($log['timestampTaken'], 0, 10)
? Format::dateTimeReadable($log['timestampTaken'], '%H:%M, %b %d')
: Format::dateTimeReadable($log['timestampTaken'], '%H:%M');
? Format::dateIntlReadable($log['timestampTaken'], 'HH:mm, MMM dd')
: Format::dateIntlReadable($log['timestampTaken'], 'HH:mm');
});

$table->addColumn('direction', __('Attendance'))
Expand Down
12 changes: 6 additions & 6 deletions modules/Attendance/report_courseClassesNotRegistered_byDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@
//Output row only if not registered on specified date, and timetabled for that day
if (isset($tt[$row['gibbonCourseClassID']]) == true && (isset($log[$row['gibbonCourseClassID']]) == false ||
count($log[$row['gibbonCourseClassID']]) < min(count($lastNSchoolDays), count($tt[$row['gibbonCourseClassID']])) ) ) {

if (!empty($offTimetableList[$row['gibbonCourseClassID']]) && (($dateStart == $dateEnd && $offTimetableList[$row['gibbonCourseClassID']][$dateStart] == true) || count(array_filter($offTimetableList[$row['gibbonCourseClassID']])) == count($lastNSchoolDays))) {
continue;
}

++$count;

//COLOR ROW BY STATUS!
Expand Down Expand Up @@ -239,12 +239,12 @@
echo "<td class='$class' style='padding: 12px !important;' title='{$title}'>";
if ($link != '') {
echo "<a href='$link'>";
echo Format::dateReadable($date, '%d').'<br/>';
echo "<span>".Format::dateReadable($date, '%b').'</span>';
echo Format::dateIntlReadable($date, 'dd').'<br/>';
echo "<span>".Format::dateIntlReadable($date, 'MMM').'</span>';
echo '</a>';
} else {
echo Format::dateReadable($date, '%d').'<br/>';
echo "<span>".Format::dateReadable($date, '%b').'</span>';
echo Format::dateIntlReadable($date, 'dd').'<br/>';
echo "<span>".Format::dateIntlReadable($date, 'MMM').'</span>';
}
echo '</td>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
}

echo "<td class='$class' style='padding: 12px !important;'>";
echo Format::dateReadable($lastNSchoolDays[$i], '%d').'<br/>';
echo "<span>".Format::dateReadable($lastNSchoolDays[$i], '%b').'</span>';
echo Format::dateIntlReadable($lastNSchoolDays[$i], 'dd').'<br/>';
echo "<span>".Format::dateIntlReadable($lastNSchoolDays[$i], 'MMM').'</span>';
echo '</td>';

// Wrap to a new line every 10 dates
Expand Down
Loading

0 comments on commit 974e078

Please sign in to comment.