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