source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/YouTube/ActivityEntry.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 6.6 KB
Line 
1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
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.
15 *
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage Health
19 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * @see Zend_Gdata_Entry
25 */
26require_once 'Zend/Gdata/Entry.php';
27
28/**
29 * @see Zend_Gdata_YouTube_Extension_VideoId
30 */
31require_once 'Zend/Gdata/YouTube/Extension/VideoId.php';
32
33/**
34 * @see Zend_Gdata_YouTube_Extension_Username
35 */
36require_once 'Zend/Gdata/YouTube/Extension/Username.php';
37
38/**
39 * @see Zend_Gdata_YouTube_Extension_Rating
40 */
41require_once 'Zend/Gdata/Extension/Rating.php';
42
43/**
44 * A concrete class for working with YouTube user activity entries.
45 *
46 * @link http://code.google.com/apis/youtube/
47 *
48 * @category Zend
49 * @package Zend_Gdata
50 * @subpackage YouTube
51 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
52 * @license http://framework.zend.com/license/new-bsd New BSD License
53 */
54class Zend_Gdata_YouTube_ActivityEntry extends Zend_Gdata_Entry
55{
56 const ACTIVITY_CATEGORY_SCHEME =
57 'http://gdata.youtube.com/schemas/2007/userevents.cat';
58
59 /**
60 * The classname for individual user activity entry elements.
61 *
62 * @var string
63 */
64 protected $_entryClassName = 'Zend_Gdata_YouTube_ActivityEntry';
65
66 /**
67 * The ID of the video that was part of the activity
68 *
69 * @var Zend_Gdata_YouTube_VideoId
70 */
71 protected $_videoId = null;
72
73 /**
74 * The username for the user that was part of the activity
75 *
76 * @var Zend_Gdata_YouTube_Username
77 */
78 protected $_username = null;
79
80 /**
81 * The rating element that was part of the activity
82 *
83 * @var Zend_Gdata_Extension_Rating
84 */
85 protected $_rating = null;
86
87 /**
88 * Constructs a new Zend_Gdata_YouTube_ActivityEntry object.
89 * @param DOMElement $element (optional) The DOMElement on which to
90 * base this object.
91 */
92 public function __construct($element = null)
93 {
94 $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
95 parent::__construct($element);
96 }
97
98 /**
99 * Retrieves a DOMElement which corresponds to this element and all
100 * child properties. This is used to build an entry back into a DOM
101 * and eventually XML text for application storage/persistence.
102 *
103 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
104 * @return DOMElement The DOMElement representing this element and all
105 * child properties.
106 */
107 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
108 {
109 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
110 if ($this->_videoId !== null) {
111 $element->appendChild($this->_videoId->getDOM(
112 $element->ownerDocument));
113 }
114 if ($this->_username !== null) {
115 $element->appendChild($this->_username->getDOM(
116 $element->ownerDocument));
117 }
118 if ($this->_rating !== null) {
119 $element->appendChild($this->_rating->getDOM(
120 $element->ownerDocument));
121 }
122 return $element;
123 }
124
125 /**
126 * Creates individual Entry objects of the appropriate type and
127 * stores them as members of this entry based upon DOM data.
128 *
129 * @param DOMNode $child The DOMNode to process
130 */
131 protected function takeChildFromDOM($child)
132 {
133 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
134 switch ($absoluteNodeName) {
135 case $this->lookupNamespace('yt') . ':' . 'videoid':
136 $videoId = new Zend_Gdata_YouTube_Extension_VideoId();
137 $videoId->transferFromDOM($child);
138 $this->_videoId = $videoId;
139 break;
140 case $this->lookupNamespace('yt') . ':' . 'username':
141 $username = new Zend_Gdata_YouTube_Extension_Username();
142 $username->transferFromDOM($child);
143 $this->_username = $username;
144 break;
145 case $this->lookupNamespace('gd') . ':' . 'rating':
146 $rating = new Zend_Gdata_Extension_Rating();
147 $rating->transferFromDOM($child);
148 $this->_rating = $rating;
149 break;
150 default:
151 parent::takeChildFromDOM($child);
152 break;
153 }
154 }
155
156 /**
157 * Returns the video ID for this activity entry.
158 *
159 * @return null|Zend_Gdata_YouTube_Extension_VideoId
160 */
161 public function getVideoId()
162 {
163 return $this->_videoId;
164 }
165
166 /**
167 * Returns the username for this activity entry.
168 *
169 * @return null|Zend_Gdata_YouTube_Extension_Username
170 */
171 public function getUsername()
172 {
173 return $this->_username;
174 }
175
176 /**
177 * Returns the rating for this activity entry.
178 *
179 * @return null|Zend_Gdata_YouTube_Extension_Rating
180 */
181 public function getRating()
182 {
183 return $this->_rating;
184 }
185
186 /**
187 * Return the value of the rating for this video entry.
188 *
189 * Convenience method to save needless typing.
190 *
191 * @return integer|null The value of the rating that was created, if found.
192 */
193 public function getRatingValue()
194 {
195 $rating = $this->_rating;
196 if ($rating) {
197 return $rating->getValue();
198 }
199 return null;
200 }
201
202 /**
203 * Return the activity type that was performed.
204 *
205 * Convenience method that inspects category where scheme is
206 * http://gdata.youtube.com/schemas/2007/userevents.cat.
207 *
208 * @return string|null The activity category if found.
209 */
210 public function getActivityType()
211 {
212 $categories = $this->getCategory();
213 foreach($categories as $category) {
214 if ($category->getScheme() == self::ACTIVITY_CATEGORY_SCHEME) {
215 return $category->getTerm();
216 }
217 }
218 return null;
219 }
220
221 /**
222 * Convenience method to quickly get access to the author of the activity
223 *
224 * @return string The author of the activity
225 */
226 public function getAuthorName()
227 {
228 $authors = $this->getAuthor();
229 return $authors[0]->getName()->getText();
230 }
231}
Note: See TracBrowser for help on using the repository browser.