web/Zend/Gdata/YouTube/Extension/Statistics.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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 YouTube
       
    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
       
    21  * @version    $Id: Statistics.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    22  */
       
    23 
       
    24 /**
       
    25  * @see Zend_Gdata_Extension
       
    26  */
       
    27 require_once 'Zend/Gdata/Extension.php';
       
    28 
       
    29 /**
       
    30  * Represents the yt:statistics element used by the YouTube data API
       
    31  *
       
    32  * @category   Zend
       
    33  * @package    Zend_Gdata
       
    34  * @subpackage YouTube
       
    35  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    36  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    37  */
       
    38 class Zend_Gdata_YouTube_Extension_Statistics extends Zend_Gdata_Extension
       
    39 {
       
    40 
       
    41     protected $_rootNamespace = 'yt';
       
    42     protected $_rootElement = 'statistics';
       
    43 
       
    44     /**
       
    45      * The videoWatchCount attribute specifies the number of videos
       
    46      * that a user has watched on YouTube. The videoWatchCount attribute
       
    47      * is only specified when the <yt:statistics> tag appears within a
       
    48      * user profile entry.
       
    49      *
       
    50      * @var integer
       
    51      */
       
    52     protected $_videoWatchCount = null;
       
    53 
       
    54     /**
       
    55      * When the viewCount attribute refers to a video entry, the attribute
       
    56      * specifies the number of times that the video has been viewed.
       
    57      * When the viewCount attribute refers to a user profile, the attribute
       
    58      * specifies the number of times that the user's profile has been
       
    59      * viewed.
       
    60      *
       
    61      * @var integer
       
    62      */
       
    63     protected $_viewCount = null;
       
    64 
       
    65     /**
       
    66      * The subscriberCount attribute specifies the number of YouTube users
       
    67      * who have subscribed to a particular user's YouTube channel.
       
    68      * The subscriberCount attribute is only specified when the
       
    69      * <yt:statistics> tag appears within a user profile entry.
       
    70      *
       
    71      * @var integer
       
    72      */
       
    73     protected $_subscriberCount = null;
       
    74 
       
    75     /**
       
    76      * The lastWebAccess attribute indicates the most recent time that
       
    77      * a particular user used YouTube.
       
    78      *
       
    79      * @var string
       
    80      */
       
    81     protected $_lastWebAccess = null;
       
    82 
       
    83     /**
       
    84      * The favoriteCount attribute specifies the number of YouTube users
       
    85      * who have added a video to their list of favorite videos. The
       
    86      * favoriteCount attribute is only specified when the
       
    87      * <yt:statistics> tag appears within a video entry.
       
    88      *
       
    89      * @var integer
       
    90      */
       
    91     protected $_favoriteCount = null;
       
    92 
       
    93     /**
       
    94      * Constructs a new Zend_Gdata_YouTube_Extension_Statistics object.
       
    95      * @param string $viewCount(optional) The viewCount value
       
    96      * @param string $videoWatchCount(optional) The videoWatchCount value
       
    97      * @param string $subscriberCount(optional) The subscriberCount value
       
    98      * @param string $lastWebAccess(optional) The lastWebAccess value
       
    99      * @param string $favoriteCount(optional) The favoriteCount value
       
   100      */
       
   101     public function __construct($viewCount = null, $videoWatchCount = null,
       
   102         $subscriberCount = null, $lastWebAccess = null,
       
   103         $favoriteCount = null)
       
   104     {
       
   105         $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
       
   106         parent::__construct();
       
   107         $this->_viewCount = $viewCount;
       
   108         $this->_videoWatchCount = $videoWatchCount;
       
   109         $this->_subscriberCount = $subscriberCount;
       
   110         $this->_lastWebAccess = $lastWebAccess;
       
   111         $this->_favoriteCount = $favoriteCount;
       
   112     }
       
   113 
       
   114     /**
       
   115      * Retrieves a DOMElement which corresponds to this element and all
       
   116      * child properties.  This is used to build an entry back into a DOM
       
   117      * and eventually XML text for sending to the server upon updates, or
       
   118      * for application storage/persistence.
       
   119      *
       
   120      * @param DOMDocument $doc The DOMDocument used to construct DOMElements
       
   121      * @return DOMElement The DOMElement representing this element and all
       
   122      * child properties.
       
   123      */
       
   124     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
       
   125     {
       
   126         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
       
   127         if ($this->_videoWatchCount !== null) {
       
   128             $element->setAttribute('watchCount', $this->_videoWatchCount);
       
   129         }
       
   130         if ($this->_viewCount !== null) {
       
   131             $element->setAttribute('viewCount', $this->_viewCount);
       
   132         }
       
   133         if ($this->_subscriberCount !== null) {
       
   134             $element->setAttribute('subscriberCount',
       
   135                 $this->_subscriberCount);
       
   136         }
       
   137         if ($this->_lastWebAccess !== null) {
       
   138             $element->setAttribute('lastWebAccess',
       
   139                 $this->_lastWebAccess);
       
   140         }
       
   141         if ($this->_favoriteCount !== null) {
       
   142             $element->setAttribute('favoriteCount',
       
   143                 $this->_favoriteCount);
       
   144         }
       
   145         return $element;
       
   146     }
       
   147 
       
   148     /**
       
   149      * Given a DOMNode representing an attribute, tries to map the data into
       
   150      * instance members.  If no mapping is defined, the name and valueare
       
   151      * stored in an array.
       
   152      * TODO: Convert attributes to proper types
       
   153      *
       
   154      * @param DOMNode $attribute The DOMNode attribute needed to be handled
       
   155      */
       
   156     protected function takeAttributeFromDOM($attribute)
       
   157     {
       
   158         switch ($attribute->localName) {
       
   159         case 'videoWatchCount':
       
   160             $this->_videoWatchCount = $attribute->nodeValue;
       
   161             break;
       
   162         case 'viewCount':
       
   163             $this->_viewCount = $attribute->nodeValue;
       
   164             break;
       
   165         case 'subscriberCount':
       
   166             $this->_subscriberCount = $attribute->nodeValue;
       
   167             break;
       
   168         case 'lastWebAccess':
       
   169             $this->_lastWebAccess = $attribute->nodeValue;
       
   170             break;
       
   171         case 'favoriteCount':
       
   172             $this->_favoriteCount = $attribute->nodeValue;
       
   173             break;
       
   174         default:
       
   175             parent::takeAttributeFromDOM($attribute);
       
   176         }
       
   177     }
       
   178 
       
   179     /**
       
   180      * Get the value for this element's viewCount attribute.
       
   181      *
       
   182      * @return int The value associated with this attribute.
       
   183      */
       
   184     public function getViewCount()
       
   185     {
       
   186         return $this->_viewCount;
       
   187     }
       
   188 
       
   189     /**
       
   190      * Set the value for this element's viewCount attribute.
       
   191      *
       
   192      * @param int $value The desired value for this attribute.
       
   193      * @return Zend_Gdata_YouTube_Extension_Statistics The element being
       
   194      * modified.
       
   195      */
       
   196     public function setViewCount($value)
       
   197     {
       
   198         $this->_viewCount = $value;
       
   199         return $this;
       
   200     }
       
   201 
       
   202     /**
       
   203      * Get the value for this element's videoWatchCount attribute.
       
   204      *
       
   205      * @return int The value associated with this attribute.
       
   206      */
       
   207     public function getVideoWatchCount()
       
   208     {
       
   209         return $this->_videoWatchCount;
       
   210     }
       
   211 
       
   212     /**
       
   213      * Set the value for this element's videoWatchCount attribute.
       
   214      *
       
   215      * @param int $value The desired value for this attribute.
       
   216      * @return Zend_Gdata_YouTube_Extension_Statistics The element being
       
   217      * modified.
       
   218      */
       
   219     public function setVideoWatchCount($value)
       
   220     {
       
   221         $this->_videoWatchCount = $value;
       
   222         return $this;
       
   223     }
       
   224 
       
   225     /**
       
   226      * Get the value for this element's subscriberCount attribute.
       
   227      *
       
   228      * @return int The value associated with this attribute.
       
   229      */
       
   230     public function getSubscriberCount()
       
   231     {
       
   232         return $this->_subscriberCount;
       
   233     }
       
   234 
       
   235     /**
       
   236      * Set the value for this element's subscriberCount attribute.
       
   237      *
       
   238      * @param int $value The desired value for this attribute.
       
   239      * @return Zend_Gdata_YouTube_Extension_Statistics The element being
       
   240      * modified.
       
   241      */
       
   242     public function setSubscriberCount($value)
       
   243     {
       
   244         $this->_subscriberCount = $value;
       
   245         return $this;
       
   246     }
       
   247 
       
   248     /**
       
   249      * Get the value for this element's lastWebAccess attribute.
       
   250      *
       
   251      * @return int The value associated with this attribute.
       
   252      */
       
   253     public function getLastWebAccess()
       
   254     {
       
   255         return $this->_lastWebAccess;
       
   256     }
       
   257 
       
   258     /**
       
   259      * Set the value for this element's lastWebAccess attribute.
       
   260      *
       
   261      * @param int $value The desired value for this attribute.
       
   262      * @return Zend_Gdata_YouTube_Extension_Statistics The element being
       
   263      * modified.
       
   264      */
       
   265     public function setLastWebAccess($value)
       
   266     {
       
   267         $this->_lastWebAccess = $value;
       
   268         return $this;
       
   269     }
       
   270 
       
   271     /**
       
   272      * Get the value for this element's favoriteCount attribute.
       
   273      *
       
   274      * @return int The value associated with this attribute.
       
   275      */
       
   276     public function getFavoriteCount()
       
   277     {
       
   278         return $this->_favoriteCount;
       
   279     }
       
   280 
       
   281     /**
       
   282      * Set the value for this element's favoriteCount attribute.
       
   283      *
       
   284      * @param int $value The desired value for this attribute.
       
   285      * @return Zend_Gdata_YouTube_Extension_Statistics The element being
       
   286      * modified.
       
   287      */
       
   288     public function setFavoriteCount($value)
       
   289     {
       
   290         $this->_favoriteCount = $value;
       
   291         return $this;
       
   292     }
       
   293 
       
   294     /**
       
   295      * Magic toString method allows using this directly via echo
       
   296      * Works best in PHP >= 4.2.0
       
   297      *
       
   298      * @return string
       
   299      */
       
   300     public function __toString()
       
   301     {
       
   302         return 'View Count=' . $this->_viewCount .
       
   303             ' VideoWatchCount=' . $this->_videoWatchCount .
       
   304             ' SubscriberCount=' . $this->_subscriberCount .
       
   305             ' LastWebAccess=' . $this->_lastWebAccess .
       
   306             ' FavoriteCount=' . $this->_favoriteCount;
       
   307     }
       
   308 
       
   309 }