Turba::getUserName PHP Method

getUserName() public static method

Returns the real name, if available, of a user.
public static getUserName ( string $uid ) : string
$uid string The uid of the name to return.
return string The user's full, real name.
    public static function getUserName($uid)
    {
        if (!isset(self::$_cache['names'])) {
            self::$_cache['names'] = array();
        }
        if (!isset(self::$_cache['names'][$uid])) {
            $ident = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($uid);
            $ident->setDefault($ident->getDefault());
            $name = $ident->getValue('fullname');
            self::$_cache['names'][$uid] = empty($name) ? $uid : $name;
        }
        return self::$_cache['names'][$uid];
    }

Usage Example

Example #1
0
 /**
  * Returns history information about this contact.
  *
  * @return array  A hash with the optional entries 'created' and 'modified'
  *                and human readable history information as the values.
  */
 public function getHistory()
 {
     if (!$this->getValue('__uid')) {
         return array();
     }
     $history = array();
     try {
         $log = $GLOBALS['injector']->getInstance('Horde_History')->getHistory($this->getGuid());
         foreach ($log as $entry) {
             if ($entry['action'] == 'add' || $entry['action'] == 'modify') {
                 if ($GLOBALS['registry']->getAuth() != $entry['who']) {
                     $by = sprintf(_("by %s"), Turba::getUserName($entry['who']));
                 } else {
                     $by = _("by me");
                 }
                 $history[$entry['action'] == 'add' ? 'created' : 'modified'] = strftime($GLOBALS['prefs']->getValue('date_format'), $entry['ts']) . ' ' . date($GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:i a', $entry['ts']) . ' ' . htmlspecialchars($by);
             }
         }
     } catch (Exception $e) {
         return array();
     }
     return $history;
 }