Skip to content

Instantly share code, notes, and snippets.

@jmertic
Created August 27, 2013 19:19
Show Gist options
  • Save jmertic/6357843 to your computer and use it in GitHub Desktop.
Save jmertic/6357843 to your computer and use it in GitHub Desktop.
<?php
/**
* This function helps generate the name and full_name member field
* variables from the salutation, title, first_name and last_name fields.
* It takes into account the locale format settings as well as ACL settings
* if supported.
*/
public function _create_proper_name_field()
{
global $locale, $app_list_strings;
$nameparts = array('first_name' => $this->first_name, 'last_name' => $this->last_name,
"title" => $this->title, 'middle_name_c' => $this->middle_name_c, 'suffix_c' => $this->suffix_c);
if (isset($this->field_defs['salutation']['options']) &&
isset($app_list_strings[$this->field_defs['salutation']['options']]) &&
isset($app_list_strings[$this->field_defs['salutation']['options']][$this->salutation])) {
$nameparts['salutation'] = $app_list_strings[$this->field_defs['salutation']['options']][$this->salutation];
} else {
$nameparts['salutation'] = '';
}
if (isset($GLOBALS['current_user'])) {
$this->ACLFilterFieldList($nameparts, array(), array("blank_value" => true));
}
if (empty($nameparts['first_name']) && empty($nameparts['last_name'])) {
$full_name = $locale->getLocaleFormattedName("", $this->last_name,
$nameparts['salutation'], $nameparts['title']);
} else {
if ($this->createLocaleFormattedName) {
$full_name = $locale->getLocaleFormattedName($nameparts['first_name'].' '.$nameparts['middle_name_c'],
$nameparts['last_name'].' '.$nameparts['suffix_c'], $nameparts['salutation'], $nameparts['title']);
} else {
$full_name = $locale->getLocaleFormattedName($nameparts['first_name'].' '.$nameparts['middle_name_c'],
$nameparts['last_name'].' '.$nameparts['middle_name_c']);
}
}
$this->name = $this->full_name = $full_name; // fill_name used by
// campaigns
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment