fix gitlab tests
This commit is contained in:
@@ -8,7 +8,9 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class WhatsappContactService
|
||||
{
|
||||
public function __construct(private WhatsappContextService $context) {}
|
||||
public function __construct(private WhatsappContextService $context)
|
||||
{
|
||||
}
|
||||
|
||||
public function listParentContacts(?string $schoolYear, ?string $semester): array
|
||||
{
|
||||
@@ -16,7 +18,7 @@ class WhatsappContactService
|
||||
$semester = trim((string) $semester);
|
||||
|
||||
$builder = DB::table('parents as sp');
|
||||
$builder->select('
|
||||
$builder->select("
|
||||
sp.id AS parents_row_id,
|
||||
sp.firstparent_id AS firstparent_id,
|
||||
sp.secondparent_firstname AS sp_firstname,
|
||||
@@ -32,7 +34,7 @@ class WhatsappContactService
|
||||
u.cellphone AS u_phone,
|
||||
u.school_year AS u_school_year,
|
||||
u.semester AS u_semester
|
||||
');
|
||||
");
|
||||
$builder->leftJoin('users as u', 'u.id', '=', 'sp.firstparent_id');
|
||||
|
||||
if ($schoolYear !== '') {
|
||||
@@ -47,7 +49,7 @@ class WhatsappContactService
|
||||
$contacts = [];
|
||||
foreach ($rows as $row) {
|
||||
$r = (array) $row;
|
||||
if (! empty($r['u_id'])) {
|
||||
if (!empty($r['u_id'])) {
|
||||
$contacts[] = [
|
||||
'firstname' => (string) ($r['u_firstname'] ?? ''),
|
||||
'lastname' => (string) ($r['u_lastname'] ?? ''),
|
||||
@@ -57,7 +59,7 @@ class WhatsappContactService
|
||||
];
|
||||
}
|
||||
|
||||
$hasSecond = ! empty($r['sp_firstname']) || ! empty($r['sp_lastname']) || ! empty($r['sp_email']) || ! empty($r['sp_phone']);
|
||||
$hasSecond = !empty($r['sp_firstname']) || !empty($r['sp_lastname']) || !empty($r['sp_email']) || !empty($r['sp_phone']);
|
||||
if ($hasSecond) {
|
||||
$contacts[] = [
|
||||
'firstname' => (string) ($r['sp_firstname'] ?? ''),
|
||||
@@ -70,9 +72,8 @@ class WhatsappContactService
|
||||
}
|
||||
|
||||
$contacts = array_values(array_filter($contacts, function ($c) {
|
||||
$name = trim(($c['firstname'] ?? '').($c['lastname'] ?? ''));
|
||||
$contact = trim(($c['phone'] ?? '').($c['email'] ?? ''));
|
||||
|
||||
$name = trim(($c['firstname'] ?? '') . ($c['lastname'] ?? ''));
|
||||
$contact = trim(($c['phone'] ?? '') . ($c['email'] ?? ''));
|
||||
return $name !== '' || $contact !== '';
|
||||
}));
|
||||
|
||||
@@ -89,7 +90,6 @@ class WhatsappContactService
|
||||
}
|
||||
$ta = ($a['type'] ?? '') === 'Primary Parent' ? 0 : 1;
|
||||
$tb = ($b['type'] ?? '') === 'Primary Parent' ? 0 : 1;
|
||||
|
||||
return $ta <=> $tb;
|
||||
});
|
||||
|
||||
@@ -115,7 +115,7 @@ class WhatsappContactService
|
||||
))));
|
||||
|
||||
$namesById = [];
|
||||
if (! empty($sectionIds)) {
|
||||
if (!empty($sectionIds)) {
|
||||
$nameRows = DB::table('classSection')
|
||||
->select('class_section_id', 'class_section_name')
|
||||
->whereIn('class_section_id', $sectionIds)
|
||||
@@ -130,13 +130,13 @@ class WhatsappContactService
|
||||
$classSections = [];
|
||||
foreach ($sections as $s) {
|
||||
$sid = (int) ($s->class_section_id ?? 0);
|
||||
if (! $sid) {
|
||||
if (!$sid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classSections[$sid] = [
|
||||
'class_section_id' => $sid,
|
||||
'class_section_name' => $namesById[$sid] ?? ('Section '.$sid),
|
||||
'class_section_name' => $namesById[$sid] ?? ('Section ' . $sid),
|
||||
'semester' => $semester,
|
||||
'school_year' => (string) ($s->school_year ?? ''),
|
||||
'description' => '',
|
||||
@@ -178,11 +178,11 @@ class WhatsappContactService
|
||||
$r = (array) $row;
|
||||
$sid = (int) ($r['class_section_id'] ?? 0);
|
||||
$pid = (int) ($r['primary_id'] ?? 0);
|
||||
if (! $sid || ! $pid || ! isset($classSections[$sid])) {
|
||||
if (!$sid || !$pid || !isset($classSections[$sid])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = $sid.':'.$pid;
|
||||
$key = $sid . ':' . $pid;
|
||||
if (isset($seen[$key])) {
|
||||
continue;
|
||||
}
|
||||
@@ -191,11 +191,11 @@ class WhatsappContactService
|
||||
$classSections[$sid]['parents'][] = [
|
||||
'class_section_id' => $sid,
|
||||
'primary_id' => $pid,
|
||||
'primary_name' => trim(($r['primary_lastname'] ?? '').', '.($r['primary_firstname'] ?? '')),
|
||||
'primary_name' => trim(($r['primary_lastname'] ?? '') . ', ' . ($r['primary_firstname'] ?? '')),
|
||||
'primary_phone' => (string) ($r['primary_phone'] ?? ''),
|
||||
'primary_email' => (string) ($r['primary_email'] ?? ''),
|
||||
'second_id' => (int) ($r['second_id'] ?? 0),
|
||||
'second_name' => trim(($r['second_lastname'] ?? '').', '.($r['second_firstname'] ?? '')),
|
||||
'second_name' => trim(($r['second_lastname'] ?? '') . ', ' . ($r['second_firstname'] ?? '')),
|
||||
'second_phone' => (string) ($r['second_phone'] ?? ''),
|
||||
'second_email' => (string) ($r['second_email'] ?? ''),
|
||||
'primary_member' => null,
|
||||
@@ -225,7 +225,7 @@ class WhatsappContactService
|
||||
}
|
||||
unset($section);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('WhatsApp membership lookup failed: '.$e->getMessage());
|
||||
Log::warning('WhatsApp membership lookup failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -239,10 +239,10 @@ class WhatsappContactService
|
||||
foreach ($teachers as $row) {
|
||||
$r = (array) $row;
|
||||
$sid = (int) ($r['class_section_id'] ?? 0);
|
||||
if (! isset($classSections[$sid])) {
|
||||
if (!isset($classSections[$sid])) {
|
||||
continue;
|
||||
}
|
||||
$name = trim(($r['lastname'] ?? '').', '.($r['firstname'] ?? ''));
|
||||
$name = trim(($r['lastname'] ?? '') . ', ' . ($r['firstname'] ?? ''));
|
||||
$pos = strtolower((string) ($r['position'] ?? 'main'));
|
||||
if ($pos === 'ta' || $pos === 'assistant') {
|
||||
$classSections[$sid]['teacher_assistants'][] = $name;
|
||||
@@ -251,7 +251,7 @@ class WhatsappContactService
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('WhatsApp teacher list lookup failed: '.$e->getMessage());
|
||||
Log::warning('WhatsApp teacher list lookup failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
foreach ($classSections as &$section) {
|
||||
|
||||
Reference in New Issue
Block a user