[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Gdata/YouTube/ -> ActivityEntry.php (source)

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


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1