AccountQuery.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_Query
  24. */
  25. require_once 'Zend/Gdata/Query.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata
  29. * @subpackage Analytics
  30. */
  31. class Zend_Gdata_Analytics_AccountQuery extends Zend_Gdata_Query
  32. {
  33. const ANALYTICS_FEED_URI = 'https://www.googleapis.com/analytics/v2.4/management/accounts';
  34. /**
  35. * The default URI used for feeds.
  36. */
  37. protected $_defaultFeedUri = self::ANALYTICS_FEED_URI;
  38. /**
  39. * @var string
  40. */
  41. protected $_accountId = '~all';
  42. /**
  43. * @var string
  44. */
  45. protected $_webpropertyId = '~all';
  46. /**
  47. * @var string
  48. */
  49. protected $_profileId = '~all';
  50. /**
  51. * @var bool
  52. */
  53. protected $_webproperties = false;
  54. /**
  55. * @var bool
  56. */
  57. protected $_profiles = false;
  58. /**
  59. * @var bool
  60. */
  61. protected $_goals = false;
  62. /**
  63. * @param string $accountId
  64. * @return Zend_Gdata_Analytics_AccountQuery
  65. */
  66. public function setAccountId($accountId)
  67. {
  68. $this->_accountId = $accountId;
  69. return $this;
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function getAccountId()
  75. {
  76. return $this->_accountId;
  77. }
  78. /**
  79. * @param string $webpropertyId
  80. * @return Zend_Gdata_Analytics_AccountQuery
  81. */
  82. public function setWebpropertyId($webpropertyId)
  83. {
  84. $this->_webpropertyId = $webpropertyId;
  85. return $this;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function getWebpropertyId()
  91. {
  92. return $this->_webpropertyId;
  93. }
  94. /**
  95. * @param string $profileId
  96. * @return Zend_Gdata_Analytics_AccountQuery
  97. */
  98. public function setProfileId($profileId)
  99. {
  100. $this->_profileId = $profileId;
  101. return $this;
  102. }
  103. /**
  104. * @return string
  105. */
  106. public function getProfileId()
  107. {
  108. return $this->_profileId;
  109. }
  110. /**
  111. * @param string $accountId
  112. * @return Zend_Gdata_Analytics_AccountQuery
  113. */
  114. public function webproperties($accountId = '~all')
  115. {
  116. $this->_webproperties = true;
  117. $this->setAccountId($accountId);
  118. return $this;
  119. }
  120. /**
  121. * @param string $webpropertyId
  122. * @param string $accountId
  123. * @return Zend_Gdata_Analytics_AccountQuery
  124. */
  125. public function profiles($webpropertyId = '~all', $accountId = '~all')
  126. {
  127. $this->_profiles = true;
  128. if (null !== $accountId) {
  129. $this->setAccountId($accountId);
  130. }
  131. $this->setWebpropertyId($webpropertyId);
  132. return $this;
  133. }
  134. /**
  135. * @param string $webpropertyId
  136. * @param string $accountId
  137. * @param string $accountId
  138. * @return Zend_Gdata_Analytics_AccountQuery
  139. */
  140. public function goals($profileId = '~all', $webpropertyId = '~all', $accountId = '~all')
  141. {
  142. $this->_goals = true;
  143. if (null !== $accountId) {
  144. $this->setAccountId($accountId);
  145. }
  146. if (null !== $webpropertyId) {
  147. $this->setWebpropertyId($webpropertyId);
  148. }
  149. $this->setProfileId($profileId);
  150. return $this;
  151. }
  152. /**
  153. * @return string url
  154. */
  155. public function getQueryUrl()
  156. {
  157. $url = $this->_defaultFeedUri;
  158. // add account id
  159. if ($this->_webproperties or $this->_profiles or $this->_goals) {
  160. $url .= '/' . $this->_accountId . '/webproperties';
  161. }
  162. if ($this->_profiles or $this->_goals) {
  163. $url .= '/' . $this->_webpropertyId . '/profiles';
  164. }
  165. if ($this->_goals) {
  166. $url .= '/' . $this->_profileId . '/goals';
  167. }
  168. $url .= $this->getQueryString();
  169. return $url;
  170. }
  171. }