UserEntry.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_Entry
  23. */
  24. require_once 'Zend/Gdata/Entry.php';
  25. /**
  26. * @see Zend_Gdata_Extension_FeedLink
  27. */
  28. require_once 'Zend/Gdata/Extension/FeedLink.php';
  29. /**
  30. * @see Zend_Gdata_Gapps_Extension_Login
  31. */
  32. require_once 'Zend/Gdata/Gapps/Extension/Login.php';
  33. /**
  34. * @see Zend_Gdata_Gapps_Extension_Name
  35. */
  36. require_once 'Zend/Gdata/Gapps/Extension/Name.php';
  37. /**
  38. * @see Zend_Gdata_Gapps_Extension_Quota
  39. */
  40. require_once 'Zend/Gdata/Gapps/Extension/Quota.php';
  41. /**
  42. * Data model class for a Google Apps User Entry.
  43. *
  44. * Each user entry describes a single user within a Google Apps hosted
  45. * domain.
  46. *
  47. * To transfer user entries to and from the Google Apps servers, including
  48. * creating new entries, refer to the Google Apps service class,
  49. * Zend_Gdata_Gapps.
  50. *
  51. * This class represents <atom:entry> in the Google Data protocol.
  52. *
  53. * @category Zend
  54. * @package Zend_Gdata
  55. * @subpackage Gapps
  56. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  57. * @license http://framework.zend.com/license/new-bsd New BSD License
  58. */
  59. class Zend_Gdata_Gapps_UserEntry extends Zend_Gdata_Entry
  60. {
  61. protected $_entryClassName = 'Zend_Gdata_Gapps_UserEntry';
  62. /**
  63. * <apps:login> element containing information about this user's
  64. * account, including their username and permissions.
  65. *
  66. * @var Zend_Gdata_Gapps_Extension_Login
  67. */
  68. protected $_login = null;
  69. /**
  70. * <apps:name> element containing the user's actual name.
  71. *
  72. * @var Zend_Gdata_Gapps_Extension_Name
  73. */
  74. protected $_name = null;
  75. /**
  76. * <apps:quotq> element describing any storage quotas in place for
  77. * this user.
  78. *
  79. * @var Zend_Gdata_Gapps_Extension_Quota
  80. */
  81. protected $_quota = null;
  82. /**
  83. * <gd:feedLink> element containing information about other feeds
  84. * relevant to this entry.
  85. *
  86. * @var Zend_Gdata_Extension_FeedLink
  87. */
  88. protected $_feedLink = array();
  89. /**
  90. * Create a new instance.
  91. *
  92. * @param DOMElement $element (optional) DOMElement from which this
  93. * object should be constructed.
  94. */
  95. public function __construct($element = null)
  96. {
  97. $this->registerAllNamespaces(Zend_Gdata_Gapps::$namespaces);
  98. parent::__construct($element);
  99. }
  100. /**
  101. * Retrieves a DOMElement which corresponds to this element and all
  102. * child properties. This is used to build an entry back into a DOM
  103. * and eventually XML text for application storage/persistence.
  104. *
  105. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  106. * @return DOMElement The DOMElement representing this element and all
  107. * child properties.
  108. */
  109. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  110. {
  111. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  112. if ($this->_login !== null) {
  113. $element->appendChild($this->_login->getDOM($element->ownerDocument));
  114. }
  115. if ($this->_name !== null) {
  116. $element->appendChild($this->_name->getDOM($element->ownerDocument));
  117. }
  118. if ($this->_quota !== null) {
  119. $element->appendChild($this->_quota->getDOM($element->ownerDocument));
  120. }
  121. foreach ($this->_feedLink as $feedLink) {
  122. $element->appendChild($feedLink->getDOM($element->ownerDocument));
  123. }
  124. return $element;
  125. }
  126. /**
  127. * Creates individual Entry objects of the appropriate type and
  128. * stores them as members of this entry based upon DOM data.
  129. *
  130. * @param DOMNode $child The DOMNode to process
  131. */
  132. protected function takeChildFromDOM($child)
  133. {
  134. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  135. switch ($absoluteNodeName) {
  136. case $this->lookupNamespace('apps') . ':' . 'login';
  137. $login = new Zend_Gdata_Gapps_Extension_Login();
  138. $login->transferFromDOM($child);
  139. $this->_login = $login;
  140. break;
  141. case $this->lookupNamespace('apps') . ':' . 'name';
  142. $name = new Zend_Gdata_Gapps_Extension_Name();
  143. $name->transferFromDOM($child);
  144. $this->_name = $name;
  145. break;
  146. case $this->lookupNamespace('apps') . ':' . 'quota';
  147. $quota = new Zend_Gdata_Gapps_Extension_Quota();
  148. $quota->transferFromDOM($child);
  149. $this->_quota = $quota;
  150. break;
  151. case $this->lookupNamespace('gd') . ':' . 'feedLink';
  152. $feedLink = new Zend_Gdata_Extension_FeedLink();
  153. $feedLink->transferFromDOM($child);
  154. $this->_feedLink[] = $feedLink;
  155. break;
  156. default:
  157. parent::takeChildFromDOM($child);
  158. break;
  159. }
  160. }
  161. /**
  162. * Get the value of the login property for this object.
  163. *
  164. * @see setLogin
  165. * @return Zend_Gdata_Gapps_Extension_Login The requested object.
  166. */
  167. public function getLogin()
  168. {
  169. return $this->_login;
  170. }
  171. /**
  172. * Set the value of the login property for this object. This property
  173. * is used to store the username address of the current user.
  174. *
  175. * @param Zend_Gdata_Gapps_Extension_Login $value The desired value for
  176. * this instance's login property.
  177. * @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
  178. */
  179. public function setLogin($value)
  180. {
  181. $this->_login = $value;
  182. return $this;
  183. }
  184. /**
  185. * Get the value of the name property for this object.
  186. *
  187. * @see setName
  188. * @return Zend_Gdata_Gapps_Extension_Name The requested object.
  189. */
  190. public function getName()
  191. {
  192. return $this->_name;
  193. }
  194. /**
  195. * Set the value of the name property for this object. This property
  196. * is used to store the full name of the current user.
  197. *
  198. * @param Zend_Gdata_Gapps_Extension_Name $value The desired value for
  199. * this instance's name property.
  200. * @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
  201. */
  202. public function setName($value)
  203. {
  204. $this->_name = $value;
  205. return $this;
  206. }
  207. /**
  208. * Get the value of the quota property for this object.
  209. *
  210. * @see setQuota
  211. * @return Zend_Gdata_Gapps_Extension_Quota The requested object.
  212. */
  213. public function getQuota()
  214. {
  215. return $this->_quota;
  216. }
  217. /**
  218. * Set the value of the quota property for this object. This property
  219. * is used to store the amount of storage available for the current
  220. * user. Quotas may not be modifiable depending on the domain used.
  221. *
  222. * @param Zend_Gdata_Gapps_Extension_Quota $value The desired value for
  223. * this instance's quota property.
  224. * @return Zend_Gdata_Gapps_UserEntry Provides a fluent interface.
  225. */
  226. public function setQuota($value)
  227. {
  228. $this->_quota = $value;
  229. return $this;
  230. }
  231. /**
  232. * Returns all feed links for this entry, or if a rel value is
  233. * specified, the feed link associated with that value is returned.
  234. *
  235. * @param string $rel The rel value of the link to be found. If null,
  236. * the array of links is returned instead.
  237. * @return mixed Either an array of Zend_Gdata_Extension_FeedLink
  238. * objects if $rel is null, a single
  239. * Zend_Gdata_Extension_FeedLink object if $rel is specified
  240. * and a matching feed link is found, or null if $rel is
  241. * specified and no matching feed link is found.
  242. */
  243. public function getFeedLink($rel = null)
  244. {
  245. if ($rel == null) {
  246. return $this->_feedLink;
  247. } else {
  248. foreach ($this->_feedLink as $feedLink) {
  249. if ($feedLink->rel == $rel) {
  250. return $feedLink;
  251. }
  252. }
  253. return null;
  254. }
  255. }
  256. /**
  257. * Set the value of the feed link property for this object. This property
  258. * is used to provide links to alternative feeds relevant to this entry.
  259. *
  260. * @param array $value A collection of
  261. * Zend_Gdata_Gapps_Extension_FeedLink objects.
  262. * @return Zend_Gdata_Gapps_EventEntry Provides a fluent interface.
  263. */
  264. public function setFeedLink($value)
  265. {
  266. $this->_feedLink = $value;
  267. return $this;
  268. }
  269. }