DataEntry.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Analytics
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_Entry
  24. */
  25. require_once 'Zend/Gdata/Entry.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata
  29. * @subpackage Analytics
  30. */
  31. class Zend_Gdata_Analytics_DataEntry extends Zend_Gdata_Entry
  32. {
  33. /**
  34. * @var array
  35. */
  36. protected $_dimensions = array();
  37. /**
  38. * @var array
  39. */
  40. protected $_metrics = array();
  41. /**
  42. * @param DOMElement $element
  43. */
  44. public function __construct($element = null)
  45. {
  46. $this->registerAllNamespaces(Zend_Gdata_Analytics::$namespaces);
  47. parent::__construct($element);
  48. }
  49. /**
  50. * @param DOMElement $child
  51. * @return void
  52. */
  53. protected function takeChildFromDOM($child)
  54. {
  55. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  56. switch ($absoluteNodeName) {
  57. case $this->lookupNamespace('analytics') . ':' . 'dimension';
  58. $dimension = new Zend_Gdata_Analytics_Extension_Dimension();
  59. $dimension->transferFromDOM($child);
  60. $this->_dimensions[] = $dimension;
  61. break;
  62. case $this->lookupNamespace('analytics') . ':' . 'metric';
  63. $metric = new Zend_Gdata_Analytics_Extension_Metric();
  64. $metric->transferFromDOM($child);
  65. $this->_metrics[] = $metric;
  66. break;
  67. default:
  68. parent::takeChildFromDOM($child);
  69. break;
  70. }
  71. }
  72. /**
  73. * @param string $name
  74. * @return mixed
  75. */
  76. public function getDimension($name)
  77. {
  78. foreach ($this->_dimensions as $dimension) {
  79. if ($dimension->getName() == $name) {
  80. return $dimension;
  81. }
  82. }
  83. return null;
  84. }
  85. /**
  86. * @param string $name
  87. * @return mixed
  88. */
  89. public function getMetric($name)
  90. {
  91. foreach ($this->_metrics as $metric) {
  92. if ($metric->getName() == $name) {
  93. return $metric;
  94. }
  95. }
  96. return null;
  97. }
  98. /**
  99. * @param string $name
  100. * @return mixed
  101. */
  102. public function getValue($name)
  103. {
  104. if (null !== ($metric = $this->getMetric($name))) {
  105. return $metric;
  106. }
  107. return $this->getDimension($name);
  108. }
  109. }