getUserName() public static method

Returns the real name, if available, of a user.
public static getUserName ( $uid ) : string
return string The real name
Esempio n. 1
0
 /**
  *
  * @param array $row           Hash of the note data, db keys.
  * @param string  $passphrase  The encryption passphrase.
  *
  * @return array a Task hash.
  * @throws Mnemo_Exception
  */
 protected function _buildNote($row, $passphrase = null)
 {
     // Make sure notes always have a UID.
     if (empty($row['memo_uid'])) {
         $row['memo_uid'] = strval(new Horde_Support_Guid());
         $query = 'UPDATE ' . $this->_table . ' SET memo_uid = ?' . ' WHERE memo_owner = ? AND memo_id = ?';
         $values = array($row['memo_uid'], $row['memo_owner'], $row['memo_id']);
         try {
             $this->_db->update($query, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Mnemo_Exception($e->getMessage());
         }
     }
     // Decrypt note if requested.
     $encrypted = false;
     $body = $this->_column->binaryToString($row['memo_body']);
     $body = Horde_String::convertCharset($body, $this->_charset, 'UTF-8');
     if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) {
         $encrypted = true;
         if (empty($passphrase)) {
             $passphrase = Mnemo::getPassphrase($row['memo_id']);
         }
         if (empty($passphrase)) {
             $body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE);
         } else {
             try {
                 $body = $this->_decrypt($body, $passphrase);
                 $body = $body->message;
             } catch (Mnemo_Exception $e) {
                 $body = $e;
             }
             Mnemo::storePassphrase($row['memo_id'], $passphrase);
         }
     }
     // Create a new note based on $row's values.
     $uid = Horde_String::convertCharset($row['memo_uid'], $this->_charset, 'UTF-8');
     $memo = array('memolist_id' => $row['memo_owner'], 'memo_id' => $row['memo_id'], 'uid' => $uid, 'desc' => Horde_String::convertCharset($row['memo_desc'], $this->_charset, 'UTF-8'), 'body' => $body, 'tags' => $GLOBALS['injector']->getInstance('Mnemo_Tagger')->getTags($uid, 'note'), 'encrypted' => $encrypted);
     try {
         $userId = $GLOBALS['registry']->getAuth();
         $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory('mnemo:' . $row['memo_owner'] . ':' . $row['memo_uid']);
         foreach ($log as $entry) {
             switch ($entry['action']) {
                 case 'add':
                     $memo['created'] = new Horde_Date($entry['ts']);
                     if ($userId != $entry['who']) {
                         $memo['createdby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who']));
                     } else {
                         $memo['createdby'] = _("by me");
                     }
                     break;
                 case 'modify':
                     $memo['modified'] = new Horde_Date($entry['ts']);
                     if ($userId != $entry['who']) {
                         $memo['modifiedby'] = sprintf(_("by %s"), Mnemo::getUserName($entry['who']));
                     } else {
                         $memo['modifiedby'] = _("by me");
                     }
                     break;
             }
         }
     } catch (Horde_Exception $e) {
     }
     return $memo;
 }