diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index 10cd928..29b740c 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -50,7 +50,7 @@ class ContactsController extends AppController { } function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { - $links['Contact'] = array('last_name', 'first_name'); + $links['Contact'] = array('display_name'); return parent::gridDataPostProcessLinks($params, $model, $records, $links); } diff --git a/site/models/contact.php b/site/models/contact.php index b691823..43ad9e0 100644 --- a/site/models/contact.php +++ b/site/models/contact.php @@ -41,14 +41,15 @@ class Contact extends AppModel { function saveContact($id, $data) { // Establish a display name if not already given - if (!$data['Contact']['display_name']) + if (!$data['Contact']['display_name'] && + $data['Contact']['first_name'] && $data['Contact']['last_name']) $data['Contact']['display_name'] = - (($data['Contact']['first_name'] && - $data['Contact']['last_name']) - ? $data['Contact']['last_name'] . ', ' . $data['Contact']['first_name'] - : ($data['Contact']['first_name'] - ? $data['Contact']['first_name'] - : $data['Contact']['last_name'])); + $data['Contact']['last_name'] . ', ' . $data['Contact']['first_name']; + + foreach (array('last_name', 'first_name', 'company_name') AS $fld) { + if (!$data['Contact']['display_name'] && $data['Contact'][$fld]) + $data['Contact']['display_name'] = $data['Contact'][$fld]; + } // Save the contact data $this->create(); diff --git a/site/views/contacts/view.ctp b/site/views/contacts/view.ctp index 55ac199..4aba32c 100644 --- a/site/views/contacts/view.ctp +++ b/site/views/contacts/view.ctp @@ -17,16 +17,17 @@ if (isset($contact['Contact'])) $contact = $contact['Contact']; $rows = array(); -$rows[] = array('First Name', $contact['first_name']); -$rows[] = array('Middle Name', $contact['middle_name']); -$rows[] = array('Last Name', $contact['last_name']); -$rows[] = array('Company', $contact['company_name']); -$rows[] = array('SSN', $contact['id_federal']); -$rows[] = array('ID', ($contact['id_local'] - . ($contact['id_local'] - ? " - ".$contact['id_local_state'] - : ""))); -$rows[] = array('Comment', $contact['comment']); +$rows[] = array('Display Name', $contact['display_name']); +$rows[] = array('First Name', $contact['first_name']); +$rows[] = array('Middle Name', $contact['middle_name']); +$rows[] = array('Last Name', $contact['last_name']); +$rows[] = array('Company', $contact['company_name']); +$rows[] = array('SSN', $contact['id_federal']); +$rows[] = array('ID', ($contact['id_local'] + . ($contact['id_local'] + ? " - ".$contact['id_local_state'] + : ""))); +$rows[] = array('Comment', $contact['comment']); echo $this->element('table', array('class' => 'item contact detail', diff --git a/site/views/elements/contacts.ctp b/site/views/elements/contacts.ctp index 7267642..b35b45b 100644 --- a/site/views/elements/contacts.ctp +++ b/site/views/elements/contacts.ctp @@ -3,6 +3,7 @@ // Define the table columns $cols = array(); $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum'); +$cols['Name'] = array('index' => 'Contact.display_name', 'formatter' => 'longname'); $cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'longname'); $cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'longname'); $cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname');