8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_Entry
27 require_once 'Zend/Gdata/Entry.php';
30 * @see Zend_Gdata_YouTube_Extension_VideoId
32 require_once 'Zend/Gdata/YouTube/Extension/VideoId.php';
35 * @see Zend_Gdata_YouTube_Extension_Username
37 require_once 'Zend/Gdata/YouTube/Extension/Username.php';
40 * @see Zend_Gdata_YouTube_Extension_Rating
42 require_once 'Zend/Gdata/Extension/Rating.php';
45 * A concrete class for working with YouTube user activity entries.
47 * @link http://code.google.com/apis/youtube/
52 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
53 * @license http://framework.zend.com/license/new-bsd New BSD License
55 class Zend_Gdata_YouTube_ActivityEntry extends Zend_Gdata_Entry
57 const ACTIVITY_CATEGORY_SCHEME =
58 'http://gdata.youtube.com/schemas/2007/userevents.cat';
61 * The classname for individual user activity entry elements.
65 protected $_entryClassName = 'Zend_Gdata_YouTube_ActivityEntry';
68 * The ID of the video that was part of the activity
70 * @var Zend_Gdata_YouTube_VideoId
72 protected $_videoId = null;
75 * The username for the user that was part of the activity
77 * @var Zend_Gdata_YouTube_Username
79 protected $_username = null;
82 * The rating element that was part of the activity
84 * @var Zend_Gdata_Extension_Rating
86 protected $_rating = null;
89 * Constructs a new Zend_Gdata_YouTube_ActivityEntry object.
90 * @param DOMElement $element (optional) The DOMElement on which to
93 public function __construct($element = null)
95 $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
96 parent::__construct($element);
100 * Retrieves a DOMElement which corresponds to this element and all
101 * child properties. This is used to build an entry back into a DOM
102 * and eventually XML text for application storage/persistence.
104 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
105 * @return DOMElement The DOMElement representing this element and all
108 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
110 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
111 if ($this->_videoId !== null) {
112 $element->appendChild($this->_videoId->getDOM(
113 $element->ownerDocument));
115 if ($this->_username !== null) {
116 $element->appendChild($this->_username->getDOM(
117 $element->ownerDocument));
119 if ($this->_rating !== null) {
120 $element->appendChild($this->_rating->getDOM(
121 $element->ownerDocument));
127 * Creates individual Entry objects of the appropriate type and
128 * stores them as members of this entry based upon DOM data.
130 * @param DOMNode $child The DOMNode to process
132 protected function takeChildFromDOM($child)
134 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
135 switch ($absoluteNodeName) {
136 case $this->lookupNamespace('yt') . ':' . 'videoid':
137 $videoId = new Zend_Gdata_YouTube_Extension_VideoId();
138 $videoId->transferFromDOM($child);
139 $this->_videoId = $videoId;
141 case $this->lookupNamespace('yt') . ':' . 'username':
142 $username = new Zend_Gdata_YouTube_Extension_Username();
143 $username->transferFromDOM($child);
144 $this->_username = $username;
146 case $this->lookupNamespace('gd') . ':' . 'rating':
147 $rating = new Zend_Gdata_Extension_Rating();
148 $rating->transferFromDOM($child);
149 $this->_rating = $rating;
152 parent::takeChildFromDOM($child);
158 * Returns the video ID for this activity entry.
160 * @return null|Zend_Gdata_YouTube_Extension_VideoId
162 public function getVideoId()
164 return $this->_videoId;
168 * Returns the username for this activity entry.
170 * @return null|Zend_Gdata_YouTube_Extension_Username
172 public function getUsername()
174 return $this->_username;
178 * Returns the rating for this activity entry.
180 * @return null|Zend_Gdata_YouTube_Extension_Rating
182 public function getRating()
184 return $this->_rating;
188 * Return the value of the rating for this video entry.
190 * Convenience method to save needless typing.
192 * @return integer|null The value of the rating that was created, if found.
194 public function getRatingValue()
196 $rating = $this->_rating;
198 return $rating->getValue();
204 * Return the activity type that was performed.
206 * Convenience method that inspects category where scheme is
207 * http://gdata.youtube.com/schemas/2007/userevents.cat.
209 * @return string|null The activity category if found.
211 public function getActivityType()
213 $categories = $this->getCategory();
214 foreach($categories as $category) {
215 if ($category->getScheme() == self::ACTIVITY_CATEGORY_SCHEME) {
216 return $category->getTerm();
223 * Convenience method to quickly get access to the author of the activity
225 * @return string The author of the activity
227 public function getAuthorName()
229 $authors = $this->getAuthor();
230 return $authors[0]->getName()->getText();