diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Gdata/YouTube/ActivityEntry.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Gdata/YouTube/ActivityEntry.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,232 @@ +registerAllNamespaces(Zend_Gdata_YouTube::$namespaces); + parent::__construct($element); + } + + /** + * Retrieves a DOMElement which corresponds to this element and all + * child properties. This is used to build an entry back into a DOM + * and eventually XML text for application storage/persistence. + * + * @param DOMDocument $doc The DOMDocument used to construct DOMElements + * @return DOMElement The DOMElement representing this element and all + * child properties. + */ + public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) + { + $element = parent::getDOM($doc, $majorVersion, $minorVersion); + if ($this->_videoId !== null) { + $element->appendChild($this->_videoId->getDOM( + $element->ownerDocument)); + } + if ($this->_username !== null) { + $element->appendChild($this->_username->getDOM( + $element->ownerDocument)); + } + if ($this->_rating !== null) { + $element->appendChild($this->_rating->getDOM( + $element->ownerDocument)); + } + return $element; + } + + /** + * Creates individual Entry objects of the appropriate type and + * stores them as members of this entry based upon DOM data. + * + * @param DOMNode $child The DOMNode to process + */ + protected function takeChildFromDOM($child) + { + $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; + switch ($absoluteNodeName) { + case $this->lookupNamespace('yt') . ':' . 'videoid': + $videoId = new Zend_Gdata_YouTube_Extension_VideoId(); + $videoId->transferFromDOM($child); + $this->_videoId = $videoId; + break; + case $this->lookupNamespace('yt') . ':' . 'username': + $username = new Zend_Gdata_YouTube_Extension_Username(); + $username->transferFromDOM($child); + $this->_username = $username; + break; + case $this->lookupNamespace('gd') . ':' . 'rating': + $rating = new Zend_Gdata_Extension_Rating(); + $rating->transferFromDOM($child); + $this->_rating = $rating; + break; + default: + parent::takeChildFromDOM($child); + break; + } + } + + /** + * Returns the video ID for this activity entry. + * + * @return null|Zend_Gdata_YouTube_Extension_VideoId + */ + public function getVideoId() + { + return $this->_videoId; + } + + /** + * Returns the username for this activity entry. + * + * @return null|Zend_Gdata_YouTube_Extension_Username + */ + public function getUsername() + { + return $this->_username; + } + + /** + * Returns the rating for this activity entry. + * + * @return null|Zend_Gdata_YouTube_Extension_Rating + */ + public function getRating() + { + return $this->_rating; + } + + /** + * Return the value of the rating for this video entry. + * + * Convenience method to save needless typing. + * + * @return integer|null The value of the rating that was created, if found. + */ + public function getRatingValue() + { + $rating = $this->_rating; + if ($rating) { + return $rating->getValue(); + } + return null; + } + + /** + * Return the activity type that was performed. + * + * Convenience method that inspects category where scheme is + * http://gdata.youtube.com/schemas/2007/userevents.cat. + * + * @return string|null The activity category if found. + */ + public function getActivityType() + { + $categories = $this->getCategory(); + foreach($categories as $category) { + if ($category->getScheme() == self::ACTIVITY_CATEGORY_SCHEME) { + return $category->getTerm(); + } + } + return null; + } + + /** + * Convenience method to quickly get access to the author of the activity + * + * @return string The author of the activity + */ + public function getAuthorName() + { + $authors = $this->getAuthor(); + return $authors[0]->getName()->getText(); + } +}