summaryrefslogtreecommitdiff
path: root/zend/library/Zend/Gdata/YouTube/Extension/Statistics.php
blob: 001c53d9a3ea6886f088b2188a6de3991fbf9b34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @subpackage YouTube
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Statistics.php 24593 2012-01-05 20:35:02Z matthew $
 */

/**
 * @see Zend_Gdata_Extension
 */
require_once 'Zend/Gdata/Extension.php';

/**
 * Represents the yt:statistics element used by the YouTube data API
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @subpackage YouTube
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Gdata_YouTube_Extension_Statistics extends Zend_Gdata_Extension
{

    protected $_rootNamespace = 'yt';
    protected $_rootElement = 'statistics';

    /**
     * The videoWatchCount attribute specifies the number of videos
     * that a user has watched on YouTube. The videoWatchCount attribute
     * is only specified when the <yt:statistics> tag appears within a
     * user profile entry.
     *
     * @var integer
     */
    protected $_videoWatchCount = null;

    /**
     * When the viewCount attribute refers to a video entry, the attribute
     * specifies the number of times that the video has been viewed.
     * When the viewCount attribute refers to a user profile, the attribute
     * specifies the number of times that the user's profile has been
     * viewed.
     *
     * @var integer
     */
    protected $_viewCount = null;

    /**
     * The subscriberCount attribute specifies the number of YouTube users
     * who have subscribed to a particular user's YouTube channel.
     * The subscriberCount attribute is only specified when the
     * <yt:statistics> tag appears within a user profile entry.
     *
     * @var integer
     */
    protected $_subscriberCount = null;

    /**
     * The lastWebAccess attribute indicates the most recent time that
     * a particular user used YouTube.
     *
     * @var string
     */
    protected $_lastWebAccess = null;

    /**
     * The favoriteCount attribute specifies the number of YouTube users
     * who have added a video to their list of favorite videos. The
     * favoriteCount attribute is only specified when the
     * <yt:statistics> tag appears within a video entry.
     *
     * @var integer
     */
    protected $_favoriteCount = null;

    /**
     * Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
     * @param string $viewCount(optional) The viewCount value
     * @param string $videoWatchCount(optional) The videoWatchCount value
     * @param string $subscriberCount(optional) The subscriberCount value
     * @param string $lastWebAccess(optional) The lastWebAccess value
     * @param string $favoriteCount(optional) The favoriteCount value
     */
    public function __construct($viewCount = null, $videoWatchCount = null,
        $subscriberCount = null, $lastWebAccess = null,
        $favoriteCount = null)
    {
        $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
        parent::__construct();
        $this->_viewCount = $viewCount;
        $this->_videoWatchCount = $videoWatchCount;
        $this->_subscriberCount = $subscriberCount;
        $this->_lastWebAccess = $lastWebAccess;
        $this->_favoriteCount = $favoriteCount;
    }

    /**
     * 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 sending to the server upon updates, or
     * 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->_videoWatchCount !== null) {
            $element->setAttribute('watchCount', $this->_videoWatchCount);
        }
        if ($this->_viewCount !== null) {
            $element->setAttribute('viewCount', $this->_viewCount);
        }
        if ($this->_subscriberCount !== null) {
            $element->setAttribute('subscriberCount',
                $this->_subscriberCount);
        }
        if ($this->_lastWebAccess !== null) {
            $element->setAttribute('lastWebAccess',
                $this->_lastWebAccess);
        }
        if ($this->_favoriteCount !== null) {
            $element->setAttribute('favoriteCount',
                $this->_favoriteCount);
        }
        return $element;
    }

    /**
     * Given a DOMNode representing an attribute, tries to map the data into
     * instance members.  If no mapping is defined, the name and valueare
     * stored in an array.
     * TODO: Convert attributes to proper types
     *
     * @param DOMNode $attribute The DOMNode attribute needed to be handled
     */
    protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
        case 'videoWatchCount':
            $this->_videoWatchCount = $attribute->nodeValue;
            break;
        case 'viewCount':
            $this->_viewCount = $attribute->nodeValue;
            break;
        case 'subscriberCount':
            $this->_subscriberCount = $attribute->nodeValue;
            break;
        case 'lastWebAccess':
            $this->_lastWebAccess = $attribute->nodeValue;
            break;
        case 'favoriteCount':
            $this->_favoriteCount = $attribute->nodeValue;
            break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }

    /**
     * Get the value for this element's viewCount attribute.
     *
     * @return int The value associated with this attribute.
     */
    public function getViewCount()
    {
        return $this->_viewCount;
    }

    /**
     * Set the value for this element's viewCount attribute.
     *
     * @param int $value The desired value for this attribute.
     * @return Zend_Gdata_YouTube_Extension_Statistics The element being
     * modified.
     */
    public function setViewCount($value)
    {
        $this->_viewCount = $value;
        return $this;
    }

    /**
     * Get the value for this element's videoWatchCount attribute.
     *
     * @return int The value associated with this attribute.
     */
    public function getVideoWatchCount()
    {
        return $this->_videoWatchCount;
    }

    /**
     * Set the value for this element's videoWatchCount attribute.
     *
     * @param int $value The desired value for this attribute.
     * @return Zend_Gdata_YouTube_Extension_Statistics The element being
     * modified.
     */
    public function setVideoWatchCount($value)
    {
        $this->_videoWatchCount = $value;
        return $this;
    }

    /**
     * Get the value for this element's subscriberCount attribute.
     *
     * @return int The value associated with this attribute.
     */
    public function getSubscriberCount()
    {
        return $this->_subscriberCount;
    }

    /**
     * Set the value for this element's subscriberCount attribute.
     *
     * @param int $value The desired value for this attribute.
     * @return Zend_Gdata_YouTube_Extension_Statistics The element being
     * modified.
     */
    public function setSubscriberCount($value)
    {
        $this->_subscriberCount = $value;
        return $this;
    }

    /**
     * Get the value for this element's lastWebAccess attribute.
     *
     * @return int The value associated with this attribute.
     */
    public function getLastWebAccess()
    {
        return $this->_lastWebAccess;
    }

    /**
     * Set the value for this element's lastWebAccess attribute.
     *
     * @param int $value The desired value for this attribute.
     * @return Zend_Gdata_YouTube_Extension_Statistics The element being
     * modified.
     */
    public function setLastWebAccess($value)
    {
        $this->_lastWebAccess = $value;
        return $this;
    }

    /**
     * Get the value for this element's favoriteCount attribute.
     *
     * @return int The value associated with this attribute.
     */
    public function getFavoriteCount()
    {
        return $this->_favoriteCount;
    }

    /**
     * Set the value for this element's favoriteCount attribute.
     *
     * @param int $value The desired value for this attribute.
     * @return Zend_Gdata_YouTube_Extension_Statistics The element being
     * modified.
     */
    public function setFavoriteCount($value)
    {
        $this->_favoriteCount = $value;
        return $this;
    }

    /**
     * Magic toString method allows using this directly via echo
     * Works best in PHP >= 4.2.0
     *
     * @return string
     */
    public function __toString()
    {
        return 'View Count=' . $this->_viewCount .
            ' VideoWatchCount=' . $this->_videoWatchCount .
            ' SubscriberCount=' . $this->_subscriberCount .
            ' LastWebAccess=' . $this->_lastWebAccess .
            ' FavoriteCount=' . $this->_favoriteCount;
    }

}