Name.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gapps
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata_Extension
  23. */
  24. require_once 'Zend/Gdata/Extension.php';
  25. /**
  26. * @see Zend_Gdata_Gapps
  27. */
  28. require_once 'Zend/Gdata/Gapps.php';
  29. /**
  30. * Represents the apps:name element used by the Apps data API. This is used
  31. * to represent a user's full name. This class is usually contained within
  32. * instances of Zend_Gdata_Gapps_UserEntry.
  33. *
  34. * @category Zend
  35. * @package Zend_Gdata
  36. * @subpackage Gapps
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Gdata_Gapps_Extension_Name extends Zend_Gdata_Extension
  41. {
  42. protected $_rootNamespace = 'apps';
  43. protected $_rootElement = 'name';
  44. /**
  45. * The associated user's family name.
  46. *
  47. * @var string
  48. */
  49. protected $_familyName = null;
  50. /**
  51. * The associated user's given name.
  52. *
  53. * @var string
  54. */
  55. protected $_givenName = null;
  56. /**
  57. * Constructs a new Zend_Gdata_Gapps_Extension_Name object.
  58. *
  59. * @param string $familyName (optional) The familyName to be set for this
  60. * object.
  61. * @param string $givenName (optional) The givenName to be set for this
  62. * object.
  63. */
  64. public function __construct($familyName = null, $givenName = null)
  65. {
  66. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  67. parent::__construct();
  68. $this->_familyName = $familyName;
  69. $this->_givenName = $givenName;
  70. }
  71. /**
  72. * Retrieves a DOMElement which corresponds to this element and all
  73. * child properties. This is used to build an entry back into a DOM
  74. * and eventually XML text for sending to the server upon updates, or
  75. * for application storage/persistence.
  76. *
  77. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  78. * @return DOMElement The DOMElement representing this element and all
  79. * child properties.
  80. */
  81. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  82. {
  83. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  84. if ($this->_familyName !== null) {
  85. $element->setAttribute('familyName', $this->_familyName);
  86. }
  87. if ($this->_givenName !== null) {
  88. $element->setAttribute('givenName', $this->_givenName);
  89. }
  90. return $element;
  91. }
  92. /**
  93. * Given a DOMNode representing an attribute, tries to map the data into
  94. * instance members. If no mapping is defined, the name and value are
  95. * stored in an array.
  96. *
  97. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  98. */
  99. protected function takeAttributeFromDOM($attribute)
  100. {
  101. switch ($attribute->localName) {
  102. case 'familyName':
  103. $this->_familyName = $attribute->nodeValue;
  104. break;
  105. case 'givenName':
  106. $this->_givenName = $attribute->nodeValue;
  107. break;
  108. default:
  109. parent::takeAttributeFromDOM($attribute);
  110. }
  111. }
  112. /**
  113. * Get the value for this element's familyName attribute.
  114. *
  115. * @see setFamilyName
  116. * @return string The requested attribute.
  117. */
  118. public function getFamilyName()
  119. {
  120. return $this->_familyName;
  121. }
  122. /**
  123. * Set the value for this element's familyName attribute. This
  124. * represents a user's family name.
  125. *
  126. * @param string $value The desired value for this attribute.
  127. * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface..
  128. */
  129. public function setFamilyName($value)
  130. {
  131. $this->_familyName = $value;
  132. return $this;
  133. }
  134. /**
  135. * Get the value for this element's givenName attribute.
  136. *
  137. * @see setGivenName
  138. * @return string The requested attribute.
  139. */
  140. public function getGivenName()
  141. {
  142. return $this->_givenName;
  143. }
  144. /**
  145. * Set the value for this element's givenName attribute. This
  146. * represents a user's given name.
  147. *
  148. * @param string $value The desired value for this attribute.
  149. * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface.
  150. */
  151. public function setGivenName($value)
  152. {
  153. $this->_givenName = $value;
  154. return $this;
  155. }
  156. /**
  157. * Magic toString method allows using this directly via echo
  158. * Works best in PHP >= 4.2.0
  159. */
  160. public function __toString()
  161. {
  162. return $this->getGivenName() . ' ' . $this->getFamilyName();
  163. }
  164. }