File indexing completed on 2025-03-02 05:29:27
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage Gapps 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata_Extension 0026 */ 0027 // require_once 'Zend/Gdata/Extension.php'; 0028 0029 /** 0030 * @see Zend_Gdata_Gapps 0031 */ 0032 // require_once 'Zend/Gdata/Gapps.php'; 0033 0034 /** 0035 * Represents the apps:name element used by the Apps data API. This is used 0036 * to represent a user's full name. This class is usually contained within 0037 * instances of Zend_Gdata_Gapps_UserEntry. 0038 * 0039 * @category Zend 0040 * @package Zend_Gdata 0041 * @subpackage Gapps 0042 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0043 * @license http://framework.zend.com/license/new-bsd New BSD License 0044 */ 0045 class Zend_Gdata_Gapps_Extension_Name extends Zend_Gdata_Extension 0046 { 0047 0048 protected $_rootNamespace = 'apps'; 0049 protected $_rootElement = 'name'; 0050 0051 /** 0052 * The associated user's family name. 0053 * 0054 * @var string 0055 */ 0056 protected $_familyName = null; 0057 0058 /** 0059 * The associated user's given name. 0060 * 0061 * @var string 0062 */ 0063 protected $_givenName = null; 0064 0065 /** 0066 * Constructs a new Zend_Gdata_Gapps_Extension_Name object. 0067 * 0068 * @param string $familyName (optional) The familyName to be set for this 0069 * object. 0070 * @param string $givenName (optional) The givenName to be set for this 0071 * object. 0072 */ 0073 public function __construct($familyName = null, $givenName = null) 0074 { 0075 $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces); 0076 parent::__construct(); 0077 $this->_familyName = $familyName; 0078 $this->_givenName = $givenName; 0079 } 0080 0081 /** 0082 * Retrieves a DOMElement which corresponds to this element and all 0083 * child properties. This is used to build an entry back into a DOM 0084 * and eventually XML text for sending to the server upon updates, or 0085 * for application storage/persistence. 0086 * 0087 * @param DOMDocument $doc The DOMDocument used to construct DOMElements 0088 * @return DOMElement The DOMElement representing this element and all 0089 * child properties. 0090 */ 0091 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) 0092 { 0093 $element = parent::getDOM($doc, $majorVersion, $minorVersion); 0094 if ($this->_familyName !== null) { 0095 $element->setAttribute('familyName', $this->_familyName); 0096 } 0097 if ($this->_givenName !== null) { 0098 $element->setAttribute('givenName', $this->_givenName); 0099 } 0100 return $element; 0101 } 0102 0103 /** 0104 * Given a DOMNode representing an attribute, tries to map the data into 0105 * instance members. If no mapping is defined, the name and value are 0106 * stored in an array. 0107 * 0108 * @param DOMNode $attribute The DOMNode attribute needed to be handled 0109 */ 0110 protected function takeAttributeFromDOM($attribute) 0111 { 0112 switch ($attribute->localName) { 0113 case 'familyName': 0114 $this->_familyName = $attribute->nodeValue; 0115 break; 0116 case 'givenName': 0117 $this->_givenName = $attribute->nodeValue; 0118 break; 0119 default: 0120 parent::takeAttributeFromDOM($attribute); 0121 } 0122 } 0123 0124 /** 0125 * Get the value for this element's familyName attribute. 0126 * 0127 * @see setFamilyName 0128 * @return string The requested attribute. 0129 */ 0130 public function getFamilyName() 0131 { 0132 return $this->_familyName; 0133 } 0134 0135 /** 0136 * Set the value for this element's familyName attribute. This 0137 * represents a user's family name. 0138 * 0139 * @param string $value The desired value for this attribute. 0140 * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface.. 0141 */ 0142 public function setFamilyName($value) 0143 { 0144 $this->_familyName = $value; 0145 return $this; 0146 } 0147 0148 /** 0149 * Get the value for this element's givenName attribute. 0150 * 0151 * @see setGivenName 0152 * @return string The requested attribute. 0153 */ 0154 public function getGivenName() 0155 { 0156 return $this->_givenName; 0157 } 0158 0159 /** 0160 * Set the value for this element's givenName attribute. This 0161 * represents a user's given name. 0162 * 0163 * @param string $value The desired value for this attribute. 0164 * @return Zend_Gdata_Gapps_Extension_Name Provides a fluent interface. 0165 */ 0166 public function setGivenName($value) 0167 { 0168 $this->_givenName = $value; 0169 return $this; 0170 } 0171 0172 /** 0173 * Magic toString method allows using this directly via echo 0174 * Works best in PHP >= 4.2.0 0175 */ 0176 public function __toString() 0177 { 0178 return $this->getGivenName() . ' ' . $this->getFamilyName(); 0179 } 0180 0181 }