From b13b5c198a159e321d1ea9d1c1d42ad62551c74c Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Tue, 6 May 2014 20:53:24 +0000 Subject: [PATCH] Add format param to PersonsName constructor Accept desired $format as part of class instantiation. System default is used when none or an invalid format is provided --- include/class.user.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/class.user.php b/include/class.user.php index c6dfbe1a2..5081f9a55 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -286,6 +286,7 @@ class User extends UserModel { User::_inspect(); class PersonsName { + var $format; var $parts; var $name; @@ -302,7 +303,14 @@ class PersonsName { 'original' => array('-- As Entered --', 'getOriginal'), ); - function __construct($name) { + function __construct($name, $format=null) { + global $cfg; + + if ($format && !isset(static::$formats[$format])) + $this->format = $format; + elseif($cfg) + $this->format = $cfg->getDefaultNameFormat(); + $this->parts = static::splitName($name); $this->name = $name; } @@ -392,9 +400,9 @@ class PersonsName { function __toString() { global $cfg; - $format = $cfg->getDefaultNameFormat(); - list(,$func) = static::$formats[$format]; + @list(,$func) = static::$formats[$this->format]; if (!$func) $func = 'getFull'; + return call_user_func(array($this, $func)); } -- GitLab