hasValue() public method

Determines whether or not the object has a value for the specified attribute.
public hasValue ( string $attribute ) : boolean
$attribute string The attribute to check.
return boolean Whether or not there is a value for $attribute.
コード例 #1
0
ファイル: Object.php プロジェクト: raz0rsdge/horde
 /**
  * Merges another contact into this one by filling empty fields of this
  * contact with values from the other.
  *
  * @param Turba_Object $contact  Another contact.
  */
 public function merge(Turba_Object $contact)
 {
     foreach (array_keys($contact->attributes) as $attribute) {
         if (!$this->hasValue($attribute) && $contact->hasValue($attribute)) {
             $this->setValue($attribute, $contact->getValue($attribute));
         }
     }
 }
コード例 #2
0
ファイル: Turba.php プロジェクト: jubinpatel/horde
 /**
  * Formats the name according to the user's preference.
  *
  * If the format is 'none', the full name with all parts is returned. If
  * the format is 'last_first' or 'first_last', only the first name and
  * last name are returned.
  *
  * @param Turba_Object $ob     The object to get a name from.
  * @param string $name_format  The formatting. One of 'none', 'last_first'
  *                             or 'first_last'. Defaults to the user
  *                             preference.
  *
  * @return string  The formatted name, either "Firstname Lastname"
  *                 or "Lastname, Firstname" depending on $name_format or
  *                 the user's preference.
  */
 public static function formatName(Turba_Object $ob, $name_format = null)
 {
     if (!$name_format) {
         if (!isset(self::$_cache['defaultFormat'])) {
             self::$_cache['defaultFormat'] = $GLOBALS['prefs']->getValue('name_format');
         }
         $name_format = self::$_cache['defaultFormat'];
     }
     /* If no formatting, return original name. */
     if (!in_array($name_format, array('first_last', 'last_first'))) {
         return $ob->getValue('name');
     }
     /* See if we have the name fields split out explicitly. */
     if ($ob->hasValue('firstname') && $ob->hasValue('lastname')) {
         return $name_format == 'last_first' ? $ob->getValue('lastname') . ', ' . $ob->getValue('firstname') : $ob->getValue('firstname') . ' ' . $ob->getValue('lastname');
     }
     /* One field, we'll have to guess. */
     $name = $ob->getValue('name');
     $lastname = self::guessLastname($name);
     if ($name_format == 'last_first' && !is_int(strpos($name, ',')) && Horde_String::length($name) > Horde_String::length($lastname)) {
         return $lastname . ', ' . preg_replace('/\\s+' . preg_quote($lastname, '/') . '/', '', $name);
     }
     if ($name_format == 'first_last' && is_int(strpos($name, ',')) && Horde_String::length($name) > Horde_String::length($lastname)) {
         return preg_replace('/' . preg_quote($lastname, '/') . ',\\s*/', '', $name) . ' ' . $lastname;
     }
     return $name;
 }