Added name abbreviation

This commit is contained in:
Frank Schubert
2021-08-30 21:14:02 +02:00
parent aa05334ce2
commit 54b6b6b501
2 changed files with 41 additions and 10 deletions

View File

@@ -39,6 +39,35 @@ class User extends mfBaseModel {
return false;
}
public function getAbbrName() {
if(strpos($this->name, " ") === false) {
return $this->name;
}
$m = [];
if(preg_match('/^([^ ]+) ([^ ]+)(?: ([^ ]+))?$/', $this->name, $m)) {
$firstname = $m[1];
if($m[3]) {
$middlename = $m[2];
$lastname = $m[3];
} else {
$middlename = "";
$lastname = $m[2];
}
//var_dump($m);exit;
$abbr = "$firstname ";
if($middlename) {
$abbr .= substr($middlename, 0, 1). ". ";
}
$abbr .= substr($lastname, 0, 1). ". ";
return $abbr;
}
return $this->name;
}
protected function afterLoad() {
$wp = new WorkerPermission();
$wp->loadByUserId($this->id);