fix ContactID null on contact_show

This commit is contained in:
mahdahar 2025-09-26 10:00:06 +07:00
parent cfb6fda288
commit 6b94cb3293

View File

@ -25,39 +25,41 @@ class ContactModel extends Model {
public function getContactWithDetail($ContactID) {
$rows = $this->where('contact.ContactID', $ContactID)->join('contactdetail cd', 'contact.ContactID=cd.ContactID','left')->get()->getResultArray();
$contact = [
'ContactID' => $rows[0]['ContactID'],
'NameFirst' => $rows[0]['NameFirst'] ?? null,
'NameLast' => $rows[0]['NameLast'] ?? null,
'Title' => $rows[0]['Title'] ?? null,
'Initial' => $rows[0]['Initial'] ?? null,
'Birthdate' => $rows[0]['Birthdate'] ?? null,
'EmailAddress1' => $rows[0]['EmailAddress1'] ?? null,
'EmailAddress2' => $rows[0]['EmailAddress2'] ?? null,
'Phone' => $rows[0]['Phone'] ?? null,
'MobilePhone1' => $rows[0]['MobilePhone1'] ?? null,
'MobilePhone2' => $rows[0]['MobilePhone2'] ?? null,
'Specialty' => $rows[0]['Specialty'] ?? null,
'SubSpecialty' => $rows[0]['SubSpecialty'] ?? null,
'Details' => []
];
$contact = [];
if(!empty($rows)) {
$contact = [
'ContactID' => $rows[0]['ContactID'] ?? null,
'NameFirst' => $rows[0]['NameFirst'] ?? null,
'NameLast' => $rows[0]['NameLast'] ?? null,
'Title' => $rows[0]['Title'] ?? null,
'Initial' => $rows[0]['Initial'] ?? null,
'Birthdate' => $rows[0]['Birthdate'] ?? null,
'EmailAddress1' => $rows[0]['EmailAddress1'] ?? null,
'EmailAddress2' => $rows[0]['EmailAddress2'] ?? null,
'Phone' => $rows[0]['Phone'] ?? null,
'MobilePhone1' => $rows[0]['MobilePhone1'] ?? null,
'MobilePhone2' => $rows[0]['MobilePhone2'] ?? null,
'Specialty' => $rows[0]['Specialty'] ?? null,
'SubSpecialty' => $rows[0]['SubSpecialty'] ?? null,
'Details' => []
];
foreach ($rows as $row) {
if (!empty($row['ContactDetID'])) {
$contact['Details'][] = [
'SiteID' => $row['SiteID'] ?? null,
'ContactDetID' => $row['ContactDetID'],
'ContactCode' => $row['ContactCode'] ?? null,
'ContactEmail' => $row['DetailPhone'] ?? null,
'OccupationID' => $row['OccupationID'] ?? null,
'JobTitle' => $row['JobTitle'] ?? null,
'Department' => $row['Department'] ?? null,
'ContactStartDate' => $row['ContactStartDate'] ?? null,
'ContactEndDate' => $row['ContactEndDate'] ?? null
];
foreach ($rows as $row) {
if (!empty($row['ContactDetID'])) {
$contact['Details'][] = [
'SiteID' => $row['SiteID'] ?? null,
'ContactDetID' => $row['ContactDetID'],
'ContactCode' => $row['ContactCode'] ?? null,
'ContactEmail' => $row['DetailPhone'] ?? null,
'OccupationID' => $row['OccupationID'] ?? null,
'JobTitle' => $row['JobTitle'] ?? null,
'Department' => $row['Department'] ?? null,
'ContactStartDate' => $row['ContactStartDate'] ?? null,
'ContactEndDate' => $row['ContactEndDate'] ?? null
];
}
}
}
return $contact;
}