From ebd805f5647d8e9deceb95250e3f08457c113e5c Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Fri, 14 Jul 2017 14:07:32 -0400 Subject: [PATCH] Set missing user names to empty strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sets the first and last names to empty string when no names are found - Changed “else if” to “elseif” --- src/ToolProvider/User.php | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ToolProvider/User.php b/src/ToolProvider/User.php index 64632dd..6788031 100644 --- a/src/ToolProvider/User.php +++ b/src/ToolProvider/User.php @@ -297,30 +297,48 @@ public function getId($idScope = null) */ public function setNames($firstname, $lastname, $fullname) { - $names = array(0 => '', 1 => ''); + if (!empty($fullname)) { + $this->fullname = trim($fullname); $names = preg_split("/[\s]+/", $this->fullname, 2); } + + if (!empty($firstname)) { + $this->firstname = trim($firstname); $names[0] = $this->firstname; - } else if (!empty($names[0])) { + + } elseif (!empty($names[0])) { + $this->firstname = $names[0]; + } else { - $this->firstname = 'User'; + + $this->firstname = ''; } + + if (!empty($lastname)) { + $this->lastname = trim($lastname); $names[1] = $this->lastname; - } else if (!empty($names[1])) { + + } elseif (!empty($names[1])) { + $this->lastname = $names[1]; + } else { - $this->lastname = $this->ltiUserId; + + $this->lastname = ''; } + + if (empty($this->fullname)) { - $this->fullname = "{$this->firstname} {$this->lastname}"; + + $this->fullname = implode(' ', array_filter(array($this->firstname, $this->lastname))); } }