php js css php js css

Changes

Changes to Script: Prepare worked hours and salaried teacher visibility examples


System
Change
Can't Undo: The change does not exist
246076
Today 4:33am
McNaught, Scott
Created script
Id:
XrSbJTYMaTQj68ME
Title:
Prepare worked hours and salaried teacher visibility examples
Last Run:

														
													
													
													
												
Created:
2026-10-08 01:00:53
Is Ai Generated:
1
Is Readonly:
1
Modified:
2026-10-08 01:00:53
Contact Id:
-2
Code:
<?php
$out = [];
foreach ([376,377,378] as $courseId) {
foreach (\Components\AF\Courses\Units::getAllForCourse($courseId) as $unit) {
if ($unit['unit_date'] < '2026-10-08') \Components\AF\Courses\Units::save(['unit_id' => $unit['unit_id'], 'unit_teacher_present' => 1]);
}
}
$rows = \Components\Customers\Contacts::getAll(['filter' => ['contact_email', '=', 'af-presentation-robin@example.invalid'], 'limit' => 1]);
$out['hidden_teacher'] = $rows ? reset($rows)['contact_id'] : \Components\Customers\Contacts::save(['contact_email' => 'af-presentation-robin@example.invalid', 'contact_first_name' => 'Robin', 'contact_last_name' => 'Salaried - Presentation Demo', 'contact_type' => 'Individual', 'contact_email_marketing_status' => 'unsubscribed', 'country_id' => 'AUS']);
\Components\Customers\Groups::addContactToGroup($out['hidden_teacher'], ['/teachers/']);
\Components\AF\Teachers::setIsHiddenFromHoursReport($out['hidden_teacher'], true);
$rows = \Components\AF\Teachers\Hours::getAll(['filter' => ['hour_comment', '=', 'Presentation Demo - salaried teacher work'], 'limit' => 1]);
if (!$rows) \Components\AF\Teachers\Hours::save(['hour_comment' => 'Presentation Demo - salaried teacher work', 'teacher_id' => $out['hidden_teacher'], 'hour_type_id' => 32, 'hour_date' => '2026-10-06', 'hour_start_time' => '11:00:00', 'hour_end_time' => '12:00:00', 'hour_billing_status' => 'unpaid']);
$hours = \Components\AF\Teachers\Hours::getFilteredHours(['teacher_id' => 1393, 'date_from' => strtotime('2026-10-01'), 'date_to' => strtotime('2026-11-30 23:59:59')]);
foreach ($hours as $type => $row) $out['teacher_hours'][$type] = is_array($row) ? $row['count'] : $row;
$out['courses'] = [];
foreach ([376,377] as $id) {
$course = \Components\AF\Courses::get($id);
$out['courses'][$id] = ['code' => $course['course_code'], 'total_hours' => $course['course_total_hours'], 'online_reasons' => \Components\AF\Courses::getCourseNotVisibleReasons($course)];
}
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
Summary:
Here's what this will do, in everyday terms:

**Changes to course dates (the main change):**
- It looks at three courses (numbers 376, 377, and 378) and goes through every class session scheduled in each of them.
- For any session dated before 8 October 2026, it marks that session as "teacher present."
- Depending on how many sessions those courses have before that date, this could be a handful of sessions or quite a lot — every single one before 8 October 2026 gets updated.

**Sets up a fake "demo" teacher:**
- It looks for a contact person with the email address "af-presentation-robin@example.invalid".
- If that person doesn't exist yet, it creates them: a new contact named Robin, marked as an individual, set to not receive marketing emails, located in Australia.
- It then adds this person to the "teachers" group, and marks them as hidden from the teachers' hours report (so they won't show up in that report).

**Adds a work record for that teacher:**
- It checks whether a work entry already exists with the note "Presentation Demo - salaried teacher work".
- If not, it creates one: a one-hour entry (11am to 12pm) on 6 October 2026, marked as unpaid, assigned to the Robin contact.

**Everything else is just for display:**
- The script also gathers some information — how many hours teacher number 1393 worked during October and November 2026, and some details about courses 376 and 377 (their codes, total hours, and why they might not be visible online).
- None of that changes anything; it's just collected and shown on screen at the end.

**In short:** it flips a "teacher present" flag on all class sessions before 8 October 2026 in three courses, creates a demo teacher contact (if needed) and hides them from the hours report, and adds one unpaid one-hour work entry for that demo teacher.